package loc

  1. Overview
  2. Docs

Module Loc.TxtSource

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
Sourcetype loc := t
Sourcetype 'a t = {
  1. txt : 'a;
  2. loc : loc;
}
Sourceval equal : ('a -> 'a -> bool) -> 'a t -> 'a t -> bool

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

Sourceval 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.

Sourceval 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 }
  ;
Sourceval map : 'a t -> f:('a -> 'b) -> 'b t

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

Sourceval no_loc : 'a -> 'a t

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

Fields getters

Sourceval loc : _ t -> loc
Sourceval txt : 'a t -> 'a