The GlobTree
interface allows one to construct arbitrarily complex
boolean expressions for evaluating whether to accept or reject a
filename.
INTERFACEAGlobTree ; IMPORT Glob, RegEx; CONST Brand = "GlobTree 1.0"; TYPE T = OBJECT METHODS test(filename: TEXT): BOOLEAN; END; VAR False, True: T; (* CONST *)
GlobTree.T
represents a boolean expression for filtering
filenames. Its test
method may be called with a filename to be
tested. It returns TRUE
or FALSE
according to whether the name
is accepted or rejected by the expression.
Expressions are trees constructed from nodes representing either
primitive matching operations (primaries) or operators that are
applied to their subexpressions. The simplest primitives are
False
, which matches nothing, and True
, which matches everything.
A more useful primitive is the matching operation. It is
constructed with a glob-style pattern. Its test
method returns
an indication of whether the given filename matches the pattern.
Expressions can be combined with the boolean operators AND, OR, and NOT, to form more complex expressions.
PROCEDURE Match(pattern: TEXT; options := Glob.MatchOptions{}): T;
Return amatch
primitive for the given pattern. Matching is performed byGlob.Match
, using the specified options.
PROCEDURE RegExMatch(pattern: TEXT): T RAISES {RegEx.Error};
Like Match
but the pattern is a regular expression.
PROCEDURE And(left, right: T): T;
Return an AND expression.
PROCEDURE Or(left, right: T): T;
Return an OR expression.
PROCEDURE Not(child: T): T;
Return an expression that evaluates the logical negation of its subexpression.
END GlobTree.