]> gitweb.factorcode.org Git - factor.git/commitdiff
More docs for regexps
authorDaniel Ehrenberg <littledan@Macintosh-122.local>
Mon, 9 Mar 2009 01:25:33 +0000 (20:25 -0500)
committerDaniel Ehrenberg <littledan@Macintosh-122.local>
Mon, 9 Mar 2009 01:25:33 +0000 (20:25 -0500)
basis/regexp/matchers/matchers.factor
basis/regexp/regexp-docs.factor

index d06ac4fef1c42b15bd7f0a63ca620e2403e1ac5c..87df845958d9cacb480bd635d44be9e020423d90 100644 (file)
@@ -20,9 +20,9 @@ GENERIC: match-index-from ( i string matcher -- index/f )
     dupd match-index-head
     [ swap length = ] [ drop f ] if* ;
 
-:: match-from ( i string matcher -- slice/f )
-    i string length [a,b)
-    [ string matcher match-slice ] map-find drop ;
+: match-from ( i string matcher -- slice/f )
+    [ [ length [a,b) ] keep ] dip
+    '[ _ _ match-slice ] map-find drop ;
 
 : match-head ( str matcher -- slice/f )
     [ 0 ] 2dip match-from ;
index 9d3d86fa13e797f8da0860707a306a31e33a6f3c..d77abe877e3cf2daa4daca8f7638189d5cc7b6ca 100644 (file)
@@ -1,6 +1,6 @@
 ! Copyright (C) 2008, 2009 Doug Coleman, Daniel Ehrenberg.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: kernel strings help.markup help.syntax regexp.matchers ;
+USING: kernel strings help.markup help.syntax regexp.matchers math ;
 IN: regexp
 
 ABOUT: "regexp"
@@ -39,12 +39,11 @@ ARTICLE: { "regexp" "theory" } "The theory of regular expressions"
 "The Factor regular expression engine was built with the design decision to support negation and intersection at the expense of backreferences. This lets us have a guaranteed linear-time matching algorithm. Systems like Ragel and Lex also use this algorithm, but in the Factor regular expression engine, all other features of regexps are still present." ;
 
 ARTICLE: { "regexp" "operations" } "Matching operations with regular expressions"
+{ $subsection all-matches }
 { $subsection matches? }
-{ $subsection match-slice }
 { $subsection re-split1 }
 { $subsection re-split }
 { $subsection re-replace }
-{ $subsection all-matches }
 { $subsection count-matches }
 { $subsection re-replace } ;
 
@@ -62,3 +61,27 @@ HELP: R/
 
 HELP: regexp
 { $class-description "The class of regular expressions. To construct these, see " { $link { "regexp" "construction" } } "." } ;
+
+HELP: matches?
+{ $values { "string" string } { "matcher" regexp } { "?" "a boolean" } }
+{ $description "Tests if the string as a whole matches the given regular expression." } ;
+
+HELP: re-split1
+{ $values { "string" string } { "matcher" regexp } { "before" string } { "after/f" string } }
+{ $description "Searches the string for a substring which matches the pattern. If found, the input string is split on the leftmost and longest occurence of the match, and the two halves are given as output. If no match is found, then the input string and " { $link f } " are output." } ;
+
+HELP: all-matches
+{ $values { "string" string } { "matcher" regexp } { "seq" "a sequence of slices of the input" } }
+{ $description "Finds a sequence of disjoint substrings which each match the pattern. It chooses this by finding the leftmost longest match, and then the leftmost longest match which starts after the end of the previous match, and so on." } ;
+
+HELP: count-matches
+{ $values { "string" string } { "matcher" regexp } { "n" integer } }
+{ $description "Counts how many disjoint matches the regexp has in the string, as made unambiguous by " { $link all-matches } "." } ;
+
+HELP: re-split
+{ $values { "string" string } { "matcher" regexp } { "seq" "a sequence of slices of the input" } }
+{ $description "Splits the input string into chunks separated by the regular expression. Each chunk contains no match of the regexp. The chunks are chosen by the strategy of " { $link all-matches } "." } ;
+
+HELP: re-replace
+{ $values { "string" string } { "matcher" regexp } { "replacement" string } { "result" string } }
+{ $description "Replaces substrings which match the input regexp with the given replacement text. The boundaries of the substring are chosen by the strategy used by " { $link all-matches } "." } ;