Refactor choice peg parser

db4
Chris Double 2008-04-05 17:54:18 +13:00
parent 102178f787
commit 226d211342
1 changed files with 3 additions and 8 deletions

View File

@ -343,21 +343,16 @@ M: seq-parser (compile) ( parser -- quot )
TUPLE: choice-parser parsers ;
MATCH-VARS: ?quot ;
: choice-pattern ( -- quot )
[
[ ?quot ] unless*
] ;
M: choice-parser (compile) ( parser -- quot )
[
f ,
parsers>> [ compiled-parser \ ?quot choice-pattern match-replace % ] each
parsers>> [ compiled-parser 1quotation , \ unless* , ] each
] [ ] make ;
TUPLE: repeat0-parser p1 ;
MATCH-VARS: ?quot ;
: (repeat0) ( quot result -- result )
over call [
[ remaining>> swap (>>remaining) ] 2keep