From 7b73d2734fde7387c060816ceee79977404d0671 Mon Sep 17 00:00:00 2001 From: Chris Double Date: Sat, 5 Apr 2008 17:30:10 +1300 Subject: [PATCH] Refactor range peg parser --- extra/peg/peg.factor | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/extra/peg/peg.factor b/extra/peg/peg.factor index 5ee497707d..671b63949f 100755 --- a/extra/peg/peg.factor +++ b/extra/peg/peg.factor @@ -297,24 +297,19 @@ M: satisfy-parser (compile) ( parser -- quot ) TUPLE: range-parser min max ; -MATCH-VARS: ?min ?max ; - -: range-pattern ( -- quot ) - [ - input-slice dup empty? [ +: parse-range ( input min max -- result ) + pick empty? [ + 3drop f + ] [ + pick first -rot between? [ + unclip-slice + ] [ drop f - ] [ - 0 over nth dup - ?min ?max between? [ - [ 1 tail-slice ] dip - ] [ - 2drop f - ] if - ] if - ] ; + ] if + ] if ; M: range-parser (compile) ( parser -- quot ) - T{ range-parser _ ?min ?max } range-pattern match-replace ; + [ min>> ] [ max>> ] bi '[ input-slice , , parse-range ] ; TUPLE: seq-parser parsers ;