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 ;
: token-pattern ( -- quot )
[
?token 2dup head? [
dup >r length tail-slice r> <parse-result>
] [
2drop f
] if
] ;
: parse-token ( input string -- result )
#! Parse the string, returning a parse result
2dup head? [
dup >r length tail-slice r> <parse-result>
] [
2drop f
] if ;
M: token-parser (compile) ( parser -- quot )
token-parser-symbol \ ?token token-pattern match-replace ;
token-parser-symbol [ parse-token ] curry ;
TUPLE: satisfy-parser quot ;