Refactor range peg parser
parent
80d11405a9
commit
7b73d2734f
|
@ -297,24 +297,19 @@ M: satisfy-parser (compile) ( parser -- quot )
|
||||||
|
|
||||||
TUPLE: range-parser min max ;
|
TUPLE: range-parser min max ;
|
||||||
|
|
||||||
MATCH-VARS: ?min ?max ;
|
: parse-range ( input min max -- result )
|
||||||
|
pick empty? [
|
||||||
: range-pattern ( -- quot )
|
3drop f
|
||||||
[
|
] [
|
||||||
input-slice dup empty? [
|
pick first -rot between? [
|
||||||
|
unclip-slice <parse-result>
|
||||||
|
] [
|
||||||
drop f
|
drop f
|
||||||
] [
|
] if
|
||||||
0 over nth dup
|
] if ;
|
||||||
?min ?max between? [
|
|
||||||
[ 1 tail-slice ] dip <parse-result>
|
|
||||||
] [
|
|
||||||
2drop f
|
|
||||||
] if
|
|
||||||
] if
|
|
||||||
] ;
|
|
||||||
|
|
||||||
M: range-parser (compile) ( parser -- quot )
|
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 ;
|
TUPLE: seq-parser parsers ;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue