Refactor choice peg parser
parent
102178f787
commit
226d211342
|
@ -343,21 +343,16 @@ M: seq-parser (compile) ( parser -- quot )
|
||||||
|
|
||||||
TUPLE: choice-parser parsers ;
|
TUPLE: choice-parser parsers ;
|
||||||
|
|
||||||
MATCH-VARS: ?quot ;
|
|
||||||
|
|
||||||
: choice-pattern ( -- quot )
|
|
||||||
[
|
|
||||||
[ ?quot ] unless*
|
|
||||||
] ;
|
|
||||||
|
|
||||||
M: choice-parser (compile) ( parser -- quot )
|
M: choice-parser (compile) ( parser -- quot )
|
||||||
[
|
[
|
||||||
f ,
|
f ,
|
||||||
parsers>> [ compiled-parser \ ?quot choice-pattern match-replace % ] each
|
parsers>> [ compiled-parser 1quotation , \ unless* , ] each
|
||||||
] [ ] make ;
|
] [ ] make ;
|
||||||
|
|
||||||
TUPLE: repeat0-parser p1 ;
|
TUPLE: repeat0-parser p1 ;
|
||||||
|
|
||||||
|
MATCH-VARS: ?quot ;
|
||||||
|
|
||||||
: (repeat0) ( quot result -- result )
|
: (repeat0) ( quot result -- result )
|
||||||
over call [
|
over call [
|
||||||
[ remaining>> swap (>>remaining) ] 2keep
|
[ remaining>> swap (>>remaining) ] 2keep
|
||||||
|
|
Loading…
Reference in New Issue