package cascade

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Module Cascade.LocSource

Source locations: byte-offset ranges in the CSS Syntax-preprocessed input.

Reader.of_string strips a leading UTF-8 BOM, replaces NUL with U+FFFD, and maps CR, FF and CRLF to LF before the lexer records these offsets.

Every Token.t and Component.t carries one.

Sourcetype meta_level = [
  1. | `None
  2. | `Locs
  3. | `Full
]

Metadata level collected during parsing, mirroring ocaml-json's type meta:

  • `None: no source positions or snippets attached; fastest.
  • `Locs: source positions are kept on tokens / components / errors (already unconditional in Cascade since tokens always carry t). Equivalent to `None in Cascade -- present for API symmetry with ocaml-json.
  • `Full: also attach source-context snippets to errors and warnings, so Context.t.snippet is populated for diagnostics.
Sourceval default_meta_level : meta_level

default_meta_level is `Full. Entry points default to this so that callers who don't pass ?meta get the rich diagnostics behaviour.

Sourcetype t = {
  1. start_pos : int;
  2. end_pos : int;
}
Sourceval v : start_pos:int -> end_pos:int -> t

v ~start_pos ~end_pos is a location spanning [start_pos, end_pos) in the preprocessed source buffer.

Sourceval dummy : t

dummy is a location of zero width at position 0. For test data and synthetic values that don't come from a real input.

Sourceval union : t -> t -> t

union a b is the smallest location covering both a and b.

Sourceval pp : t Pp.t

pp formats as [start-end].

Sourceval to_string : t -> string

to_string t formats t as [start-end].

Sourcemodule Path : sig ... end
Sourcemodule Context : sig ... end
Sourceval snippet : ?window:int -> string -> t -> Context.snippet

snippet source loc extracts a snippet of source around loc: source must be the same preprocessed buffer the lexer indexed, such as Reader.source; a caller's original BOM/CRLF/NUL/FF-containing string is in a different coordinate space.

Context.snippet.text is the window (default: 40 bytes on each side of the location), Context.snippet.marker_pos counts the characters of Context.snippet.text before loc.start_pos, and Context.snippet.marker_len counts the characters the located range spans.

A column is one Unicode scalar value, which a combining mark and a wide glyph each make approximate on a terminal. window is a target rather than a cap: a boundary falling inside a UTF-8 sequence moves outward to the lead byte, so Context.snippet.text is never a truncated code point.