Use cache in compiled-parser in peg

db4
Chris Double 2008-03-27 14:55:14 +13:00
parent c0f4e37427
commit e6da3bc43a
1 changed files with 3 additions and 7 deletions

View File

@ -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 [