diff --git a/basis/regexp/prettyprint/prettyprint.factor b/basis/regexp/prettyprint/prettyprint.factor index ae3877c7d7..db51be3322 100644 --- a/basis/regexp/prettyprint/prettyprint.factor +++ b/basis/regexp/prettyprint/prettyprint.factor @@ -1,13 +1,17 @@ ! Copyright (C) 2008, 2009 Doug Coleman, Daniel Ehrenberg. ! See http://factorcode.org/license.txt for BSD license. -USING: accessors kernel make prettyprint.backend -prettyprint.custom regexp regexp.parser splitting ; +USING: accessors escape-strings kernel make prettyprint.backend +prettyprint.custom regexp regexp.parser sequences splitting ; IN: regexp.prettyprint M: regexp pprint* [ [ - [ raw>> "/" "\\/" replace "R/ " % % "/" % ] - [ options>> options>string % ] bi + dup options>> options>string [ + raw>> "/" "\\/" replace "re" % escape-simplest % + ] [ + [ raw>> "/" "\\/" replace "re:: " % escape-simplest % ] + [ " " % escape-simplest % ] bi* + ] if-empty ] "" make ] keep present-text ; diff --git a/basis/regexp/regexp-docs.factor b/basis/regexp/regexp-docs.factor index e0dcc0cd49..737f856bb3 100644 --- a/basis/regexp/regexp-docs.factor +++ b/basis/regexp/regexp-docs.factor @@ -27,20 +27,20 @@ ARTICLE: "regexp" "Regular expressions" ARTICLE: "regexp-intro" "A quick introduction to regular expressions" "Regular expressions are a terse way to do certain simple string processing tasks. For example, to replace all instances of " { $snippet "foo" } " in one string with " { $snippet "bar" } ", the following can be used:" -{ $code "R/ foo/ \"bar\" re-replace" } +{ $code "re[[foo]] \"bar\" re-replace" } "That could be done with sequence operations, but consider doing this replacement for an arbitrary number of o's, at least two:" -{ $code "R/ foo+/ \"bar\" re-replace" } +{ $code "re[[foo+]] \"bar\" re-replace" } "The " { $snippet "+" } " operator matches one or more occurrences of the previous expression; in this case " { $snippet "o" } ". Another useful feature is alternation. Say we want to do this replacement with fooooo or boooo. Then we could use the code" -{ $code "R/ (f|b)oo+/ \"bar\" re-replace" } +{ $code "re[[(f|b)oo+]] \"bar\" re-replace" } "To search a file for all lines that match a given regular expression, you could use code like this:" -{ $code "\"file.txt\" ascii file-lines [ R/ (f|b)oo+/ re-contains? ] filter" } +{ $code "\"file.txt\" ascii file-lines [ re[[(f|b)oo+]] re-contains? ] filter" } "To test if a string in its entirety matches a regular expression, the following can be used:" -{ $example "USE: regexp \"fooo\" R/ (b|f)oo+/ matches? ." "t" } +{ $example "USE: regexp \"fooo\" re[[(b|f)oo+]] matches? ." "t" } "Regular expressions can't be used for all parsing tasks. For example, they are not powerful enough to match balancing parentheses." ; ARTICLE: "regexp-construction" "Constructing regular expressions" "Most of the time, regular expressions are literals and the parsing word should be used, to construct them at parse time. This ensures that they are only compiled once, and gives parse time syntax checking." -{ $subsections postpone: R/ } +{ $subsections postpone: \re[[ } "Sometimes, regular expressions need to be constructed at run time instead; for example, in a text editor, the user might input a regular expression to search for in a document." { $subsections } "Another approach is to use " { $vocab-link "regexp.combinators" } "." ; @@ -48,9 +48,9 @@ ARTICLE: "regexp-construction" "Constructing regular expressions" ARTICLE: "regexp-syntax" "Regular expression syntax" "Regexp syntax is largely compatible with Perl, Java and extended POSIX regexps, but not completely. Below, the syntax is documented." { $heading "Characters" } -"At its core, regular expressions consist of character literals. For example, " { $snippet "R/ f/" } " is a regular expression matching just the string 'f'. In addition, the normal escape codes are provided, like " { $snippet "\\t" } " for the tab character and " { $snippet "\\uxxxxxx" } " for an arbitrary Unicode code point, by its hex value. In addition, any character can be preceded by a backslash to escape it, unless this has special meaning. For example, to match a literal opening parenthesis, use " { $snippet "\\(" } "." +"At its core, regular expressions consist of character literals. For example, " { $snippet "re[[f]]" } " is a regular expression matching just the string 'f'. In addition, the normal escape codes are provided, like " { $snippet "\\t" } " for the tab character and " { $snippet "\\uxxxxxx" } " for an arbitrary Unicode code point, by its hex value. In addition, any character can be preceded by a backslash to escape it, unless this has special meaning. For example, to match a literal opening parenthesis, use " { $snippet "\\(" } "." { $heading "Concatenation, alternation and grouping" } -"Regular expressions can be built out of multiple characters by concatenation. For example, " { $snippet "R/ ab/" } " matches a followed by b. The " { $snippet "|" } " (alternation) operator can construct a regexp which matches one of two alternatives. Parentheses can be used for grouping. So " { $snippet "R/ f(oo|ar)/" } " would match either 'foo' or 'far'." +"Regular expressions can be built out of multiple characters by concatenation. For example, " { $snippet "re[[ab]]" } " matches a followed by b. The " { $snippet "|" } " (alternation) operator can construct a regexp which matches one of two alternatives. Parentheses can be used for grouping. So " { $snippet "re[[f(oo|ar)]]" } " would match either 'foo' or 'far'." { $heading "Character classes" } "Square brackets define a convenient way to refer to a set of characters. For example, " { $snippet "[ab]" } " refers to either a or b. And " { $snippet "[a-z]" } " refers to all of the characters between a and z, in code point order. You can use these together, as in " { $snippet "[ac-fz]" } " which matches all of the characters between c and f, in addition to a and z. Character classes can be negated using a caret, as in " { $snippet "[^a]" } " which matches all characters which are not a." { $heading "Predefined character classes" } @@ -110,7 +110,7 @@ ARTICLE: "regexp-syntax" "Regular expression syntax" { { $snippet "(?<=a)" } "Asserts that the current position is immediately preceded by a" } { { $snippet "(? { $values { "string" string } { "options" "a string of " { $link "regexp-options" } } { "regexp" regexp } } { $description "Given a string in regular expression syntax, and a string of options, creates a regular expression object. When it is first used for matching, a DFA is compiled, and this DFA is stored for reuse so it is only compiled once." } ; -HELP: R/ -{ $syntax "R/ foo.*|[a-zA-Z]bar/options" } +HELP: \re[[ +{ $syntax "re[[foo.*|[a-zA-Z]bar]]" } +{ $syntax "re:: [[foo.*|[a-zA-Z]bar]] [[options]]" } { $description "Literal syntax for a regular expression. When this syntax is used, the DFA is compiled at compile-time, rather than on first use. The syntax for the " { $snippet "options" } " string is documented in " { $link "regexp-options" } "." } ; HELP: regexp @@ -231,7 +232,7 @@ HELP: re-replace { $examples { $example "USING: prettyprint regexp ;" - "\"python is pythonic\" R/ python/ \"factor\" re-replace ." + "\"python is pythonic\" re[[python]] \"factor\" re-replace ." "\"factor is factoric\"" } } ; @@ -241,7 +242,7 @@ HELP: re-replace-with { $examples { $example "USING: ascii prettyprint regexp ;" - "\"abcdefghi\" R/ [aeiou]/ [ >upper ] re-replace-with ." + "\"abcdefghi\" re\"[aeiou]\" [ >upper ] re-replace-with ." "\"AbcdEfghI\"" } } ; diff --git a/basis/regexp/regexp.factor b/basis/regexp/regexp.factor index 7753d00f3b..ea0b780af5 100644 --- a/basis/regexp/regexp.factor +++ b/basis/regexp/regexp.factor @@ -223,7 +223,7 @@ PRIVATE> parse-noblank-token compile-next-match suffix! ; -SYNTAX: R/ parse-regexp ; +! SYNTAX: R/ parse-regexp ; SYNTAX: \R[[ "]]" parse-optioned-regexp ; SYNTAX: \R[=[ "]=]" parse-optioned-regexp ; SYNTAX: \R[==[ "]==]" parse-optioned-regexp ; @@ -236,8 +236,8 @@ SYNTAX: \re[==[ "]==]" parse-optioned-regexp ; SYNTAX: \re[===[ "]===]" parse-optioned-regexp ; SYNTAX: \re[====[ "]====]" parse-optioned-regexp ; -SYNTAX: \re: scan-object "" suffix! ; -SYNTAX: \re:: scan-object scan-object suffix! ; +SYNTAX: \re: scan-object "" compile-next-match suffix! ; +SYNTAX: \re:: scan-object scan-object compile-next-match suffix! ; SYNTAX: \R(( "))" parse-optioned-regexp ; SYNTAX: \R(=( ")=)" parse-optioned-regexp ; diff --git a/basis/sorting/functor/functor.factor b/basis/sorting/functor/functor.factor index df6d3b7a0b..790f9671cc 100644 --- a/basis/sorting/functor/functor.factor +++ b/basis/sorting/functor/functor.factor @@ -3,7 +3,7 @@ USING: functors2 quotations strings ; IN: sorting.functor -INLINE-FUNCTOR: sorting ( name: name quot: string -- ) [[ +INLINE-FUNCTOR: sorting ( name: name quot: string -- ) [=[ : ${name}<=> ( obj1 obj2 -- <=> ) ${quot} compare ; : ${name}>=< ( obj1 obj2 -- >=< ) ${name}<=> invert-comparison ; -]] +]=] diff --git a/basis/sorting/title/title.factor b/basis/sorting/title/title.factor index 97c84f01f9..6f0a3885e6 100644 --- a/basis/sorting/title/title.factor +++ b/basis/sorting/title/title.factor @@ -5,6 +5,6 @@ sorting.functor unicode ; IN: sorting.title SORTING: title "[ - >lower dup R/ ^(the|a|an|el|la|los|las|il) / first-match + >lower dup re[[^(the|a|an|el|la|los|las|il) ]] first-match [ to>> tail-slice ] when* ]" diff --git a/extra/talks/galois-talk/galois-talk.factor b/extra/talks/galois-talk/galois-talk.factor index 6549ce98e0..7bf3800a98 100644 --- a/extra/talks/galois-talk/galois-talk.factor +++ b/extra/talks/galois-talk/galois-talk.factor @@ -134,7 +134,7 @@ CONSTANT: galois-slides "Implemented with library code" { $code "USE: regexp" } { $code "\"ababbc\" \"[ab]+c\" matches? ." } - { $code "\"ababbc\" R/ [ab]+c/ matches? ." } + { $code "\"ababbc\" re\"[ab]+c\" matches? ." } } { $slide "Example: memoization" { "Memoization with " { $link postpone: \MEMO: } }