Paste: such a balagan

Author: randy7
Mode: factor
Date: Fri, 13 Feb 2009 13:15:26
Plain Text |
USING: kernel peg peg.search make sequences ;

: (1action) ( str1 str2 -- action-parser ) 
    [ token ] [ [ ] curry [ drop ] prepose ] bi* action ;

: replace-all ( long-str seq-of-pairs -- str ) ! "some string" { { "om" "mop!" } { "s" "B" } } 
    dupd [ [ first ] [ second ] bi (1action) ] with map
    [ [ , ] curry ] map concat    
     choice* 
    replace ;
    
    
!  "something" { { "me" "you" } { "so" "so " } { "thing" " think?" } }  replace-all 

Annotation: oops, fixed (but yet to be tested)

Author: randy7
Mode: factor
Date: Fri, 13 Feb 2009 13:37:25
Plain Text |
: replace-all ( long-str seq-of-pairs -- str ) ! "some string" { { "om" "mop!" } { "s" "B" } } 
    dupd [ [ first ] [ second ] bi (1action) nip ] with map
    [ [ , ] curry ] map concat    
     choice* 
    replace ;

! Truth is I'm not sure pegs are suitable here, since the input changes, and it compiles again.
! probably not suitable for runtime input. (but I don't know enough to say)

New Annotation

Summary:
Author:
Mode:
Body: