Add <EBNF ... ENBF> syntax to return a parser object

db4
Chris Double 2008-07-04 12:40:42 +12:00
parent 8aa7bc6d78
commit 4c1fe8f0b3
1 changed files with 7 additions and 2 deletions

View File

@ -518,11 +518,16 @@ M: ebnf-non-terminal (transform) ( ast -- parser )
"Could not parse EBNF" throw
] if ;
: parse-ebnf ( string -- hashtable )
'ebnf' parse check-parse-result ast>> transform ;
: ebnf>quot ( string -- hashtable quot )
'ebnf' parse check-parse-result
parse-result-ast transform dup dup parser [ main swap at compile ] with-variable
parse-ebnf dup dup parser [ main swap at compile ] with-variable
[ compiled-parse ] curry [ with-scope ] curry ;
: <EBNF "EBNF>" reset-tokenizer parse-multiline-string parse-ebnf main swap at
parsed reset-tokenizer ; parsing
: [EBNF "EBNF]" reset-tokenizer parse-multiline-string ebnf>quot nip
parsed \ call parsed reset-tokenizer ; parsing