Module Ops.Pattern_matcher
Pattern matchers.
An ordered list of rules, each a pattern and a function of the nodes it names. Matching a node tries the rules in order and is the first result. A matcher is typed by the context its rules read, 'ctx, and by its results, 'r. A rewriter's results are nodes; a fold's are anything else, such as verdicts or text.
type ('ctx, 'r) ruleThe type for rules.
rule p f is f m for a node p matches, where m name is the node p names name. m raises Invalid_argument on a name the match did not bind.
rule_ctx p f is rule, with the context passed to f.
type ('ctx, 'r) tThe type for pattern matchers.
v rules is the rewriter of the rules rules () returns, which it calls on its first rewrite. Domains that rewrite first at once may each call rules (); all of them use the one result the matcher keeps. A rule declines by returning None or the node it matched; the next rule is then tried.
The first rewrite raises Invalid_argument if a rule's pattern has no operation.
fold rules is the matcher of the rules rules () returns, which it calls on its first rewrite as v does, and whose results are not the nodes they match. A rule declines by returning None.
The first rewrite raises Invalid_argument if a rule's pattern has no operation.
append m0 m1 tries m0's rules, then m1's, each declining as its matcher says.
with_ctx m is m, ignoring the context, for appending to matchers that read one.
rewrite m ctx u is the result of the first rule of m that matches u and does not decline, trying the namings of each pattern in Upat.match_'s order.