From d93c7958fdad169d99dc1ddeb1ef01cae6594b0f Mon Sep 17 00:00:00 2001 From: Chris Double Date: Sat, 5 Apr 2008 18:33:50 +1300 Subject: [PATCH] Refactor action peg parser --- extra/peg/peg.factor | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/extra/peg/peg.factor b/extra/peg/peg.factor index 7970d761de..fd41a67bfe 100755 --- a/extra/peg/peg.factor +++ b/extra/peg/peg.factor @@ -423,17 +423,16 @@ TUPLE: action-parser p1 quot ; MATCH-VARS: ?action ; -: action-pattern ( -- quot ) - [ - ?quot dup [ - dup ast>> ?action call - >>ast - ] when - ] ; +: check-action ( result quot -- result ) + over [ + over ast>> swap call >>ast + ] [ + drop + ] if ; inline M: action-parser (compile) ( parser -- quot ) - [ p1>> compiled-parser ] [ quot>> ] bi - 2array { ?quot ?action } action-pattern match-replace ; + [ p1>> compiled-parser 1quotation ] [ quot>> ] bi '[ + @ , check-action ] ; : left-trim-slice ( string -- string ) #! Return a new string without any leading whitespace