package yuujinchou

  1. Overview
  2. Docs

Module Yuujinchou.PatternSource

The Pattern module defines the patterns.

Pattern Type

Sourcetype path = string list

The type of hierarchical names.

We assume names are hierarchical and can be encoded as lists of strings. For example, the name x.y.z is represented as the following OCaml list:

  ["x"; "y"; "z"]
Sourcetype +'hook t

The type of patterns, parametrized by the type of hook labels. See hook.

The pattern type is abstract---you should build a pattern using the following builders and execute it by Action.run.

Sourceval equal : ('hook -> 'hook -> bool) -> 'hook t -> 'hook t -> bool

Checking equality.

Pattern Builders

Basics

Sourceval any : 'hook t

any keeps the content of the current tree. It is an error if the tree is empty (no name to match).

Sourceval only : path -> 'hook t

only path keeps the subtree rooted at path. It is an error if the subtree was empty.

Sourceval in_ : path -> 'hook t -> 'hook t

in_ path pattern runs the pattern pat on the subtree rooted at path. Bindings outside the subtree are kept intact. For example, in_ ["x"]any will keep y (if existing), while only["x"] will drop y.

Negation

Sourceval none : 'hook t

none drops everything. It is an error if the tree was already empty (nothing to drop).

Sourceval except : path -> 'hook t

except p drops the subtree rooted at p. It is an error if there was nothing in the subtree. This is equivalent to in_pnone.

Renaming

Sourceval renaming : path -> path -> 'hook t

renaming path path' relocates the subtree rooted at path to path'. It is an error if the subtree was empty (nothing to move).

Sequencing

Sourceval seq : 'hook t list -> 'hook t

seq [pat0; pat1; pat2; ...; patn] runs the patterns pat0, pat1, pat2, ..., patn in order.

Union

Sourceval union : 'hook t list -> 'hook t

union [pat0; pat1; pat2; ...; patn] calculates the union of the results of individual patterns pat0, pat1, pat2, ..., patn.

Custom Hooks

Sourceval hook : 'hook -> 'hook t

hook h applies the hook labelled h to the entire trie; see Action.run_with_hooks.

Utility Functions

Sourceval pp_path : Format.formatter -> Pattern.path -> unit

Pretty printer for path.