1 ! Copyright (C) 2009 Daniel Ehrenberg
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: help.syntax help.markup regexp strings ;
6 ABOUT: "regexp.combinators"
8 ARTICLE: "regexp.combinators.intro" "Regular expression combinator rationale"
9 "Regular expression combinators are useful when part of the regular expression contains user input. For example, given a sequence of strings on the stack, a regular expression which matches any one of them can be constructed:"
11 "[ <literal> ] map <or>"
13 "Without combinators, a naive approach would look as follows:"
17 "However, this code is incorrect, because one of the strings in the sequence might contain characters which have special meaning inside a regular expression. Combinators avoid this problem by building a regular expression syntax tree directly, without any parsing." ;
19 ARTICLE: "regexp.combinators" "Regular expression combinators"
20 "The " { $vocab-link "regexp.combinators" } " vocabulary defines combinators which can be used to build up regular expressions to match strings. This complements the traditional syntax defined in the " { $vocab-link "regexp" } " vocabulary."
21 { $subsections "regexp.combinators.intro" }
23 { $subsections <literal> <nothing> }
24 "Higher-order combinators for building new regular expressions from existing ones:"
32 "Derived combinators implemented in terms of the above:"
33 { $subsections <one-or-more> }
35 { $subsections <option> } ;
38 { $values { "string" string } { "regexp" regexp } }
39 { $description "Creates a regular expression which matches the given literal string." } ;
42 { $values { "value" regexp } }
43 { $description "The empty regular language." } ;
46 { $values { "regexps" "a sequence of regular expressions" } { "disjunction" regexp } }
47 { $description "Creates a new regular expression which matches the union of what elements of the sequence match." } ;
50 { $values { "regexps" "a sequence of regular expressions" } { "conjunction" regexp } }
51 { $description "Creates a new regular expression which matches the intersection of what elements of the sequence match." } ;
54 { $values { "regexps" "a sequence of regular expressions" } { "regexp" regexp } }
55 { $description "Creates a new regular expression which matches strings that match each element of the sequence in order." } ;
58 { $values { "regexp" regexp } { "not-regexp" regexp } }
59 { $description "Creates a new regular expression which matches everything that the given regexp does not match." } ;
62 { $values { "regexp" regexp } { "regexp+" regexp } }
63 { $description "Creates a new regular expression which matches one or more copies of the given regexp." } ;
66 { $values { "regexp" regexp } { "regexp?" regexp } }
67 { $description "Creates a new regular expression which matches zero or one copies of the given regexp." } ;
70 { $values { "regexp" regexp } { "regexp*" regexp } }
71 { $description "Creates a new regular expression which matches zero or more copies of the given regexp." } ;