]> gitweb.factorcode.org Git - factor.git/blob - basis/peg/search/search.factor
Fix permission bits
[factor.git] / basis / peg / search / search.factor
1 ! Copyright (C) 2006 Chris Double.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: kernel math io io.streams.string sequences strings
4 combinators peg memoize arrays continuations ;
5 IN: peg.search
6
7 : tree-write ( object -- )
8   {
9     { [ dup number?   ] [ write1 ] }
10     { [ dup string?   ] [ write ] }
11     { [ dup sequence? ] [ [ tree-write ] each ] }
12     { [ t             ] [ write ] }
13   } cond ;
14
15 MEMO: any-char-parser ( -- parser )
16   [ drop t ] satisfy ;
17
18 : search ( string parser -- seq )
19   any-char-parser [ drop f ] action 2array choice repeat0 
20   [ parse sift ] [ 3drop { } ] recover ;
21
22
23 : (replace) ( string parser -- seq )
24   any-char-parser 2array choice repeat0 parse sift ;
25
26 : replace ( string parser -- result )
27  [  (replace) [ tree-write ] each ] with-string-writer ;
28
29