myPatterns tutorial
overview
myPatterns is a flexible
library for pattern matching in Java and JavaScript programs.
Pattern matching is a well-known programming mechanism for recognizing
data having a particular shape (or "matching" a particular "pattern"),
and at the same time binding some variables occurring in the pattern
to some sub-structures of those instances.
The standard matching implementations included in Java is limited to
pattern matching of strings using regular expressions. Regexps are a
very powerful matching notation, implemented in Java by the standard
library java.util.regex.
MyPatterns implements nevertheless a much more general form of pattern
matching:
- by allowing to match data structures of any kind besides strings
(numbers and objects of any kind), using predefined notations
(regexps for matching strings and JSON for matching objects)
- by offering, beyond the fixed set of predefined notations, the
liberty to override them with custom notations for any data types
Indeed, text matching is extremely useful when isolating substrings of
"flat" strings, but cannot cope with data containing structures nested
to an arbitrary level. Such "recursively" structured data are much
better handled by the kind of matching that myPatterns implements.
chapters
Next: Predefined notation