diff --git a/extra/parser-combinators/replace/replace-docs.factor b/extra/parser-combinators/replace/replace-docs.factor deleted file mode 100644 index fe73f5d3c2..0000000000 --- a/extra/parser-combinators/replace/replace-docs.factor +++ /dev/null @@ -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' [ \"\" swap \"\" 3append ] <@ replace ." "\"hello world from factor\"" } -{ $example "USE: parser-combinators" "\"hello *world* from _factor_\"\n 'bold' [ \"\" swap \"\" 3append ] <@\n 'italic' [ \"\" swap \"\" 3append ] <@ <|>\n replace ." "\"hello world from factor\"" } -{ $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' [ \"\" swap \"\" 3append ] <@\n 'italic' [ \"\" swap \"\" 3append ] <@ 2array\n replace* ." "\"hello world\"" } -{ $see-also search search* replace* } ; - diff --git a/extra/parser-combinators/replace/replace.factor b/extra/parser-combinators/replace/replace.factor deleted file mode 100755 index d783fde061..0000000000 --- a/extra/parser-combinators/replace/replace.factor +++ /dev/null @@ -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 ; -