Finish cleanup of regexp
parent
b8845cb87e
commit
77b069ee5c
basis/regexp
|
@ -41,11 +41,11 @@ IN: regexp.dfa
|
|||
|
||||
:: new-transitions ( nfa dfa new-states visited-states -- nfa dfa )
|
||||
new-states [ nfa dfa ] [
|
||||
new-states pop :> state
|
||||
state nfa-table find-transitions
|
||||
pop :> state
|
||||
state nfa find-transitions
|
||||
[| trans |
|
||||
state trans nfa find-closure :> new-state
|
||||
state visited-states new-state add-todo-state
|
||||
new-state visited-states new-states add-todo-state
|
||||
state new-state trans transition make-transition dfa add-transition
|
||||
] each
|
||||
nfa dfa new-states visited-states new-transitions
|
||||
|
|
|
@ -7,11 +7,22 @@ regexp.parser regexp.nfa regexp.dfa regexp.traversal
|
|||
regexp.transition-tables splitting sorting regexp.ast ;
|
||||
IN: regexp
|
||||
|
||||
TUPLE: regexp raw options parse-tree dfa ;
|
||||
TUPLE: regexp raw parse-tree options dfa ;
|
||||
|
||||
: <optioned-regexp> ( string options -- regexp )
|
||||
[ dup parse-regexp ] [ string>options ] bi*
|
||||
2dup <with-options> construct-nfa construct-dfa
|
||||
regexp boa ;
|
||||
|
||||
: <regexp> ( string -- regexp ) "" <optioned-regexp> ;
|
||||
|
||||
<PRIVATE
|
||||
|
||||
: (match) ( string regexp -- dfa-traverser )
|
||||
dfa>> <dfa-traverser> do-match ; inline
|
||||
|
||||
PRIVATE>
|
||||
|
||||
: match ( string regexp -- slice/f )
|
||||
(match) return-match ;
|
||||
|
||||
|
@ -40,9 +51,13 @@ TUPLE: regexp raw options parse-tree dfa ;
|
|||
dupd first-match
|
||||
[ split1-slice swap ] [ "" like f swap ] if* ;
|
||||
|
||||
<PRIVATE
|
||||
|
||||
: (re-split) ( string regexp -- )
|
||||
over [ [ re-cut , ] keep (re-split) ] [ 2drop ] if ;
|
||||
|
||||
PRIVATE>
|
||||
|
||||
: re-split ( string regexp -- seq )
|
||||
[ (re-split) ] { } make ;
|
||||
|
||||
|
@ -76,22 +91,6 @@ TUPLE: regexp raw options parse-tree dfa ;
|
|||
{ "R| " "|" }
|
||||
} swap [ subseq? not nip ] curry assoc-find drop ;
|
||||
|
||||
PRIVATE>
|
||||
|
||||
:: <optioned-regexp> ( string options -- regexp )
|
||||
string parse-regexp :> tree
|
||||
options parse-options :> opt
|
||||
tree opt <with-options> :> ast
|
||||
regexp new
|
||||
string >>raw
|
||||
opt >>options
|
||||
tree >>parse-tree
|
||||
tree opt <with-options> construct-nfa construct-dfa >>dfa ;
|
||||
|
||||
: <regexp> ( string -- regexp ) "" <optioned-regexp> ;
|
||||
|
||||
<PRIVATE
|
||||
|
||||
: parsing-regexp ( accum end -- accum )
|
||||
lexer get dup skip-blank
|
||||
[ [ index-from dup 1+ swap ] 2keep swapd subseq swap ] change-lexer-column
|
||||
|
|
Loading…
Reference in New Issue