MODULEConstructors.; IMPORT Glob, RegEx; TYPE MatchNode = T OBJECT pattern: TEXT; options: Glob.MatchOptions; OVERRIDES test := MatchTest; END; UnaryNode = T OBJECT child: T; END; BinaryNode = T OBJECT left, right: T; END; GlobTree
PROCEDUREEvaluators.Match (pattern: TEXT; options := Glob.MatchOptions{}): T = BEGIN RETURN NEW(MatchNode, pattern := pattern, options := options); END Match; PROCEDUREAnd (left, right: T): T = BEGIN IF left = True THEN RETURN right; ELSIF left = False THEN RETURN False; ELSIF right = True THEN RETURN left; ELSIF right = False THEN RETURN False; ELSE RETURN NEW(BinaryNode, test := AndTest, left := left, right := right); END; END And; PROCEDUREOr (left, right: T): T = BEGIN IF left = True THEN RETURN True; ELSIF left = False THEN RETURN right; ELSIF right = True THEN RETURN True; ELSIF right = False THEN RETURN left; ELSE RETURN NEW(BinaryNode, test := OrTest, left := left, right := right); END; END Or; PROCEDURENot (child: T): T = BEGIN IF child = True THEN RETURN False; ELSIF child = False THEN RETURN True; ELSE RETURN NEW(UnaryNode, test := NotTest, child := child); END; END Not;
PROCEDUREMatchTest (self: MatchNode; filename: TEXT): BOOLEAN RAISES {RegEx.Error} = BEGIN RETURN Glob.Match(self.pattern, filename, self.options); END MatchTest; PROCEDUREAndTest (self: BinaryNode; filename: TEXT): BOOLEAN RAISES {RegEx.Error} = BEGIN RETURN self.left.test(filename) AND self.right.test(filename); END AndTest; PROCEDUREOrTest (self: BinaryNode; filename: TEXT): BOOLEAN RAISES {RegEx.Error} = BEGIN RETURN self.left.test(filename) OR self.right.test(filename); END OrTest; PROCEDURENotTest (self: UnaryNode; filename: TEXT): BOOLEAN RAISES {RegEx.Error} = BEGIN RETURN NOT self.child.test(filename); END NotTest; PROCEDURETrueTest (<*UNUSED*> self: T; <*UNUSED*> filename: TEXT): BOOLEAN = BEGIN RETURN TRUE; END TrueTest; PROCEDUREFalseTest (<*UNUSED*> self: T; <*UNUSED*> filename: TEXT): BOOLEAN = BEGIN RETURN FALSE; END FalseTest; BEGIN True := NEW(T, test := TrueTest); False := NEW(T, test := FalseTest); END GlobTree.