unbreak regexp2 for fry change, use dip some, pprint*, make \^ and \$ parse
parent
71252506f3
commit
dab32f7abe
|
@ -21,7 +21,6 @@ TUPLE: regexp
|
||||||
0 >>state
|
0 >>state
|
||||||
V{ } clone >>stack
|
V{ } clone >>stack
|
||||||
V{ } clone >>new-states
|
V{ } clone >>new-states
|
||||||
H{ } clone >>options
|
|
||||||
H{ } clone >>visited-states ;
|
H{ } clone >>visited-states ;
|
||||||
|
|
||||||
SYMBOL: current-regexp
|
SYMBOL: current-regexp
|
||||||
|
|
|
@ -15,7 +15,7 @@ IN: regexp2.dfa
|
||||||
eps swap find-delta ;
|
eps swap find-delta ;
|
||||||
|
|
||||||
: find-epsilon-closure ( states regexp -- new-states )
|
: find-epsilon-closure ( states regexp -- new-states )
|
||||||
'[ dup , (find-epsilon-closure) union ] [ length ] while-changes
|
'[ dup _ (find-epsilon-closure) union ] [ length ] while-changes
|
||||||
natural-sort ;
|
natural-sort ;
|
||||||
|
|
||||||
: find-closure ( states transition regexp -- new-states )
|
: find-closure ( states transition regexp -- new-states )
|
||||||
|
|
|
@ -291,6 +291,8 @@ ERROR: bad-escaped-literals seq ;
|
||||||
{ CHAR: f [ HEX: c <constant> ] }
|
{ CHAR: f [ HEX: c <constant> ] }
|
||||||
{ CHAR: a [ HEX: 7 <constant> ] }
|
{ CHAR: a [ HEX: 7 <constant> ] }
|
||||||
{ CHAR: e [ HEX: 1b <constant> ] }
|
{ CHAR: e [ HEX: 1b <constant> ] }
|
||||||
|
{ CHAR: $ [ CHAR: $ <constant> ] }
|
||||||
|
{ CHAR: ^ [ CHAR: ^ <constant> ] }
|
||||||
|
|
||||||
{ CHAR: d [ digit-class ] }
|
{ CHAR: d [ digit-class ] }
|
||||||
{ CHAR: D [ digit-class <negation> ] }
|
{ CHAR: D [ digit-class <negation> ] }
|
||||||
|
|
|
@ -222,6 +222,8 @@ IN: regexp2-tests
|
||||||
<regexp> drop
|
<regexp> drop
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
|
[ ] [ "(\\$[\\p{XDigit}]|[\\p{Digit}])" <regexp> drop ] unit-test
|
||||||
|
|
||||||
! Comment
|
! Comment
|
||||||
[ t ] [ "ac" "a(?#boo)c" <regexp> matches? ] unit-test
|
[ t ] [ "ac" "a(?#boo)c" <regexp> matches? ] unit-test
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,8 @@
|
||||||
USING: accessors combinators kernel math math.ranges
|
USING: accessors combinators kernel math math.ranges
|
||||||
sequences regexp2.backend regexp2.utils memoize sets
|
sequences regexp2.backend regexp2.utils memoize sets
|
||||||
regexp2.parser regexp2.nfa regexp2.dfa regexp2.traversal
|
regexp2.parser regexp2.nfa regexp2.dfa regexp2.traversal
|
||||||
regexp2.transition-tables ;
|
regexp2.transition-tables assocs prettyprint.backend
|
||||||
|
make ;
|
||||||
IN: regexp2
|
IN: regexp2
|
||||||
|
|
||||||
: default-regexp ( string -- regexp )
|
: default-regexp ( string -- regexp )
|
||||||
|
@ -14,6 +15,7 @@ IN: regexp2
|
||||||
<transition-table> >>minimized-table
|
<transition-table> >>minimized-table
|
||||||
H{ } clone >>nfa-traversal-flags
|
H{ } clone >>nfa-traversal-flags
|
||||||
H{ } clone >>dfa-traversal-flags
|
H{ } clone >>dfa-traversal-flags
|
||||||
|
H{ } clone >>options
|
||||||
reset-regexp ;
|
reset-regexp ;
|
||||||
|
|
||||||
: construct-regexp ( regexp -- regexp' )
|
: construct-regexp ( regexp -- regexp' )
|
||||||
|
@ -60,3 +62,30 @@ IN: regexp2
|
||||||
: R` CHAR: ` <regexp> ; parsing
|
: R` CHAR: ` <regexp> ; parsing
|
||||||
: R{ CHAR: } <regexp> ; parsing
|
: R{ CHAR: } <regexp> ; parsing
|
||||||
: R| CHAR: | <regexp> ; parsing
|
: R| CHAR: | <regexp> ; parsing
|
||||||
|
|
||||||
|
: find-regexp-syntax ( string -- prefix suffix )
|
||||||
|
{
|
||||||
|
{ "R/ " "/" }
|
||||||
|
{ "R! " "!" }
|
||||||
|
{ "R\" " "\"" }
|
||||||
|
{ "R# " "#" }
|
||||||
|
{ "R' " "'" }
|
||||||
|
{ "R( " ")" }
|
||||||
|
{ "R@ " "@" }
|
||||||
|
{ "R[ " "]" }
|
||||||
|
{ "R` " "`" }
|
||||||
|
{ "R{ " "}" }
|
||||||
|
{ "R| " "|" }
|
||||||
|
} swap [ subseq? not nip ] curry assoc-find drop ;
|
||||||
|
|
||||||
|
: option? ( option regexp -- ? )
|
||||||
|
options>> key? ;
|
||||||
|
|
||||||
|
M: regexp pprint*
|
||||||
|
[
|
||||||
|
[
|
||||||
|
dup raw>>
|
||||||
|
dup find-regexp-syntax swap % swap % %
|
||||||
|
case-insensitive swap option? [ "i" % ] when
|
||||||
|
] "" make
|
||||||
|
] keep present-text ;
|
||||||
|
|
|
@ -45,7 +45,9 @@ TUPLE: dfa-traverser
|
||||||
] when text-finished? ;
|
] when text-finished? ;
|
||||||
|
|
||||||
: increment-state ( dfa-traverser state -- dfa-traverser )
|
: increment-state ( dfa-traverser state -- dfa-traverser )
|
||||||
>r [ 1+ ] change-current-index dup current-state>> >>last-state r>
|
[
|
||||||
|
[ 1+ ] change-current-index dup current-state>> >>last-state
|
||||||
|
] dip
|
||||||
first >>current-state ;
|
first >>current-state ;
|
||||||
|
|
||||||
: match-failed ( dfa-traverser -- dfa-traverser )
|
: match-failed ( dfa-traverser -- dfa-traverser )
|
||||||
|
|
|
@ -9,7 +9,7 @@ IN: regexp2.utils
|
||||||
: (while-changes) ( obj quot pred pred-ret -- obj )
|
: (while-changes) ( obj quot pred pred-ret -- obj )
|
||||||
! quot: ( obj -- obj' )
|
! quot: ( obj -- obj' )
|
||||||
! pred: ( obj -- <=> )
|
! pred: ( obj -- <=> )
|
||||||
>r >r dup slip r> pick over call r> dupd =
|
[ [ dup slip ] dip pick over call ] dip dupd =
|
||||||
[ 3drop ] [ (while-changes) ] if ; inline recursive
|
[ 3drop ] [ (while-changes) ] if ; inline recursive
|
||||||
|
|
||||||
: while-changes ( obj quot pred -- obj' )
|
: while-changes ( obj quot pred -- obj' )
|
||||||
|
|
Loading…
Reference in New Issue