Use cache in compiled-parser in peg
parent
c0f4e37427
commit
e6da3bc43a
|
@ -16,7 +16,6 @@ SYMBOL: ignore
|
||||||
|
|
||||||
SYMBOL: compiled-parsers
|
SYMBOL: compiled-parsers
|
||||||
SYMBOL: packrat
|
SYMBOL: packrat
|
||||||
SYMBOL: failed
|
|
||||||
|
|
||||||
GENERIC: (compile) ( parser -- quot )
|
GENERIC: (compile) ( parser -- quot )
|
||||||
|
|
||||||
|
@ -36,12 +35,9 @@ GENERIC: (compile) ( parser -- quot )
|
||||||
#! Look to see if the given parser has been compiled.
|
#! Look to see if the given parser has been compiled.
|
||||||
#! If not, compile it to a temporary word, cache it,
|
#! If not, compile it to a temporary word, cache it,
|
||||||
#! and return it. Otherwise return the existing one.
|
#! and return it. Otherwise return the existing one.
|
||||||
dup compiled-parsers get at [
|
compiled-parsers get [
|
||||||
nip
|
(compile) [ run-parser ] curry define-temp
|
||||||
] [
|
] cache ;
|
||||||
dup (compile) [ run-parser ] curry define-temp
|
|
||||||
[ swap compiled-parsers get set-at ] keep
|
|
||||||
] if* ;
|
|
||||||
|
|
||||||
: compile ( parser -- word )
|
: compile ( parser -- word )
|
||||||
H{ } clone compiled-parsers [
|
H{ } clone compiled-parsers [
|
||||||
|
|
Loading…
Reference in New Issue