Permalink
Browse files

initial barely working json parser

  • Loading branch information...
0 parents commit 955caa83d85f931d9f45aca29a00c53aa7285323 Chris Anderson committed Jul 24, 2008
Showing with 3,260 additions and 0 deletions.
  1. BIN jsong.beam
  2. +510 −0 jsong.erl
  3. +29 −0 jsong.yrl
  4. BIN jsonl.beam
  5. +474 −0 jsonl.erl
  6. +39 −0 jsonl.xrl
  7. BIN leex.beam
  8. +825 −0 leex.erl
  9. +258 −0 leex.txt
  10. +24 −0 leex/COPYRIGHT
  11. +136 −0 leex/erlang_scan.xrl
  12. +178 −0 leex/lfe_scan.xrl
  13. +214 −0 leexinc.hrl
  14. BIN listgrammar.beam
  15. +274 −0 listgrammar.erl
  16. +13 −0 listgrammar.yrl
  17. BIN sexp.beam
  18. +272 −0 sexp.erl
  19. +14 −0 sexp.xrl
Binary file not shown.
Oops, something went wrong.
@@ -0,0 +1,29 @@
+Nonterminals array element elements arrobj object members member.
+
+Terminals '{' '}' '[' ']' string ',' ':' integer true false null.
+
+Rootsymbol arrobj.
+
+arrobj -> array : '$1'.
+arrobj -> object : '$1'.
+
+object -> '{' members '}' : '$2'.
+object -> '{' member '}' : {'$2'}. % results in a shift/reduce conflict...
+
+members -> member ',' members : {'$1', '$3'}.
+members -> member : '$1'.
+
+member -> string ':' element : {element(3, '$1'),'$3'}.
+
+array -> '[' elements ']' : '$2'.
+
+elements -> element ',' elements : lists:flatten(['$1', '$3']). % can this be faster?
+elements -> element : '$1'.
+elements -> '$empty' : nil.
+
+element -> string : element(3, '$1').
+element -> arrobj : '$1'.
+element -> integer : element(3, '$1').
+element -> true : element(1, '$1').
+element -> false : element(1, '$1').
+element -> null : element(1, '$1').
Binary file not shown.
Oops, something went wrong.
@@ -0,0 +1,39 @@
+Definitions.
+
+ST = [^"]
+L = [A-Za-z]
+WS = ([\000-\s]|%.*)
+D = [0-9]
+H = [0-9a-fA-F]
+
+Rules.
+
+{ : {token, {'{', TokenLine}}.
+} : {token, {'}', TokenLine}}.
+
+\[ : {token, {'[', TokenLine}}.
+\] : {token, {']', TokenLine}}.
+
+{D}+\.{D}+((E|e)(\+|\-)?{D}+)? :
+ {token,{float,TokenLine,list_to_float(TokenChars)}}.
+{D}+ : {token,{integer,TokenLine,list_to_integer(TokenChars)}}.
+
+% "[^"\\]*(\\[^u][^"\\]*)*" : {token,{string,TokenLine,strip(TokenChars,TokenLen)}}.
+"[^"\\]*(\\.[^"\\]*)*" : {token,{string,TokenLine,list_to_binary(strip(TokenChars,TokenLen))}}.
+
+
+\\u{H}{H}{H}{H} : {token, {unicode, TokenLine,TokenChars}}.
+
+true : {token,{'true', TokenLine}}.
+false : {token,{'false', TokenLine}}.
+null : {token,{'null', TokenLine}}.
+
+: : {token, {':', TokenLine}}.
+, : {token, {',', TokenLine}}.
+
+{WS}+ : skip_token.
+
+Erlang code.
+
+strip(TokenChars,TokenLen) -> lists:sublist(TokenChars, 2, TokenLen - 2).
+
Binary file not shown.
Oops, something went wrong.

0 comments on commit 955caa8

Please sign in to comment.