]> gitweb.factorcode.org Git - factor.git/commitdiff
Make replace-escapes infer and fix remaining unit test breakage in ebnf
authorChris Double <chris@bethia.(none)>
Fri, 20 Jun 2008 03:14:30 +0000 (15:14 +1200)
committerChris Double <chris@bethia.(none)>
Fri, 20 Jun 2008 03:14:30 +0000 (15:14 +1200)
extra/peg/ebnf/ebnf-tests.factor
extra/peg/ebnf/ebnf.factor

index e3c6586c89524992f60ba42cb53ea19e645fc792..5a4ecc5c2f87251ea5478a302a83f6605306e304 100644 (file)
@@ -448,7 +448,7 @@ foo=<foreign any-char> 'd'
 ] unit-test
 
 [
-  "USING: peg.ebnf ; [EBNF foo='a' foo='b' EBNF]" eval 
+  "USING: peg.ebnf ; [EBNF foo='a' foo='b' EBNF]" eval drop
 ] must-fail
 
 
index cba48f5892e30c7929f2e366da56c3a12c4743ab..8f36218b6179c8a4086472dc10a9a3b5c961df2a 100644 (file)
@@ -63,12 +63,17 @@ C: <ebnf> ebnf
   #! begin and end.\r
   [ syntax ] 2dip syntax pack ;\r
 \r
-: replace-escapes ( string -- string )\r
+#! Don't want to use 'replace' in an action since replace doesn't infer.\r
+#! Do the compilation of the peg at parse time and call (replace).\r
+PEG: escaper ( string -- ast )\r
   [\r
     "\\t" token [ drop "\t" ] action ,\r
     "\\n" token [ drop "\n" ] action ,\r
     "\\r" token [ drop "\r" ] action ,\r
-  ] choice* replace ;\r
+  ] choice* any-char-parser 2array choice repeat0 ;\r
+\r
+: replace-escapes ( string -- string )\r
+  escaper sift [ [ tree-write ] each ] with-string-writer ;\r
 \r
 : insert-escapes ( string -- string )\r
   [\r
@@ -319,7 +324,11 @@ M: ebnf (transform) ( ast -- parser )
 M: ebnf-rule (transform) ( ast -- parser )\r
   dup elements>> \r
   (transform) [\r
-    swap symbol>> dup get [ "Rule '" over append "' defined more than once" append throw ] [ set ] if\r
+    swap symbol>> dup get { [ tuple? ] [ delegate parser? ] } 1&& [ \r
+      "Rule '" over append "' defined more than once" append throw \r
+    ] [ \r
+      set \r
+    ] if\r
   ] keep ;\r
 \r
 M: ebnf-sequence (transform) ( ast -- parser )\r