1 ! Copyright (C) 2006 Chris Double.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: combinators continuations io io.streams.string kernel
4 literals math namespaces peg sequences strings ;
7 : stream-tree-write ( object stream -- )
9 { [ over number? ] [ stream-write1 ] }
10 { [ over string? ] [ stream-write ] }
11 { [ over sequence? ] [ [ stream-tree-write ] curry each ] }
15 : tree-write ( object -- )
16 output-stream get stream-tree-write ;
20 CONSTANT: any-char-parser $[ [ drop t ] satisfy ]
24 : search ( string parser -- seq )
25 any-char-parser [ drop f ] action 2choice repeat0
26 [ parse sift ] [ 3drop { } ] recover ;
28 : replace ( string parser -- result )
30 any-char-parser 2choice repeat0
32 ] with-string-writer ;