Module Upat.Pattern_matcher

type t

An ordered collection of rules.

type 'ctx with_ctx

An ordered collection of context-sensitive rules.

val make : rule list -> t

make rs is the pattern matcher that tries rs in order. Rules are dispatched by the candidate node's root op before structural matching.

Raises Invalid_argument if a top-level pattern has no root op.

val make_with_ctx : 'ctx rule_with_ctx list -> 'ctx with_ctx

make_with_ctx rs is the context-sensitive variant of make.

Raises Invalid_argument if a top-level pattern has no root op.

val rewrite : t -> Uop.t -> Uop.t option

rewrite pm u tries each rule of pm in order. For each rule whose pattern matches u, the callback is invoked with every binding set produced by match_; the first Some _ return is the result. A callback result physically equal to the candidate node is ignored. None means no rule (with any binding) fired.

val rewrite_with_ctx : 'ctx with_ctx -> ctx:'ctx -> Uop.t -> Uop.t option

rewrite_with_ctx pm ~ctx u is like rewrite except callbacks receive ctx.

val (++) : t -> t -> t

a ++ b concatenates rules: a's rules are tried before b's.

val compose : t list -> t

compose pms concatenates the rule lists of pms in order.