implement list-of, list-of* in terms of (list-of)

add 2choice 3choice
db4
Doug Coleman 2008-02-26 17:13:15 -06:00
parent 11147c7bc0
commit 635b02ca27
1 changed files with 14 additions and 1 deletions

View File

@ -318,6 +318,12 @@ MEMO: range ( min max -- parser )
: choice ( seq -- parser )
choice-parser construct-boa init-parser ;
: 2choice ( parser1 parser2 -- parser )
2array choice ;
: 3choice ( parser1 parser2 parser3 -- parser )
3array choice ;
: choice* ( quot -- paser )
{ } make choice ; inline
@ -348,8 +354,15 @@ MEMO: hide ( parser -- parser )
MEMO: delay ( parser -- parser )
delay-parser construct-boa init-parser ;
MEMO: (list-of) ( items separator repeat1? -- parser )
>r over 2seq r> [ repeat1 ] [ repeat0 ] if [ concat ] action 2seq
[ unclip 1vector swap first append ] action ;
MEMO: list-of ( items separator -- parser )
hide over 2seq repeat0 [ concat ] action 2seq [ unclip 1vector swap first append ] action ;
hide f (list-of) ;
MEMO: list-of* ( items separator -- parser )
hide t (list-of) ;
MEMO: 'digit' ( -- parser )
[ digit? ] satisfy [ digit> ] action ;