Merge branch 'master' of git://factorcode.org/git/factor

db4
Doug Coleman 2008-08-21 13:09:38 -05:00
commit 88134e539f
4 changed files with 35 additions and 12 deletions

View File

@ -10,6 +10,7 @@ TUPLE: regexp
nfa-table
dfa-table
minimized-table
case-insensitive
{ state integer }
{ new-states vector }
{ visited-states hashtable } ;

View File

@ -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

View File

@ -1,7 +1,8 @@
! Copyright (C) 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors combinators kernel regexp2.backend regexp2.utils
regexp2.parser regexp2.nfa regexp2.dfa regexp2.traversal state-tables
USING: accessors combinators kernel math math.ranges
sequences regexp2.backend regexp2.utils memoize
regexp2.parser regexp2.nfa regexp2.dfa regexp2.traversal
regexp2.transition-tables ;
IN: regexp2
@ -13,8 +14,7 @@ IN: regexp2
<transition-table> >>minimized-table
reset-regexp ;
: <regexp> ( string -- regexp )
default-regexp
: construct-regexp ( regexp -- regexp' )
{
[ parse-regexp ]
[ construct-nfa ]
@ -22,6 +22,22 @@ IN: regexp2
[ ]
} 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

View File

@ -78,11 +78,3 @@ TUPLE: dfa-traverser
dup matches>>
[ drop f ]
[ [ 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- ;