path: root/libregex/doc
diff options
Diffstat (limited to 'libregex/doc')
2 files changed, 203 insertions, 0 deletions
diff --git a/libregex/doc/Makefile b/libregex/doc/Makefile
new file mode 100644
index 0000000..c1749d3
--- /dev/null
+++ b/libregex/doc/Makefile
@@ -0,0 +1,5 @@
+MAN=myr-regex.3 \
+include ../
+include ../mk/
diff --git a/libregex/doc/myr-regex.3 b/libregex/doc/myr-regex.3
new file mode 100644
index 0000000..c0d0da0
--- /dev/null
+++ b/libregex/doc/myr-regex.3
@@ -0,0 +1,198 @@
+regex myr-regex
+.B use regex
+.I const compile : (re : byte[:] -> std.error(regex#, status))
+.I const dbgcompile : (re : byte[:] -> std.error(regex#, status))
+.I const free : (re : regex# -> void)
+.I const exec : (re : regex#, str : byte[:] -> bool)
+.I const search : (re : regex#, str : byte[:] -> bool)
+The regex library provides functions for compiling and evaluating regular
+expressions, as described later in this document, or in myr-regex(7).
+.I regex.compile will take a string describing a regex, and will attempt
+to compile it, returing
+.I `std.Success regex#
+if the regex is valid, and there were no error conditions encountered during
+compilation. If the compilation failed,
+.I `std.Failure regex.status
+will be returned, where regex.status is a failure code.
+.I regex.dbgcompile
+is identical to
+.I regex.compile,
+however, it will print debugging information as it compiles, and each
+time the regex is evaluated.
+.I regex.exec
+will take the regex passed to it, and evaluate it over the text provided,
+returning the
+.I `std.Some matches,
+.I `std.None
+if there were no matches found. The matches must span the whole string.
+is similar to regex.exec, but it will attempt to find a match somewhere
+within the string, instead of attempting to find a match spanning the whole
+The grammar used by libregex is below:
+ regex : altexpr
+ altexpr : catexpr ('|' altexpr)+
+ catexpr : repexpr (catexpr)+
+ repexpr : baseexpr[*+?]
+ baseexpr : literal
+ | charclass
+ | charrange
+ | escaped
+ | '.'
+ | '^'
+ | '$'
+ | '(' regex ')'
+ charclass : see below
+ charrange : '[' (literal('-' literal)?)+']'
+The following metacharacters have the meanings listed below:
+Matches a single unicode character
+Matches the beginning of a line. Does not consume any characters.
+Matches the end of a line. Does not consume any characters.
+Matches any number of repetitions of the preceding regex fragment.
+Reluctantly matches any number of repetitions of the preceding regex fragment.
+Matches one or more repetitions of the preceding regex fragment.
+Reluctantly matches one or more repetitions of the preceding regex fragment.
+Matches zero or one of the preceding regex fragment.
+In order to match a literal metacharacter, it needs to be preceded by
+a '\\' character.
+The following character classes are supported:
+ASCII digits
+Negation of ASCII digits
+ASCII Hex digits
+Negation of ASCII Hex digits
+ASCII spaces
+Negation of ASCII spaces
+ASCII word characters
+Negation of ASCII word characters
+ASCII whitespace characters
+Negation of ASCII whitespace characters
+\\pX, \\p{X}
+Characters with unicode property 'X'
+\\PX, \\P{X}
+Negation of characters with unicode property 'X'
+Unicode properties that are supported are listed below:
+L, Letter
+Unicode letter property
+Lu, Uppercase_Letter
+Uppercase letter unicode property
+Ll, Lowercase_Letter
+Lowercase letter unicode property
+Lt, Titlecase_Letter
+Titlecase letter unicode property
+N, Number
+Number unicode property
+Z, Separator
+Any separator character unicode property
+Zs, Space_Separator
+Space separator unicode property
+ use std
+ use regex
+ const main = {
+ match regex.compile(pat)
+ var i
+ | `std.Success re:
+ match regex.exec(re, text)
+ | `std.Some matches:
+ for i = 0; i < matches.len; i++
+ std.put("Match %i: %s\n", i, match[i])
+ ;;
+ | `std.None: std.put("Text did not match\n")
+ ;;
+ | `std.Failure err:
+ std.put("failed to compile regex")
+ ;;
+ }
+The source code for this compiler is available from
+.B git://
+.IR mc(1)
+This code is insufficiently tested.
+This code does not support all of the regex features that one would expect.