move words around, some docs, start of case insensitive
parent
95657e5742
commit
df74d3ac62
|
@ -10,6 +10,7 @@ TUPLE: regexp
|
||||||
nfa-table
|
nfa-table
|
||||||
dfa-table
|
dfa-table
|
||||||
minimized-table
|
minimized-table
|
||||||
|
case-insensitive
|
||||||
{ state integer }
|
{ state integer }
|
||||||
{ new-states vector }
|
{ new-states vector }
|
||||||
{ visited-states hashtable } ;
|
{ visited-states hashtable } ;
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
! Copyright (C) 2008 Doug Coleman.
|
||||||
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
|
USING: kernel strings help.markup help.syntax regexp2.backend ;
|
||||||
|
IN: regexp2
|
||||||
|
|
||||||
|
HELP: <regexp>
|
||||||
|
{ $values { "string" string } { "regexp" regexp } }
|
||||||
|
{ $description "Compiles a regular expression into a DFA and returns this object. Regular expressions only have to be compiled once and can then be used multiple times to match input strings." } ;
|
||||||
|
|
||||||
|
HELP: <iregexp>
|
||||||
|
{ $values { "string" string } { "regexp" regexp } }
|
||||||
|
{ $description "Compiles a case-insensitive regular expression into a DFA and returns this object. Otherwise, exactly the same as " { $link <regexp> } } ;
|
||||||
|
|
||||||
|
{ <regexp> <iregexp> } related-words
|
|
@ -1,7 +1,8 @@
|
||||||
! Copyright (C) 2008 Doug Coleman.
|
! Copyright (C) 2008 Doug Coleman.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: accessors combinators kernel regexp2.backend regexp2.utils
|
USING: accessors combinators kernel math math.ranges
|
||||||
regexp2.parser regexp2.nfa regexp2.dfa regexp2.traversal state-tables
|
sequences regexp2.backend regexp2.utils memoize
|
||||||
|
regexp2.parser regexp2.nfa regexp2.dfa regexp2.traversal
|
||||||
regexp2.transition-tables ;
|
regexp2.transition-tables ;
|
||||||
IN: regexp2
|
IN: regexp2
|
||||||
|
|
||||||
|
@ -13,8 +14,7 @@ IN: regexp2
|
||||||
<transition-table> >>minimized-table
|
<transition-table> >>minimized-table
|
||||||
reset-regexp ;
|
reset-regexp ;
|
||||||
|
|
||||||
: <regexp> ( string -- regexp )
|
: construct-regexp ( regexp -- regexp' )
|
||||||
default-regexp
|
|
||||||
{
|
{
|
||||||
[ parse-regexp ]
|
[ parse-regexp ]
|
||||||
[ construct-nfa ]
|
[ construct-nfa ]
|
||||||
|
@ -22,6 +22,22 @@ IN: regexp2
|
||||||
[ ]
|
[ ]
|
||||||
} cleave ;
|
} cleave ;
|
||||||
|
|
||||||
|
: match ( string regexp -- pair )
|
||||||
|
<dfa-traverser> do-match return-match ;
|
||||||
|
|
||||||
|
: matches? ( string regexp -- ? )
|
||||||
|
dupd match [ [ length ] [ range-length 1- ] bi* = ] [ drop f ] if* ;
|
||||||
|
|
||||||
|
: match-head ( string regexp -- end ) match length>> 1- ;
|
||||||
|
|
||||||
|
MEMO: <regexp> ( string -- regexp )
|
||||||
|
default-regexp construct-regexp ;
|
||||||
|
|
||||||
|
MEMO: <iregexp> ( string -- regexp )
|
||||||
|
default-regexp
|
||||||
|
t >>case-insensitive
|
||||||
|
construct-regexp ;
|
||||||
|
|
||||||
: R! CHAR: ! <regexp> ; parsing
|
: R! CHAR: ! <regexp> ; parsing
|
||||||
: R" CHAR: " <regexp> ; parsing
|
: R" CHAR: " <regexp> ; parsing
|
||||||
: R# CHAR: # <regexp> ; parsing
|
: R# CHAR: # <regexp> ; parsing
|
||||||
|
|
|
@ -78,11 +78,3 @@ TUPLE: dfa-traverser
|
||||||
dup matches>>
|
dup matches>>
|
||||||
[ drop f ]
|
[ drop f ]
|
||||||
[ [ start-index>> ] [ peek ] bi* 1 <range> ] if-empty ;
|
[ [ start-index>> ] [ peek ] bi* 1 <range> ] if-empty ;
|
||||||
|
|
||||||
: match ( string regexp -- pair )
|
|
||||||
<dfa-traverser> do-match return-match ;
|
|
||||||
|
|
||||||
: matches? ( string regexp -- ? )
|
|
||||||
dupd match [ [ length ] [ range-length 1- ] bi* = ] [ drop f ] if* ;
|
|
||||||
|
|
||||||
: match-head ( string regexp -- end ) match length>> 1- ;
|
|
||||||
|
|
Loading…
Reference in New Issue