Refactor range peg parser

db4
Chris Double 2008-04-05 17:30:10 +13:00
parent 80d11405a9
commit 7b73d2734f
1 changed files with 10 additions and 15 deletions

View File

@ -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 <parse-result>
] [
drop f
] [
0 over nth dup
?min ?max between? [
[ 1 tail-slice ] dip <parse-result>
] [
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 ;