peg delay parsers now infer
parent
40924f7b4a
commit
9f0f2d0bbc
|
@ -295,3 +295,5 @@ main = Primary
|
||||||
{ V{ V{ V{ "x" "[" "i" "]" } "[" "j" "]" } "." "y" } } [
|
{ V{ V{ V{ "x" "[" "i" "]" } "[" "j" "]" } "." "y" } } [
|
||||||
"x[i][j].y" primary parse-result-ast
|
"x[i][j].y" primary parse-result-ast
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
|
'ebnf' compile must-infer
|
||||||
|
|
|
@ -240,8 +240,21 @@ GENERIC: (compile) ( parser -- quot )
|
||||||
gensym tuck >>compiled 2dup parser-body 0 1 <effect> define-declared dupd "peg" set-word-prop
|
gensym tuck >>compiled 2dup parser-body 0 1 <effect> define-declared dupd "peg" set-word-prop
|
||||||
] if* ;
|
] if* ;
|
||||||
|
|
||||||
|
SYMBOL: delayed
|
||||||
|
|
||||||
|
: fixup-delayed ( -- )
|
||||||
|
#! Work through all delayed parsers and recompile their
|
||||||
|
#! words to have the correct bodies.
|
||||||
|
delayed get [
|
||||||
|
call compiled-parser 1quotation 0 1 <effect> define-declared
|
||||||
|
] assoc-each ;
|
||||||
|
|
||||||
: compile ( parser -- word )
|
: compile ( parser -- word )
|
||||||
[ compiled-parser ] with-compilation-unit ;
|
[
|
||||||
|
H{ } clone delayed [
|
||||||
|
compiled-parser fixup-delayed
|
||||||
|
] with-variable
|
||||||
|
] with-compilation-unit ;
|
||||||
|
|
||||||
: compiled-parse ( state word -- result )
|
: compiled-parse ( state word -- result )
|
||||||
swap [ execute ] with-packrat ; inline
|
swap [ execute ] with-packrat ; inline
|
||||||
|
@ -451,7 +464,7 @@ M: delay-parser (compile) ( parser -- quot )
|
||||||
#! For efficiency we memoize the quotation.
|
#! For efficiency we memoize the quotation.
|
||||||
#! This way it is run only once and the
|
#! This way it is run only once and the
|
||||||
#! parser constructed once at run time.
|
#! parser constructed once at run time.
|
||||||
quot>> '[ @ compile ] { } { "word" } <effect> memoize-quot '[ @ execute ] ;
|
quot>> gensym [ delayed get set-at ] keep 1quotation ;
|
||||||
|
|
||||||
TUPLE: box-parser quot ;
|
TUPLE: box-parser quot ;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue