From 635b02ca27c57ab6551428089600d9b798a32fc1 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Tue, 26 Feb 2008 17:13:15 -0600 Subject: [PATCH] implement list-of, list-of* in terms of (list-of) add 2choice 3choice --- extra/peg/peg.factor | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/extra/peg/peg.factor b/extra/peg/peg.factor index 6e42668436..ed7012da45 100755 --- a/extra/peg/peg.factor +++ b/extra/peg/peg.factor @@ -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 ;