module type GLOB = sig .. end
A self-contained module implementing extended shell glob patterns who have an expressive power
equal to boolean combinations of regular expressions.
A globber is a boolean combination of basic expressions indented to work on
pathnames. Known operators
are or, and and not, which may also be written |, & and ~. There are
also constants true and false (or 1 and 0). Expression can be grouped
using parentheses.
true matches anything,
false matches nothing,
- basic
or basic matches strings matching either one of the basic expressions,
- basic
and basic matches strings matching both basic expressions,
- not basic matches string that don't match the basic expression,
- basic matches strings that match the basic expression.
A basic expression can be a constant string enclosed in double quotes, in which
double quotes must be preceded by backslashes, or a glob pattern enclosed between a < and a >,
"string" matches the literal string string,
<glob> matches the glob pattern glob.
A glob pattern is an anchored regular expression in a shell-like syntax. Most characters stand for themselves.
Character ranges are given in usual shell syntax between brackets. The star * stands for any sequence of
characters. The joker '?' stands for exactly one, unspecified character. Alternation is achieved using braces {.
- glob1glob2 matches strings who have a prefix matching glob1 and the corresponding suffix
matching glob2.
a matches the string consisting of the single letter a.
{glob1,glob2} matches strings matching glob1 or glob2.
? any one-letter string, excluding the slash.
* matches all strings not containing a slash, including the empty one.
**/ the empty string, or any string ending with a slash.
/** any string starting with a slash, or the empty string.
/**/ any string starting and ending with a slash.
[c1-c2c3-c4...] matches characters in the range c1 to c2 inclusive,
or in the range c3 to c4 inclusive. For instance [a-fA-F0-9] matches hexadecimal digits.
To match the dash, put it at the end.
type globber
The type representing globbers. Do not attempt to compare them, as they get on-the-fly optimizations.
val parse : ?dir:string -> string -> globber
parse ~dir pattern will parse the globber pattern pattern, optionally prefixing its patterns with dir.
exception Parse_error of string
A descriptive exception raised when an invalid glob pattern description is given.
val eval : globber -> string -> bool
eval g u returns true if and only if the string u matches the given glob expression. Avoid reparsing
the same pattern, since the automaton implementing the pattern is optimized on the fly. The first few evaluations
are done using a time-inefficient but memory-efficient algorithm. It then compiles the pattern into an efficient
but more memory-hungry data structure.