Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

fix bugs in string grammer.

  • Loading branch information...
commit bb99ff8b8a2875ae01c9f2c664dce6a9ee2ecc53 1 parent d75e0a5
Eric Merritt authored January 05, 2012
44  src/joxa/compiler.jxa
@@ -410,27 +410,29 @@
410 410
              (p-string "\"")])
411 411
 
412 412
      (fn (node idx)
413  
-         (let ((convert (lists/map (fn (el)
414  
-                                       (case el
415  
-                                         ([_ <<"\\\"">>]
416  
-                                          <<"\"">>)
417  
-                                         ([_ <<"\\\\">>]
418  
-                                          <<"\\">>)
419  
-                                         ([_ <<"\\b">>]
420  
-                                          <<"\b">>)
421  
-                                         ([_ <<"\\f">>]
422  
-                                          <<"\f">>)
423  
-                                         ([_ <<"\\n">>]
424  
-                                          <<"\n">>)
425  
-                                         ([_ <<"\\r">>]
426  
-                                          <<"\r">>)
427  
-                                         ([_ <<"\\t">>]
428  
-                                          <<"\t">>)
429  
-                                         (_
430  
-                                          el)))
431  
-                                   node))
432  
-               (result (erlang/binary_to_list (erlang/iolist_to_binary convert))))
433  
-           {:string result idx}))))
  413
+         (case node
  414
+           ([_ string _]
  415
+            (let ((convert (lists/map (fn (el)
  416
+                                          (case el
  417
+                                            ([_ <<"\\\"">>]
  418
+                                             <<"\"">>)
  419
+                                            ([_ <<"\\\\">>]
  420
+                                             <<"\\">>)
  421
+                                            ([_ <<"\\b">>]
  422
+                                             <<"\b">>)
  423
+                                            ([_ <<"\\f">>]
  424
+                                             <<"\f">>)
  425
+                                            ([_ <<"\\n">>]
  426
+                                             <<"\n">>)
  427
+                                            ([_ <<"\\r">>]
  428
+                                             <<"\r">>)
  429
+                                            ([_ <<"\\t">>]
  430
+                                             <<"\t">>)
  431
+                                            (_
  432
+                                             el)))
  433
+                                      string))
  434
+                  (result (erlang/binary_to_list (erlang/iolist_to_binary convert))))
  435
+              {:string result idx}))))))
434 436
 
435 437
 ;; A forward declaration to support the mutually recursive types
436 438
 ;; in the parser
32  test/jxat_peg.erl
@@ -501,25 +501,25 @@ fun_reference_test() ->
501 501
 
502 502
 
503 503
 string_test() ->
