Don't use 'delay' parser in ebnf

db4
Chris Double 2008-03-29 17:42:21 +13:00
parent 0db0d9cd44
commit 86653e7a46
2 changed files with 16 additions and 3 deletions

View File

@ -262,8 +262,8 @@ M: ebnf-terminal (transform) ( ast -- parser )
M: ebnf-non-terminal (transform) ( ast -- parser )
symbol>> [
, parser get , \ at ,
] [ ] make delay sp ;
, parser get , \ at , \ sp ,
] [ ] make box ;
: transform-ebnf ( string -- object )
'ebnf' parse parse-result-ast transform ;
@ -282,7 +282,8 @@ M: ebnf-non-terminal (transform) ( ast -- parser )
: ebnf>quot ( string -- hashtable quot )
'ebnf' parse check-parse-result
parse-result-ast transform dup main swap at compile [ compiled-parse ] curry ;
parse-result-ast transform dup dup parser [ main swap at compile ] with-variable
[ compiled-parse ] curry ;
: [EBNF "EBNF]" parse-multiline-string ebnf>quot nip parsed ; parsing

View File

@ -489,6 +489,15 @@ M: delay-parser (compile) ( parser -- quot )
{ } { "word" } <effect> memoize-quot
[ % \ execute , ] [ ] make ;
TUPLE: box-parser quot ;
M: box-parser (compile) ( parser -- quot )
#! Calls the quotation at compile time
#! to produce the parser to be compiled.
#! This differs from 'delay' which calls
#! it at run time.
quot>> call compiled-parser 1quotation ;
PRIVATE>
: token ( string -- parser )
@ -557,6 +566,9 @@ PRIVATE>
: delay ( quot -- parser )
delay-parser construct-boa init-parser ;
: box ( quot -- parser )
box-parser construct-boa init-parser ;
: PEG:
(:) [
[