package loc

  1. Overview
  2. Docs

When the symbol you want to decorate is not already an argument in a record, it may be convenient to use this type as a standard way to decorate a symbol with a position.

Using Loc.t or 'a Loc.Txt.t are two different styles to decorate a symbol, you may choose one depending on the context.

An example using Loc.t:

type t =
  | T of { loc : Loc.t ; a : A.t; b : B.t; ... }

An example using 'a Loc.Txt.t:

type t = A.t Loc.Txt.t list
type loc := t
type 'a t = {
  1. txt : 'a;
  2. loc : loc;
}
val equal : ('a -> 'a -> bool) -> 'a t -> 'a t -> bool

It is possible to ignore the locations by setting Loc.equal_ignores_locs to true.

val sexp_of_t : ('a -> Sexplib0.Sexp.t) -> 'a t -> Sexplib0.Sexp.t

By default locations are not shown. To include the locations set Loc.include_sexp_of_locs to true.

val create : (Lexing.position * Lexing.position) -> 'a -> 'a t

To be called in the right hand side of a Menhir rule, using the $loc special keyword provided by Menhir. For example:

ident:
 | ident=IDENT { Loc.Txt.create $loc ident }
;
val map : 'a t -> f:('a -> 'b) -> 'b t

Build a new node where the symbol has been mapped, keeping the original location.

val no_loc : 'a -> 'a t

Build a t where t.loc = Loc.none.

Fields getters

val loc : _ t -> loc
val txt : 'a t -> 'a
OCaml

Innovation. Community. Security.