Get regexp words to infer

db4
Slava Pestov 2008-11-17 21:42:59 -06:00
parent d6dd9ea2a3
commit 5c51d9fd2c
5 changed files with 11 additions and 5 deletions

View File

@ -137,7 +137,7 @@ ERROR: bad-special-group string ;
DEFER: (parse-regexp)
: nested-parse-regexp ( token ? -- )
[ push-stack (parse-regexp) pop-stack ] dip
[ <negation> ] when pop-stack boa push-stack ;
[ <negation> ] when pop-stack new swap >>term push-stack ;
! non-capturing groups
: (parse-special-group) ( -- )

View File

@ -2,6 +2,9 @@ USING: regexp tools.test kernel sequences regexp.parser
regexp.traversal eval ;
IN: regexp-tests
\ <regexp> must-infer
\ matches? must-infer
[ f ] [ "b" "a*" <regexp> matches? ] unit-test
[ t ] [ "" "a*" <regexp> matches? ] unit-test
[ t ] [ "a" "a*" <regexp> matches? ] unit-test

View File

@ -107,7 +107,8 @@ M: capture-group-off flag-action ( dfa-traverser flag -- )
: increment-state ( dfa-traverser state -- dfa-traverser )
[
dup traverse-forward>>
[ 1+ ] [ 1- ] ? change-current-index
[ [ 1+ ] change-current-index ]
[ [ 1- ] change-current-index ] if
dup current-state>> >>last-state
] dip
first >>current-state ;

View File

@ -0,0 +1,4 @@
USING: regexp.utils tools.test ;
IN: regexp.utils.tests
[ [ ] [ ] while-changes ] must-infer

View File

@ -5,9 +5,7 @@ namespaces regexp.backend sequences unicode.categories
math.ranges fry combinators.short-circuit vectors ;
IN: regexp.utils
: (while-changes) ( obj quot pred pred-ret -- obj )
! quot: ( obj -- obj' )
! pred: ( obj -- <=> )
: (while-changes) ( obj quot: ( obj -- obj' ) pred: ( obj -- <=> ) pred-ret -- obj )
[ [ dup slip ] dip pick over call ] dip dupd =
[ 3drop ] [ (while-changes) ] if ; inline recursive