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 ;
7 : tree-write ( object -- )
9 { [ dup number? ] [ write1 ] }
10 { [ dup string? ] [ write ] }
11 { [ dup sequence? ] [ [ tree-write ] each ] }
15 MEMO: any-char-parser ( -- parser )
18 : search ( string parser -- seq )
19 any-char-parser [ drop f ] action 2array choice repeat0
20 [ parse sift ] [ 3drop { } ] recover ;
23 : (replace) ( string parser -- seq )
24 any-char-parser 2array choice repeat0 parse sift ;
26 : replace ( string parser -- result )
27 [ (replace) [ tree-write ] each ] with-string-writer ;