Add some words
parent
22f9478c5e
commit
4fab0695b8
|
@ -1,10 +1,9 @@
|
||||||
! 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 math math.ranges
|
USING: accessors combinators kernel math math.ranges sequences
|
||||||
sequences regexp.backend regexp.utils memoize sets
|
sets assocs prettyprint.backend make lexer namespaces parser
|
||||||
regexp.parser regexp.nfa regexp.dfa regexp.traversal
|
arrays fry regexp.backend regexp.utils regexp.parser regexp.nfa
|
||||||
regexp.transition-tables assocs prettyprint.backend
|
regexp.dfa regexp.traversal regexp.transition-tables ;
|
||||||
make lexer namespaces parser ;
|
|
||||||
IN: regexp
|
IN: regexp
|
||||||
|
|
||||||
: default-regexp ( string -- regexp )
|
: default-regexp ( string -- regexp )
|
||||||
|
@ -47,6 +46,33 @@ IN: regexp
|
||||||
[ 3drop drop f f ] [ drop [ 1+ ] dip match-range ] if
|
[ 3drop drop f f ] [ drop [ 1+ ] dip match-range ] if
|
||||||
] if ;
|
] if ;
|
||||||
|
|
||||||
|
: first-match ( string regexp -- pair/f )
|
||||||
|
0 swap match-range dup [ 2array ] [ 2drop f ] if ;
|
||||||
|
|
||||||
|
: re-cut ( string regexp -- end/f start )
|
||||||
|
dupd first-match
|
||||||
|
[ [ second tail-slice ] [ first head ] 2bi ]
|
||||||
|
[ "" like f swap ]
|
||||||
|
if* ;
|
||||||
|
|
||||||
|
: re-split ( string regexp -- seq )
|
||||||
|
[ dup ] swap '[ _ re-cut ] [ ] produce nip ;
|
||||||
|
|
||||||
|
: re-replace ( string regexp replacement -- result )
|
||||||
|
[ re-split ] dip join ;
|
||||||
|
|
||||||
|
: next-match ( string regexp -- end/f match/f )
|
||||||
|
dupd first-match dup
|
||||||
|
[ [ second tail-slice ] keep ]
|
||||||
|
[ 2drop f f ]
|
||||||
|
if ;
|
||||||
|
|
||||||
|
: all-matches ( string regexp -- seq )
|
||||||
|
[ dup ] swap '[ _ next-match ] [ ] produce nip ;
|
||||||
|
|
||||||
|
: count-matches ( string regexp -- n )
|
||||||
|
all-matches length 1- ;
|
||||||
|
|
||||||
: initial-option ( regexp option -- regexp' )
|
: initial-option ( regexp option -- regexp' )
|
||||||
over options>> conjoin ;
|
over options>> conjoin ;
|
||||||
|
|
||||||
|
@ -102,8 +128,6 @@ IN: regexp
|
||||||
: option? ( option regexp -- ? )
|
: option? ( option regexp -- ? )
|
||||||
options>> key? ;
|
options>> key? ;
|
||||||
|
|
||||||
USE: multiline
|
|
||||||
/*
|
|
||||||
M: regexp pprint*
|
M: regexp pprint*
|
||||||
[
|
[
|
||||||
[
|
[
|
||||||
|
@ -112,4 +136,3 @@ M: regexp pprint*
|
||||||
case-insensitive swap option? [ "i" % ] when
|
case-insensitive swap option? [ "i" % ] when
|
||||||
] "" make
|
] "" make
|
||||||
] keep present-text ;
|
] keep present-text ;
|
||||||
*/
|
|
||||||
|
|
Loading…
Reference in New Issue