package cmarkit

  1. Overview
  2. Docs

Node metadata.

Holds text locations and custom, client-defined metadata.

type id = int

The type for non-negative metadata identifiers.

type t

The type for abstract syntax tree node metadata.

val none : t

none is metadata for when there is none, its textloc is Textloc.none.

val make : ?textloc:Textloc.t -> unit -> t

make textloc is metadata with text location textloc (defaults to Textloc.none) and a fresh identifier (see id).

val id : t -> id

id m is an identifier for the metadata. Depending on how you process the abstract syntax tree this may become non-unique but the metadata values in an abstract syntax tree returned by Doc.of_string with locs:true have distinct identifiers.

val textloc : t -> Textloc.t

textloc m is the source location of the syntactic construct m is attached to.

val with_textloc : keep_id:bool -> t -> Textloc.t -> t

with_textloc ~keep_id m textloc is metadata m with text location textloc and a fresh id, unless keep_id is true.

Predicates and comparisons

val equal : t -> t -> bool

equal m0 m1 is true if m0 and m1 have the same id. Note that they may have different metadata.

val compare : t -> t -> int

compare m0 m1 is a total order on metadata ids compatible with equal.

val is_none : t -> bool

is_none m is equal none m.

Custom metadata

Warning. Operating on custom metadata never changes id. It is possible for two meta values to have the same id and different metadata.

type 'a key

The type for custom metadata keys.

val key : unit -> 'a key

key () is a new metadata key.

val mem : 'a key -> t -> bool

mem k m is true iff k is bound in m.

val add : 'a key -> 'a -> t -> t

add k v m is m with key k bound to v.

val tag : unit key -> t -> t

tag k m is add k () m.

val remove : 'a key -> t -> t

remove k m is m with key k unbound in v.

val find : 'a key -> t -> 'a option

find k m the value of k in m, if any.


Innovation. Community. Security.