From 40009dac8793f6f1972c120446512b0078f08f61 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Fri, 19 Sep 2008 15:14:05 -0500 Subject: [PATCH] add match-range to regexp --- unfinished/regexp/regexp.factor | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/unfinished/regexp/regexp.factor b/unfinished/regexp/regexp.factor index 47c6e52c39..85bdccc2f4 100644 --- a/unfinished/regexp/regexp.factor +++ b/unfinished/regexp/regexp.factor @@ -33,7 +33,19 @@ IN: regexp dupd match [ [ length ] [ length>> 1- ] bi* = ] [ drop f ] if* ; -: match-head ( string regexp -- end ) match length>> 1- ; +: match-head ( string regexp -- end/f ) match [ length>> 1- ] [ f ] if* ; + +: match-at ( string m regexp -- n/f finished? ) + [ + 2dup swap length > [ 2drop f f ] [ tail-slice t ] if + ] dip swap [ match-head f ] [ 2drop f t ] if ; + +: match-range ( string m regexp -- a/f b/f ) + 3dup match-at over [ + drop nip rot drop dupd + + ] [ + [ 3drop drop f f ] [ drop [ 1+ ] dip match-range ] if + ] if ; : initial-option ( regexp option -- regexp' ) over options>> conjoin ;