From 796981e192e3a2f622be5c3bc455efd1e49bd6af Mon Sep 17 00:00:00 2001 From: Chris Double Date: Sat, 5 Apr 2008 18:19:11 +1300 Subject: [PATCH] Refactor semantic peg parser --- extra/peg/peg.factor | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/extra/peg/peg.factor b/extra/peg/peg.factor index 332f7164f8..ab70745b11 100755 --- a/extra/peg/peg.factor +++ b/extra/peg/peg.factor @@ -392,18 +392,16 @@ MATCH-VARS: ?quot ; MATCH-VARS: ?parser ; -: semantic-pattern ( -- quot ) - [ - ?parser [ - dup parse-result-ast ?quot call [ drop f ] unless - ] [ - f - ] if* - ] ; +: check-semantic ( result quot -- result ) + over [ + over ast>> swap call [ drop f ] unless + ] [ + drop + ] if ; inline M: semantic-parser (compile) ( parser -- quot ) - [ p1>> compiled-parser ] [ quot>> ] bi - 2array { ?parser ?quot } semantic-pattern match-replace ; + [ p1>> compiled-parser 1quotation ] [ quot>> ] bi + '[ @ , check-semantic ] ; TUPLE: ensure-parser p1 ;