#! begin and end.\r
[ syntax ] 2dip syntax pack ;\r
\r
+: replace-escapes ( string -- string )\r
+ [\r
+ "\\t" token [ drop "\t" ] action ,\r
+ "\\n" token [ drop "\n" ] action ,\r
+ "\\r" token [ drop "\r" ] action ,\r
+ ] choice* replace ;\r
+\r
+: insert-escapes ( string -- string )\r
+ [\r
+ "\t" token [ drop "\\t" ] action ,\r
+ "\n" token [ drop "\\n" ] action ,\r
+ "\r" token [ drop "\\r" ] action ,\r
+ ] choice* replace ;\r
+\r
: 'identifier' ( -- parser )\r
#! Return a parser that parses an identifer delimited by\r
#! a quotation character. The quotation can be single\r
[\r
[ CHAR: " = not ] satisfy repeat1 "\"" "\"" surrounded-by ,\r
[ CHAR: ' = not ] satisfy repeat1 "'" "'" surrounded-by ,\r
- ] choice* [ >string ] action ;\r
+ ] choice* [ >string replace-escapes ] action ;\r
\r
: 'non-terminal' ( -- parser )\r
#! A non-terminal is the name of another rule. It can\r
} cond ;\r
\r
M: ebnf-action (transform) ( ast -- parser )\r
- [ parser>> (transform) ] [ code>> ] [ parser>> ] tri build-locals \r
+ [ parser>> (transform) ] [ code>> insert-escapes ] [ parser>> ] tri build-locals \r
string-lines parse-lines check-action-effect action ;\r
\r
M: ebnf-semantic (transform) ( ast -- parser )\r
- [ parser>> (transform) ] [ code>> ] [ parser>> ] tri build-locals \r
+ [ parser>> (transform) ] [ code>> insert-escapes ] [ parser>> ] tri build-locals \r
string-lines parse-lines semantic ;\r
\r
M: ebnf-var (transform) ( ast -- parser )\r
parse-result-ast transform dup dup parser [ main swap at compile ] with-variable\r
[ compiled-parse ] curry [ with-scope ] curry ;\r
\r
-: replace-escapes ( string -- string )\r
- [\r
- "\\t" token [ drop "\t" ] action ,\r
- "\\n" token [ drop "\n" ] action ,\r
- "\\r" token [ drop "\r" ] action ,\r
- ] choice* replace ;\r
-\r
-: [EBNF "EBNF]" parse-multiline-string replace-escapes ebnf>quot nip parsed ; parsing\r
+: [EBNF "EBNF]" parse-multiline-string ebnf>quot nip parsed ; parsing\r
\r
: EBNF: \r
CREATE-WORD dup \r
- ";EBNF" parse-multiline-string replace-escapes\r
+ ";EBNF" parse-multiline-string \r
ebnf>quot swapd 1 1 <effect> define-declared "ebnf-parser" set-word-prop ; parsing\r
\r