Reduce amount of generated code for peg token parser

db4
Chris Double 2008-03-26 15:40:17 +13:00
parent 9b7246555a
commit b1561de0f6
1 changed files with 9 additions and 10 deletions

View File

@ -43,17 +43,16 @@ TUPLE: token-parser symbol ;
MATCH-VARS: ?token ; MATCH-VARS: ?token ;
: token-pattern ( -- quot ) : parse-token ( input string -- result )
[ #! Parse the string, returning a parse result
?token 2dup head? [ 2dup head? [
dup >r length tail-slice r> <parse-result> dup >r length tail-slice r> <parse-result>
] [ ] [
2drop f 2drop f
] if ] if ;
] ;
M: token-parser (compile) ( parser -- quot ) M: token-parser (compile) ( parser -- quot )
token-parser-symbol \ ?token token-pattern match-replace ; token-parser-symbol [ parse-token ] curry ;
TUPLE: satisfy-parser quot ; TUPLE: satisfy-parser quot ;