From 226d211342bef6b64354396fbcbb06e49700b5dc Mon Sep 17 00:00:00 2001 From: Chris Double Date: Sat, 5 Apr 2008 17:54:18 +1300 Subject: [PATCH] Refactor choice peg parser --- extra/peg/peg.factor | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/extra/peg/peg.factor b/extra/peg/peg.factor index 8c92605c44..465e0dd757 100755 --- a/extra/peg/peg.factor +++ b/extra/peg/peg.factor @@ -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