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