Permalink
Browse files

fix bugs in string grammer.

  • Loading branch information...
1 parent d75e0a5 commit bb99ff8b8a2875ae01c9f2c664dce6a9ee2ecc53 @ericbmerritt ericbmerritt committed Jan 5, 2012
Showing with 39 additions and 37 deletions.
  1. +23 −21 src/joxa/compiler.jxa
  2. +16 −16 test/jxat_peg.erl
View
@@ -410,27 +410,29 @@
(p-string "\"")])
(fn (node idx)
- (let ((convert (lists/map (fn (el)
- (case el
- ([_ <<"\\\"">>]
- <<"\"">>)
- ([_ <<"\\\\">>]
- <<"\\">>)
- ([_ <<"\\b">>]
- <<"\b">>)
- ([_ <<"\\f">>]
- <<"\f">>)
- ([_ <<"\\n">>]
- <<"\n">>)
- ([_ <<"\\r">>]
- <<"\r">>)
- ([_ <<"\\t">>]
- <<"\t">>)
- (_
- el)))
- node))
- (result (erlang/binary_to_list (erlang/iolist_to_binary convert))))
- {:string result idx}))))
+ (case node
+ ([_ string _]
+ (let ((convert (lists/map (fn (el)
+ (case el
+ ([_ <<"\\\"">>]
+ <<"\"">>)
+ ([_ <<"\\\\">>]
+ <<"\\">>)
+ ([_ <<"\\b">>]
+ <<"\b">>)
+ ([_ <<"\\f">>]
+ <<"\f">>)
+ ([_ <<"\\n">>]
+ <<"\n">>)
+ ([_ <<"\\r">>]
+ <<"\r">>)
+ ([_ <<"\\t">>]
+ <<"\t">>)
+ (_
+ el)))
+ string))
+ (result (erlang/binary_to_list (erlang/iolist_to_binary convert))))
+ {:string result idx}))))))
;; A forward declaration to support the mutually recursive types
;; in the parser
View
@@ -501,25 +501,25 @@ fun_reference_test() ->
string_test() ->
- ?memo(?assertMatch({{string,"\" \\\" \"",{1,1}},<<>>,{1,7}},
+ ?memo(?assertMatch({{string," \" ",{1,1}},<<>>,{1,7}},
joxa.compiler:string(<<"\" \\\" \"">>, index()))),
- ?memo(?assertMatch({{string,"\"\\\\\"",{1,1}},<<>>,{1,5}},
+ ?memo(?assertMatch({{string,"\\",{1,1}},<<>>,{1,5}},
joxa.compiler:string(<<"\"\\\\\"">>,
index()))),
- ?memo(?assertMatch({{string,"\"\\f\"",{1,1}},<<>>,{1,5}},
+ ?memo(?assertMatch({{string,"\f",{1,1}},<<>>,{1,5}},
joxa.compiler:string(<<"\"\\f\"">>,
index()))),
- ?memo(?assertMatch({{string,"\"\\t\"",{1,1}},<<>>,{1,5}},
+ ?memo(?assertMatch({{string,"\t",{1,1}},<<>>,{1,5}},
joxa.compiler:string(<<"\"\\t\"">>,
index()))),
- ?memo(?assertMatch({{string,"\"\\n\"",{1,1}},<<>>,{2,2}},
+ ?memo(?assertMatch({{string,"\n",{1,1}},<<>>,{2,2}},
joxa.compiler:string(<<"\"\\n\"">>, index()))),
- ?memo(?assertMatch({{string,"\"\\r\"",{1,1}},<<>>,{1,5}},
+ ?memo(?assertMatch({{string,"\r",{1,1}},<<>>,{1,5}},
joxa.compiler:string(<<"\"\\r\"">>, index()))).
@@ -694,12 +694,12 @@ binary_test() ->
?memo(?assertMatch({{binary,[],{1,1}},<<>>,{1,5}},
joxa.compiler:binary(<<"<<>>">>, index()))),
- ?memo(?assertMatch({{binary,{string,"\"\"",{1,3}},{1,1}},
+ ?memo(?assertMatch({{binary,{string,[],{1,3}},{1,1}},
<<>>,
{1,7}},
joxa.compiler:binary(<<"<<\"\">>">>,
index()))),
- ?memo(?assertMatch({{binary,{string,"\"HelloWorld\"",{1,4}},{1,1}},
+ ?memo(?assertMatch({{binary,{string,"HelloWorld",{1,4}},{1,1}},
<<>>,
{1,19}},
joxa.compiler:binary(<<"<< \"HelloWorld\" >>">>,
@@ -769,25 +769,25 @@ value_test() ->
{'character-class',"[0-9]"}},{1,1}}},
joxa.compiler:value(<<"/2">>, index()))),
- ?memo(?assertMatch({{string,"\" \\\" \"",{1,1}},<<>>,{1,7}},
+ ?memo(?assertMatch({{string," \" ",{1,1}},<<>>,{1,7}},
joxa.compiler:value(<<"\" \\\" \"">>, index()))),
- ?memo(?assertMatch({{string,"\"\\\\\"",{1,1}},<<>>,{1,5}},
+ ?memo(?assertMatch({{string,"\\",{1,1}},<<>>,{1,5}},
joxa.compiler:value(<<"\"\\\\\"">>,
index()))),
- ?memo(?assertMatch({{string,"\"\\f\"",{1,1}},<<>>,{1,5}},
+ ?memo(?assertMatch({{string,"\f",{1,1}},<<>>,{1,5}},
joxa.compiler:value(<<"\"\\f\"">>,
index()))),
- ?memo(?assertMatch({{string,"\"\\t\"",{1,1}},<<>>,{1,5}},
+ ?memo(?assertMatch({{string,"\t",{1,1}},<<>>,{1,5}},
joxa.compiler:value(<<"\"\\t\"">>,
index()))),
- ?memo(?assertMatch({{string,"\"\\n\"",{1,1}},<<>>,{2,2}},
+ ?memo(?assertMatch({{string,"\n",{1,1}},<<>>,{2,2}},
joxa.compiler:value(<<"\"\\n\"">>, index()))),
- ?memo(?assertMatch({{string,"\"\\r\"",{1,1}},<<>>,{1,5}},
+ ?memo(?assertMatch({{string,"\r",{1,1}},<<>>,{1,5}},
joxa.compiler:value(<<"\"\\r\"">>, index()))),
?memo(?assertMatch({{quote,{ident,ok,{1,2}},{1,1}},<<>>,{1,4}},
@@ -956,12 +956,12 @@ value_test() ->
?memo(?assertMatch({{binary,[],{1,1}},<<>>,{1,5}},
joxa.compiler:value(<<"<<>>">>, index()))),
- ?memo(?assertMatch({{binary,{string,"\"\"",{1,3}},{1,1}},
+ ?memo(?assertMatch({{binary,{string,"",{1,3}},{1,1}},
<<>>,
{1,7}},
joxa.compiler:value(<<"<<\"\">>">>,
index()))),
- ?memo(?assertMatch({{binary,{string,"\"HelloWorld\"",{1,4}},{1,1}},
+ ?memo(?assertMatch({{binary,{string,"HelloWorld",{1,4}},{1,1}},
<<>>,
{1,19}},
joxa.compiler:value(<<"<< \"HelloWorld\" >>">>,

0 comments on commit bb99ff8

Please sign in to comment.