1 ! Copyright (C) 2009 Daniel Ehrenberg
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors kernel regexp regexp.ast regexp.classes
9 : modify-regexp ( regexp raw-quot tree-quot -- new-regexp )
11 [ '[ parse-tree>> @ ] ] bi* bi
16 CONSTANT: <nothing> R/ (?~.*)/s
18 : <literal> ( string -- regexp )
19 [ "\\Q" "\\E" surround ] [ <concatenation> ] bi make-regexp ; foldable
21 : <char-range> ( char1 char2 -- regexp )
22 [ [ 1string ] bi@ [ "[" "-" surround ] [ "]" append ] bi* append ]
23 [ <range-class> ] 2bi make-regexp ;
25 : <or> ( regexps -- disjunction )
26 [ [ raw>> "(" ")" surround ] map "|" join ]
27 [ [ parse-tree>> ] map <alternation> ] bi
28 make-regexp ; foldable
30 : <any-of> ( strings -- regexp )
31 [ <literal> ] map <or> ; foldable
33 : <sequence> ( regexps -- regexp )
34 [ [ raw>> ] map concat ]
35 [ [ parse-tree>> ] map <concatenation> ] bi
36 make-regexp ; foldable
38 : <not> ( regexp -- not-regexp )
39 [ "(?~" ")" surround ]
40 [ <negation> ] modify-regexp ; foldable
42 : <and> ( regexps -- conjunction )
43 [ <not> ] map <or> <not> ; foldable
45 : <zero-or-more> ( regexp -- regexp* )
47 [ <star> ] modify-regexp ; foldable
49 : <one-or-more> ( regexp -- regexp+ )
51 [ <plus> ] modify-regexp ; foldable
53 : <option> ( regexp -- regexp? )
55 [ <maybe> ] modify-regexp ; foldable