Declare stack effects for compiled parsers
parent
78633e03a0
commit
bb8198d3d0
|
@ -3,7 +3,7 @@
|
|||
USING: kernel compiler.units parser words arrays strings math.parser sequences
|
||||
quotations vectors namespaces math assocs continuations peg
|
||||
peg.parsers unicode.categories multiline combinators.lib
|
||||
splitting accessors ;
|
||||
splitting accessors effects ;
|
||||
IN: peg.ebnf
|
||||
|
||||
TUPLE: ebnf-non-terminal symbol ;
|
||||
|
@ -310,5 +310,5 @@ M: ebnf-non-terminal (transform) ( ast -- parser )
|
|||
: EBNF:
|
||||
CREATE-WORD dup
|
||||
";EBNF" parse-multiline-string
|
||||
ebnf>quot swapd define "ebnf-parser" set-word-prop ; parsing
|
||||
ebnf>quot swapd 1 1 <effect> define-declared "ebnf-parser" set-word-prop ; parsing
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
USING: kernel sequences strings namespaces math assocs shuffle
|
||||
vectors arrays combinators.lib math.parser match
|
||||
unicode.categories sequences.lib compiler.units parser
|
||||
words quotations effects memoize accessors locals ;
|
||||
words quotations effects memoize accessors locals effects ;
|
||||
IN: peg
|
||||
|
||||
USE: prettyprint
|
||||
|
@ -206,7 +206,7 @@ GENERIC: (compile) ( parser -- quot )
|
|||
:: parser-body ( parser -- quot )
|
||||
#! Return the body of the word that is the compiled version
|
||||
#! of the parser.
|
||||
[let* | rule [ parser (compile) define-temp dup parser "peg" set-word-prop ]
|
||||
[let* | rule [ gensym dup parser (compile) 0 1 <effect> define-declared dup parser "peg" set-word-prop ]
|
||||
|
|
||||
[
|
||||
rule pos get apply-rule dup fail = [
|
||||
|
@ -216,7 +216,7 @@ GENERIC: (compile) ( parser -- quot )
|
|||
] if
|
||||
]
|
||||
] ;
|
||||
|
||||
|
||||
: compiled-parser ( parser -- word )
|
||||
#! Look to see if the given parser has been compiled.
|
||||
#! If not, compile it to a temporary word, cache it,
|
||||
|
@ -227,7 +227,7 @@ GENERIC: (compile) ( parser -- quot )
|
|||
dup compiled>> [
|
||||
nip
|
||||
] [
|
||||
gensym tuck >>compiled 2dup parser-body define dupd "peg" set-word-prop
|
||||
gensym tuck >>compiled 2dup parser-body 0 1 <effect> define-declared dupd "peg" set-word-prop
|
||||
] if* ;
|
||||
|
||||
: compile ( parser -- word )
|
||||
|
|
Loading…
Reference in New Issue