peg: Qualify use of replace. Fix some spacing.

db4
Doug Coleman 2013-01-03 18:33:20 -08:00
parent d8e8eee935
commit 10a2288ed4
1 changed files with 11 additions and 12 deletions

View File

@ -5,25 +5,24 @@ combinators peg memoize arrays continuations ;
IN: peg.search
: tree-write ( object -- )
{
{ [ dup number? ] [ write1 ] }
{ [ dup string? ] [ write ] }
{ [ dup sequence? ] [ [ tree-write ] each ] }
{ [ t ] [ write ] }
} cond ;
{
{ [ dup number? ] [ write1 ] }
{ [ dup string? ] [ write ] }
{ [ dup sequence? ] [ [ tree-write ] each ] }
{ [ t ] [ write ] }
} cond ;
MEMO: any-char-parser ( -- parser )
[ drop t ] satisfy ;
[ drop t ] satisfy ;
: search ( string parser -- seq )
any-char-parser [ drop f ] action 2choice repeat0
[ parse sift ] [ 3drop { } ] recover ;
any-char-parser [ drop f ] action 2choice repeat0
[ parse sift ] [ 3drop { } ] recover ;
: (replace) ( string parser -- seq )
any-char-parser 2choice repeat0 parse sift ;
any-char-parser 2choice repeat0 parse sift ;
: replace ( string parser -- result )
[ (replace) [ tree-write ] each ] with-string-writer ;
[ (replace) [ tree-write ] each ] with-string-writer ;