Select the types of activity you want to include in your feed.
loc,json,csv,sexp,toml,xml,opam,rego,sbom: rename Meta.textloc to Meta.loc
Follow up to the loc/json reorg: the [textloc] field of [Meta] is renamed to [loc] across every text-codec consumer. Pure mechanical rename, no behaviour change.
···11# loc
2233-Source locations and structured errors for text-based codecs in OCaml,
44-extracted from Daniel Bünzli's
55-[jsont](https://erratique.ch/software/jsont). Packaging the shared base
66-as a standalone library lets non-JSON text codecs (`xml`, `csv`, `sexp`,
77-`toml`, ...) report error positions uniformly without pulling in
88-`jsont`.
33+Source locations and structured errors shared across text codecs
44+(JSON, TOML, YAML, XML, CSV, S-expression, ...).
951010-A direct copy of `jsont_base.ml` and the `Error` module of `jsont.ml`,
1111-with JSON-specific pieces (the `Number` module, the JSON `Sort.t` enum,
1212-JSON-shaped predefined errors) removed; everything else is verbatim.
66+Every OCaml codec library needs the same plumbing: byte ranges, line
77+positions, context-aware error paths, and a printer that matches the
88+OCaml compiler / GNU error convention. `loc` provides that plumbing as
99+one small library so codecs depend on it instead of each reinventing
1010+it — or, worse, exposing a private error type that upstream tools
1111+cannot compose.
13121413Provides:
15141615- `Loc` — byte and line ranges for UTF-8 source text
1716- `Loc.Meta` — node metadata: source location and surrounding whitespace
1817- `Loc.Path` — structural paths (`Mem of string node | Nth of int node`)
1919-- `Loc.Error` — structured errors: extensible kind, source location,
2020- contextual path; formatted per the OCaml compiler / GNU error
2121- conventions
1818+- `Loc.Context` — navigation contexts accumulated during descent
1919+- `Loc.Error` — structured errors with an {i extensible} kind, source
2020+ location, and contextual path; formatted per the OCaml compiler /
2121+ GNU error conventions
2222- `exception Loc.Error of Loc.Error.t` — single shared exception for
2323 cross-package error propagation
2424
+16-18
lib/loc.ml
···191191(* Node metadata *)
192192193193module Meta = struct
194194- type textloc = t
195195- type t = { textloc : textloc; ws_before : string; ws_after : string }
196196-197197- let make ?(ws_before = "") ?(ws_after = "") textloc =
198198- { textloc; ws_before; ws_after }
194194+ type location = t
195195+ type t = { loc : location; ws_before : string; ws_after : string }
199196200200- let none = { textloc = none; ws_before = ""; ws_after = "" }
197197+ let make ?(ws_before = "") ?(ws_after = "") loc = { loc; ws_before; ws_after }
198198+ let none = { loc = none; ws_before = ""; ws_after = "" }
201199 let is_none m = none == m
202202- let textloc m = m.textloc
200200+ let loc m = m.loc
203201 let ws_before m = m.ws_before
204202 let ws_after m = m.ws_after
205205- let with_textloc m textloc = { m with textloc }
203203+ let with_loc m loc = { m with loc }
206204 let clear_ws m = { m with ws_before = ""; ws_after = "" }
207207- let clear_textloc m = { m with textloc = none.textloc }
205205+ let clear_loc m = { m with loc = none.loc }
208206209207 let copy_ws src ~dst =
210208 { dst with ws_before = src.ws_before; ws_after = src.ws_after }
···240238241239 let default_pp_step_trace ppf = function
242240 | Mem (n, meta) ->
243243- Fmt.pf ppf "%a: in member %a" pp (Meta.textloc meta) pp_name n
241241+ Fmt.pf ppf "%a: in member %a" pp (Meta.loc meta) pp_name n
244242 | Nth (n, meta) ->
245245- Fmt.pf ppf "%a: at index %a" pp (Meta.textloc meta) pp_step_num n
243243+ Fmt.pf ppf "%a: at index %a" pp (Meta.loc meta) pp_step_num n
246244 | s -> pp_step ppf s
247245248246 let pp_step_trace = default_pp_step_trace
···349347350348 let pp ppf ctx =
351349 let pp_meta ppf meta =
352352- if Meta.is_none meta then () else Fmt.pf ppf "%a: " pp (Meta.textloc meta)
350350+ if Meta.is_none meta then () else Fmt.pf ppf "%a: " pp (Meta.loc meta)
353351 in
354352 let pp_el ppf { sort; step } =
355353 match step with
···423421 match e.ctx with
424422 | [] -> raise_notrace (Error e)
425423 | { sort = name, smeta; step } :: is ->
426426- let textloc = Meta.textloc smeta in
427427- let textloc =
428428- if is_none textloc then textloc
429429- else set_first textloc ~first_byte ~first_line_num ~first_line_byte
424424+ let loc = Meta.loc smeta in
425425+ let loc =
426426+ if is_none loc then loc
427427+ else set_first loc ~first_byte ~first_line_num ~first_line_byte
430428 in
431431- let smeta = Meta.with_textloc smeta textloc in
429429+ let smeta = Meta.with_loc smeta loc in
432430 let ctx = { Context.sort = (name, smeta); step } :: is in
433431 raise_notrace (Error { e with ctx })
434432435433 let pp ppf e =
436434 let pp_meta ppf m =
437437- if not (Meta.is_none m) then Fmt.pf ppf "@,%a:" pp (Meta.textloc m)
435435+ if not (Meta.is_none m) then Fmt.pf ppf "@,%a:" pp (Meta.loc m)
438436 in
439437 Fmt.pf ppf "@[<v>%a%a%a@]" pp_kind e.kind pp_meta e.meta Context.pp e.ctx
440438
+6-6
lib/loc.mli
···176176 val is_none : t -> bool
177177 (** [is_none m] is [true] iff [m] is {!none} (physical equality). *)
178178179179- val textloc : t -> loc
180180- (** [textloc m] is the source location of [m]. *)
179179+ val loc : t -> loc
180180+ (** [loc m] is the source location of [m]. *)
181181182182 val ws_before : t -> string
183183 (** [ws_before m] is the whitespace preceding the node. *)
···185185 val ws_after : t -> string
186186 (** [ws_after m] is the whitespace following the node. *)
187187188188- val with_textloc : t -> loc -> t
189189- (** [with_textloc m loc] is [m] with source location set to [loc]. *)
188188+ val with_loc : t -> loc -> t
189189+ (** [with_loc m loc] is [m] with source location set to [loc]. *)
190190191191 val clear_ws : t -> t
192192 (** [clear_ws m] is [m] with both whitespace fields cleared. *)
193193194194- val clear_textloc : t -> t
195195- (** [clear_textloc m] is [m] with its source location set to {!none}. *)
194194+ val clear_loc : t -> t
195195+ (** [clear_loc m] is [m] with its source location set to {!none}. *)
196196197197 val copy_ws : t -> dst:t -> t
198198 (** [copy_ws src ~dst] is [dst] with its whitespace fields copied from [src].