more slices in regexps, change unit tests
parent
a5c4463e34
commit
86546552d3
|
@ -326,26 +326,26 @@ IN: regexp-tests
|
|||
! "a(?#bcdefg)bcd" <regexp> "abcdefg" over first-match
|
||||
! "a(?:bcdefg)" <regexp> "abcdefg" over first-match
|
||||
|
||||
[ { 0 1 } ] [ "ac" "a(?!b)" <regexp> first-match ] unit-test
|
||||
[ "a" ] [ "ac" "a(?!b)" <regexp> first-match >string ] unit-test
|
||||
[ f ] [ "ab" "a(?!b)" <regexp> first-match ] unit-test
|
||||
|
||||
! "a(?<=b)" <regexp> "caba" over first-match
|
||||
|
||||
[ { 0 1 } ] [ "ab" "a(?=b)(?=b)" <regexp> first-match ] unit-test
|
||||
[ { 1 2 } ] [ "ba" "a(?<=b)(?<=b)" <regexp> first-match ] unit-test
|
||||
[ { 1 2 } ] [ "cab" "a(?=b)(?<=c)" <regexp> first-match ] unit-test
|
||||
[ "a" ] [ "ab" "a(?=b)(?=b)" <regexp> first-match >string ] unit-test
|
||||
[ "a" ] [ "ba" "a(?<=b)(?<=b)" <regexp> first-match >string ] unit-test
|
||||
[ "a" ] [ "cab" "a(?=b)(?<=c)" <regexp> first-match >string ] unit-test
|
||||
|
||||
! capture group 1: "aaaa" 2: ""
|
||||
! "aaaa" "(a*)(a*)" <regexp> match*
|
||||
! "aaaa" "(a*)(a+)" <regexp> match*
|
||||
|
||||
[ { 0 2 } ] [ "ab" "(a|ab)(bc)?" <regexp> first-match ] unit-test
|
||||
[ { 0 3 } ] [ "abc" "(a|ab)(bc)?" <regexp> first-match ] unit-test
|
||||
[ "ab" ] [ "ab" "(a|ab)(bc)?" <regexp> first-match >string ] unit-test
|
||||
[ "abc" ] [ "abc" "(a|ab)(bc)?" <regexp> first-match >string ] unit-test
|
||||
|
||||
[ { 0 2 } ] [ "ab" "(ab|a)(bc)?" <regexp> first-match ] unit-test
|
||||
[ { 0 3 } ] [ "abc" "(ab|a)(bc)?" <regexp> first-match ] unit-test
|
||||
[ "ab" ] [ "ab" "(ab|a)(bc)?" <regexp> first-match >string ] unit-test
|
||||
[ "abc" ] [ "abc" "(ab|a)(bc)?" <regexp> first-match >string ] unit-test
|
||||
|
||||
[ { 23 24 } ] [ "aaaaaaaaaaaaaaaaaaaaaaab" "((a*)*b)*b" <regexp> first-match ] unit-test
|
||||
[ "b" ] [ "aaaaaaaaaaaaaaaaaaaaaaab" "((a*)*b)*b" <regexp> first-match >string ] unit-test
|
||||
|
||||
[ t ] [ "a:b" ".+:?" <regexp> matches? ] unit-test
|
||||
|
||||
|
|
|
@ -25,11 +25,14 @@ IN: regexp
|
|||
[ ]
|
||||
} cleave ;
|
||||
|
||||
: match ( string regexp -- pair )
|
||||
<dfa-traverser> do-match return-match ;
|
||||
: (match) ( string regexp -- dfa-traverser )
|
||||
<dfa-traverser> do-match ; inline
|
||||
|
||||
: match* ( string regexp -- pair captured-groups )
|
||||
<dfa-traverser> do-match [ return-match ] [ captured-groups>> ] bi ;
|
||||
: match ( string regexp -- slice/f )
|
||||
(match) return-match ;
|
||||
|
||||
: match* ( string regexp -- slice/f captured-groups )
|
||||
(match) [ return-match ] [ captured-groups>> ] bi ;
|
||||
|
||||
: matches? ( string regexp -- ? )
|
||||
dupd match
|
||||
|
@ -50,7 +53,7 @@ IN: regexp
|
|||
] if ;
|
||||
|
||||
: first-match ( string regexp -- pair/f )
|
||||
0 swap match-range dup [ 2array ] [ 2drop f ] if ;
|
||||
dupd 0 swap match-range rot over [ <slice> ] [ 3drop f ] if ;
|
||||
|
||||
: re-cut ( string regexp -- end/f start )
|
||||
dupd first-match
|
||||
|
@ -66,9 +69,7 @@ IN: regexp
|
|||
|
||||
: next-match ( string regexp -- end/f match/f )
|
||||
dupd first-match dup
|
||||
[ [ second tail-slice ] keep ]
|
||||
[ 2drop f f ]
|
||||
if ;
|
||||
[ [ length 1+ tail-slice ] keep ] [ 2drop f f ] if ;
|
||||
|
||||
: all-matches ( string regexp -- seq )
|
||||
[ dup ] swap '[ _ next-match ] [ ] produce nip ;
|
||||
|
|
Loading…
Reference in New Issue