package yuujinchou

  1. Overview
  2. Docs
Module type
Class type

The Action module implements the engine running the patterns.

The engine tries to preserve physical equality whenever feasible. For example, if the trie t has a binding at x, the pattern Pattern.renaming["x"] ["x"] on t will return the original t.


type nonrec ('a, 'error) result = ('a Trie.t, [> `BindingNotFound of Pattern.path ] as 'error) Stdlib.result

The type of the result. The error `BindingNotFound means that the engine expected at least one binding under path but could not find it.

val run : ?rev_prefix:Pattern.path -> union:(rev_path:Pattern.path -> 'a -> 'a -> 'a) -> unit Pattern.t -> 'a Trie.t -> ('a, 'error) result

run ~rev_prefix ~union pattern trie runs the pattern on the trie and return the transformed trie. It ignores patterns created by Pattern.hook.

  • parameter rev_prefix

    The prefix prepended to any path sent to union and any path in the error reporting, but in reverse. The default is the empty unit path ([]).

  • parameter union

    The resolver for two conflicting bindings sharing the same name. Patterns such as Pattern.renaming and Pattern.union could lead to conflicting bindings, and union ~rev_path x y should return the resolution of x and y at the (reversed) path rev_path.

  • returns

    The new trie after the transformation. Error (`BindingNotFound p) means the transformation failed because of the absence of expected bindings. For example, the pattern Pattern.except["x"; "y"] expects that there was already something under the subtree at x.y. If there were actually no names with the prefix x.y, then the pattern will trigger the error `BindingNotFound ["x"; "y"]. The path p is only an approximation---the user might have intended to hide the binding at ["x"; "y"; "z"], a binding under ["x"; "y"], but the engine would never know the user's true intention.

val run_with_hooks : ?rev_prefix:Pattern.path -> union:(rev_path:Pattern.path -> 'a -> 'a -> 'a) -> hooks:('hook -> rev_prefix:Pattern.path -> 'a Trie.t -> ('a, 'error) result) -> 'hook Pattern.t -> 'a Trie.t -> ('a, 'error) result

run_with_hooks ~rev_prefix ~hooks ~union pattern trie runs the pattern on the trie and return the transformed trie. It is similar to run but accepts a new argument hooks to handle the patterns created by Pattern.hook.

  • parameter hooks

    The hooks that will be triggered by patterns created by Pattern.hook. When the engine encounters the pattern Pattern.hookh, it will call hooks h ~rev_path:p t on the current trie where p is the path (in reverse) and t is the subtrie at p.

Pretty Printers

val pp_path : Stdlib.Format.formatter -> Pattern.path -> unit

Pretty printer for path.


Innovation. Community. Security.