Remove parser-combinators.replace

db4
Chris Double 2007-12-20 17:12:48 +13:00
parent b655d4c759
commit 0bf1355657
2 changed files with 0 additions and 113 deletions

View File

@ -1,76 +0,0 @@
! Copyright (C) 2006 Chris Double.
! See http://factorcode.org/license.txt for BSD license.
USING: help.syntax help.markup parser-combinators
parser-combinators.replace ;
HELP: tree-write
{ $values
{ "object" "an object" } }
{ $description
"Write the object to the standard output stream, unless "
"it is an array, in which case recurse through the array "
"writing each object to the stream." }
{ $example "USE: parser-combinators" "{ 65 \"bc\" { 68 \"ef\" } } tree-write" "AbcDef" } ;
HELP: search
{ $values
{ "string" "a string" }
{ "parser" "a parser combinator based parser" }
{ "seq" "a sequence" }
}
{ $description
"Returns a sequence containing the parse results of all substrings "
"from the input string that successfully parse using the "
"parser."
}
{ $example "USE: parser-combinators" "\"one 123 two 456\" 'integer' search ." "{ 123 456 }" }
{ $example "USE: parser-combinators" "\"one 123 \\\"hello\\\" two 456\" 'integer' 'string' <|> search ." "{ 123 \"hello\" 456 }" }
{ $see-also search* replace replace* } ;
HELP: search*
{ $values
{ "string" "a string" }
{ "parsers" "a sequence of parser combinator based parsers" }
{ "seq" "a sequence" }
}
{ $description
"Returns a sequence containing the parse results of all substrings "
"from the input string that successfully parse using any of the "
"parsers in the 'parsers' sequence."
}
{ $example "USE: parser-combinators" "\"one 123 \\\"hello\\\" two 456\" 'integer' 'string' 2array search* ." "{ 123 \"hello\" 456 }" }
{ $see-also search replace replace* } ;
HELP: replace
{ $values
{ "string" "a string" }
{ "parser" "a parser combinator based parser" }
{ "result" "a string" }
}
{ $description
"Returns a copy of the original string but with all substrings that "
"successfully parse with the given parser replaced with "
"the result of that parser."
}
{ $example "USING: parser-combinators math.parser ;" "\"one 123 two 456\" 'integer' [ 2 * number>string ] <@ replace ." "\"one 246 two 912\"" }
{ $example "USE: parser-combinators" "\"hello *world* from *factor*\" 'bold' [ \"<strong>\" swap \"</strong>\" 3append ] <@ replace ." "\"hello <strong>world</strong> from <strong>factor</strong>\"" }
{ $example "USE: parser-combinators" "\"hello *world* from _factor_\"\n 'bold' [ \"<strong>\" swap \"</strong>\" 3append ] <@\n 'italic' [ \"<emphasis>\" swap \"</emphasis>\" 3append ] <@ <|>\n replace ." "\"hello <strong>world</strong> from <emphasis>factor</emphasis>\"" }
{ $see-also search search* replace* } ;
HELP: replace*
{ $values
{ "string" "a string" }
{ "parsers" "a sequence of parser combinator based parsers" }
{ "result" "a string" }
}
{ $description
"Returns a copy of the original string but with all substrings that "
"successfully parse with the given parsers replaced with "
"the result of that parser. Each parser is done in sequence so that "
"the parse results of the first parser can be replaced by later parsers."
}
{ $example "USE: parser-combinators" "\"*hello _world_*\"\n 'bold' [ \"<strong>\" swap \"</strong>\" 3append ] <@\n 'italic' [ \"<emphasis>\" swap \"</emphasis>\" 3append ] <@ 2array\n replace* ." "\"<strong>hello <emphasis>world</emphasis></strong>\"" }
{ $see-also search search* replace* } ;

View File

@ -1,37 +0,0 @@
! Copyright (C) 2006 Chris Double.
! See http://factorcode.org/license.txt for BSD license.
USING: kernel math io io.streams.string sequences strings
lazy-lists combinators parser-combinators parser-combinators.simple ;
IN: parser-combinators.replace
: tree-write ( object -- )
{
{ [ dup number? ] [ write1 ] }
{ [ dup string? ] [ write ] }
{ [ dup sequence? ] [ [ tree-write ] each ] }
{ [ t ] [ write ] }
} cond ;
: search ( string parser -- seq )
any-char-parser [ drop f ] <@ <|> <*> parse dup nil? [
drop { }
] [
car parse-result-parsed [ ] subset
] if ;
: search* ( string parsers -- seq )
unclip [ <|> ] reduce any-char-parser [ drop f ] <@ <|> <*> parse dup nil? [
drop { }
] [
car parse-result-parsed [ ] subset
] if ;
: (replace) ( string parser -- seq )
any-char-parser <|> <*> parse-1 ;
: replace ( string parser -- result )
[ (replace) [ tree-write ] each ] string-out ;
: replace* ( string parsers -- result )
swap [ replace ] reduce ;