: find-transitions ( seq1 regexp -- seq2 )
nfa-table>> transitions>>
- [ at keys ] curry map concat
+ [ at keys ] curry gather
eps swap remove ;
: add-todo-state ( state regexp -- )
! clear "a$" <regexp> "a\n" over match
! clear "a$" <regexp> "a\r" over match
! clear "a$" <regexp> "a\r\n" over match
+
+! "(az)(?<=b)" <regexp> "baz" over first-match
+! "a(?<=b*)" <regexp> "cbaz" over first-match
+! "a(?<=b)" <regexp> "baz" over first-match
+
+! "a(?<!b)" <regexp> "baz" over first-match
+! "a(?<!b)" <regexp> "caz" over first-match
key? ;
: text-finished? ( dfa-traverser -- ? )
- [ current-index>> ] [ text>> length ] bi >= ;
+ {
+ [ current-state>> empty? ]
+ [ [ current-index>> ] [ text>> length ] bi >= ]
+ ! [ current-index>> 0 < ]
+ } 1|| ;
: save-final-state ( dfa-straverser -- )
[ current-index>> ] [ matches>> ] bi push ;
M: lookbehind-on flag-action ( dfa-traverser flag -- )
drop
f >>traverse-forward
+ [ 2 - ] change-current-index
lookbehind-counters>> 0 swap push ;
M: lookbehind-off flag-action ( dfa-traverser flag -- )
drop
t >>traverse-forward
dup lookbehind-counters>>
- [ drop ] [ pop '[ _ + ] change-current-index drop ] if-empty ;
+ [ drop ] [ pop '[ _ + 2 + ] change-current-index drop ] if-empty ;
: process-flags ( dfa-traverser -- )
[ [ 1+ ] map ] change-lookahead-counters
+ [ [ 1+ ] map ] change-lookbehind-counters
+ ! dup current-state>> .
dup [ current-state>> ] [ traversal-flags>> ] bi
at [ dup . flag-action ] with each ;
: increment-state ( dfa-traverser state -- dfa-traverser )
[
dup traverse-forward>>
- [ [ 1+ ] change-current-index ]
- [ [ 1- ] change-current-index ] if
+ [ 1+ ] [ 1- ] ? change-current-index
dup current-state>> >>last-state
] dip
first >>current-state ;