504  
-    ?memo(?assertMatch({{string,"\" \\\" \"",{1,1}},<<>>,{1,7}},
  504
+    ?memo(?assertMatch({{string," \" ",{1,1}},<<>>,{1,7}},
505 505
                        joxa.compiler:string(<<"\" \\\" \"">>, index()))),
506 506
 
507  
-    ?memo(?assertMatch({{string,"\"\\\\\"",{1,1}},<<>>,{1,5}},
  507
+    ?memo(?assertMatch({{string,"\\",{1,1}},<<>>,{1,5}},
508 508
                        joxa.compiler:string(<<"\"\\\\\"">>,
509 509
                                             index()))),
510 510
 
511  
-    ?memo(?assertMatch({{string,"\"\\f\"",{1,1}},<<>>,{1,5}},
  511
+    ?memo(?assertMatch({{string,"\f",{1,1}},<<>>,{1,5}},
512 512
                        joxa.compiler:string(<<"\"\\f\"">>,
513 513
                                             index()))),
514 514
 
515  
-    ?memo(?assertMatch({{string,"\"\\t\"",{1,1}},<<>>,{1,5}},
  515
+    ?memo(?assertMatch({{string,"\t",{1,1}},<<>>,{1,5}},
516 516
                        joxa.compiler:string(<<"\"\\t\"">>,
517 517
                                             index()))),
518 518
 
519  
-    ?memo(?assertMatch({{string,"\"\\n\"",{1,1}},<<>>,{2,2}},
  519
+    ?memo(?assertMatch({{string,"\n",{1,1}},<<>>,{2,2}},
520 520
                        joxa.compiler:string(<<"\"\\n\"">>, index()))),
521 521
 
522  
-    ?memo(?assertMatch({{string,"\"\\r\"",{1,1}},<<>>,{1,5}},
  522
+    ?memo(?assertMatch({{string,"\r",{1,1}},<<>>,{1,5}},
523 523
                        joxa.compiler:string(<<"\"\\r\"">>, index()))).
524 524
 
525 525
 
@@ -694,12 +694,12 @@ binary_test() ->
694 694
     ?memo(?assertMatch({{binary,[],{1,1}},<<>>,{1,5}},
695 695
                        joxa.compiler:binary(<<"<<>>">>, index()))),
696 696
 
697  
-    ?memo(?assertMatch({{binary,{string,"\"\"",{1,3}},{1,1}},
  697
+    ?memo(?assertMatch({{binary,{string,[],{1,3}},{1,1}},
698 698
                         <<>>,
699 699
                         {1,7}},
700 700
                        joxa.compiler:binary(<<"<<\"\">>">>,
701 701
                                             index()))),
702  
-    ?memo(?assertMatch({{binary,{string,"\"HelloWorld\"",{1,4}},{1,1}},
  702
+    ?memo(?assertMatch({{binary,{string,"HelloWorld",{1,4}},{1,1}},
703 703
                         <<>>,
704 704
                         {1,19}},
705 705
                        joxa.compiler:binary(<<"<< \"HelloWorld\" >>">>,
@@ -769,25 +769,25 @@ value_test() ->
769 769
                                    {'character-class',"[0-9]"}},{1,1}}},
770 770
                        joxa.compiler:value(<<"/2">>, index()))),
771 771
 
772  
-    ?memo(?assertMatch({{string,"\" \\\" \"",{1,1}},<<>>,{1,7}},
  772
+    ?memo(?assertMatch({{string," \" ",{1,1}},<<>>,{1,7}},
773 773
                        joxa.compiler:value(<<"\" \\\" \"">>, index()))),
774 774
 
775  
-    ?memo(?assertMatch({{string,"\"\\\\\"",{1,1}},<<>>,{1,5}},
  775
+    ?memo(?assertMatch({{string,"\\",{1,1}},<<>>,{1,5}},
776 776
                        joxa.compiler:value(<<"\"\\\\\"">>,
777 777
                                            index()))),
778 778
 
779  
-    ?memo(?assertMatch({{string,"\"\\f\"",{1,1}},<<>>,{1,5}},
  779
+    ?memo(?assertMatch({{string,"\f",{1,1}},<<>>,{1,5}},
780 780
                        joxa.compiler:value(<<"\"\\f\"">>,
781 781
                                            index()))),
782 782
 
783  
-    ?memo(?assertMatch({{string,"\"\\t\"",{1,1}},<<>>,{1,5}},
  783
+    ?memo(?assertMatch({{string,"\t",{1,1}},<<>>,{1,5}},
784 784
                        joxa.compiler:value(<<"\"\\t\"">>,
785 785
                                            index()))),
786 786
 
787  
-    ?memo(?assertMatch({{string,"\"\\n\"",{1,1}},<<>>,{2,2}},
  787
+    ?memo(?assertMatch({{string,"\n",{1,1}},<<>>,{2,2}},
788 788
                        joxa.compiler:value(<<"\"\\n\"">>, index()))),
789 789
 
790  
-    ?memo(?assertMatch({{string,"\"\\r\"",{1,1}},<<>>,{1,5}},
  790
+    ?memo(?assertMatch({{string,"\r",{1,1}},<<>>,{1,5}},
791 791
                        joxa.compiler:value(<<"\"\\r\"">>, index()))),
792 792
 
793 793
     ?memo(?assertMatch({{quote,{ident,ok,{1,2}},{1,1}},<<>>,{1,4}},
@@ -956,12 +956,12 @@ value_test() ->
956 956
     ?memo(?assertMatch({{binary,[],{1,1}},<<>>,{1,5}},
957 957
                        joxa.compiler:value(<<"<<>>">>, index()))),
958 958
 
959  
-    ?memo(?assertMatch({{binary,{string,"\"\"",{1,3}},{1,1}},
  959
+    ?memo(?assertMatch({{binary,{string,"",{1,3}},{1,1}},
960 960
                         <<>>,
961 961
                         {1,7}},
962 962
                        joxa.compiler:value(<<"<<\"\">>">>,
963 963
                                            index()))),
964  
-    ?memo(?assertMatch({{binary,{string,"\"HelloWorld\"",{1,4}},{1,1}},
  964
+    ?memo(?assertMatch({{binary,{string,"HelloWorld",{1,4}},{1,1}},
965 965
                         <<>>,
966 966
                         {1,19}},
967 967
                        joxa.compiler:value(<<"<< \"HelloWorld\" >>">>,

0 notes on commit bb99ff8

Please sign in to comment.
Something went wrong with that request. Please try again.