matches? works as expected for reversed regexps

db4
Daniel Ehrenberg 2009-03-10 19:17:25 -05:00
parent 987cd1c8ce
commit 8836b2a73b
2 changed files with 13 additions and 10 deletions

View File

@ -211,8 +211,8 @@ IN: regexp-tests
[ f ] [ "aaaxb" "a+ab" <regexp> matches? ] unit-test
[ t ] [ "aaacb" "a+cb" <regexp> matches? ] unit-test
[ 3 ] [ "aaacb" "a*" <regexp> match-index-head ] unit-test
[ 2 ] [ "aaacb" "aa?" <regexp> match-index-head ] unit-test
[ "aaa" ] [ "aaacb" "a*" <regexp> match-head >string ] unit-test
[ "aa" ] [ "aaacb" "aa?" <regexp> match-head >string ] unit-test
[ t ] [ "aaa" R/ AAA/i matches? ] unit-test
[ f ] [ "aax" R/ AAA/i matches? ] unit-test
@ -310,8 +310,8 @@ IN: regexp-tests
[ "a" ] [ "ba" "(?<=b)(?<=b)a" <regexp> match-head >string ] unit-test
[ "a" ] [ "cab" "(?<=c)a(?=b)" <regexp> match-head >string ] unit-test
[ 3 ] [ "foobar" "foo(?=bar)" <regexp> match-index-head ] unit-test
[ f ] [ "foobxr" "foo(?=bar)" <regexp> match-index-head ] unit-test
[ 3 ] [ "foobar" "foo(?=bar)" <regexp> match-head length ] unit-test
[ f ] [ "foobxr" "foo(?=bar)" <regexp> match-head ] unit-test
! Bug in parsing word
[ t ] [ "a" R' a' matches? ] unit-test
@ -424,8 +424,8 @@ IN: regexp-tests
[ 1 ] [ "a\r" R/ a$/m count-matches ] unit-test
[ 1 ] [ "a\r\n" R/ a$/m count-matches ] unit-test
[ f ] [ "foobxr" "foo\\z" <regexp> match-index-head ] unit-test
[ 3 ] [ "foo" "foo\\z" <regexp> match-index-head ] unit-test
[ f ] [ "foobxr" "foo\\z" <regexp> match-head ] unit-test
[ 3 ] [ "foo" "foo\\z" <regexp> match-head length ] unit-test
! [ t ] [ "foo" "\\bfoo\\b" <regexp> matches? ] unit-test
! [ t ] [ "afoob" "\\Bfoo\\B" <regexp> matches? ] unit-test

View File

@ -44,14 +44,17 @@ M: lookbehind question>quot ! Returns ( index string -- ? )
! and that string is a string.
dup dfa>> execute( index string regexp -- i/f ) ;
: match-index-head ( string regexp -- index/f )
[ 0 ] 2dip [ check-string ] dip match-index-from ;
GENERIC: end/start ( string regexp -- end start )
M: regexp end/start drop length 0 ;
M: reverse-regexp end/start drop length 1- -1 swap ;
PRIVATE>
: matches? ( string regexp -- ? )
dupd match-index-head
[ swap length = ] [ drop f ] if* ;
[ end/start ] 2keep
[ check-string ] dip
match-index-from
[ swap = ] [ drop f ] if* ;
<PRIVATE