On Feb 14, 2008 12:56 AM, Chris Double <[EMAIL PROTECTED]> wrote:
>
> peg.search (or is it peg.replace) has a 'replace' word that lets you
> search and replace in strings. The thing to search for needs to be a
> combinator but you could use 'token' for a string. See the help for
> the vocab.

Here's an example of the replace word:

USING: peg peg.search ;

: bold ( -- parser )
  [
    "*" token ,
    [ CHAR: * = not ] satisfy repeat1 ,
    "*" token ,
  ] seq* [ second >string ] action ;

"Hello *World*" bold [
  "<strong>" swap "</strong>" 3append
] action replace .
 => "Hello <strong>World</strong>"

For more, there's now a search and replace chapter in my
work-in-progress factor articles PDF which works with latest git:

http://www.bluishcoder.co.nz/factor-articles.pdf

Chris.
-- 
http://www.bluishcoder.co.nz

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Factor-talk mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/factor-talk

Reply via email to