Add 'delay' parser to peg
parent
ea2d4ea261
commit
e49d84ce97
|
@ -138,3 +138,13 @@ HELP: hide
|
|||
"Returns a parser that succeeds if the original parser succeeds, but does not "
|
||||
"put any result in the AST. Useful for ignoring 'syntax' in the AST." }
|
||||
{ $example "\"[\" token hide number \"]\" token hide 3array seq" } ;
|
||||
|
||||
HELP: delay
|
||||
{ $values
|
||||
{ "quot" "a quotation with stack effect ( -- parser )" }
|
||||
{ "parser" "a parser" }
|
||||
}
|
||||
{ $description
|
||||
"Delays the construction of a parser until it is actually required to parse. This "
|
||||
"allows for calling a parser that results in a recursive call to itself. The quotation "
|
||||
"should return the constructed parser." } ;
|
|
@ -168,6 +168,11 @@ TUPLE: sp-parser p1 ;
|
|||
M: sp-parser parse ( state parser -- result )
|
||||
[ left-trim-slice ] dip sp-parser-p1 parse ;
|
||||
|
||||
TUPLE: delay-parser quot ;
|
||||
|
||||
M: delay-parser parse ( state parser -- result )
|
||||
delay-parser-quot call parse ;
|
||||
|
||||
PRIVATE>
|
||||
|
||||
: token ( string -- parser )
|
||||
|
@ -208,3 +213,6 @@ PRIVATE>
|
|||
|
||||
: hide ( parser -- parser )
|
||||
[ drop ignore ] action ;
|
||||
|
||||
: delay ( parser -- parser )
|
||||
delay-parser construct-boa init-parser ;
|
||||
|
|
Loading…
Reference in New Issue