Pure OCaml Yaml 1.2 reader and writer using Bytesrw
at main 1.2 kB view raw
1(*--------------------------------------------------------------------------- 2 Copyright (c) 2025 Anil Madhavapeddy <anil@recoil.org>. All rights reserved. 3 SPDX-License-Identifier: ISC 4 ---------------------------------------------------------------------------*) 5 6(** Source spans representing ranges in input *) 7 8type t = { start : Position.t; stop : Position.t } 9 10let make ~start ~stop = { start; stop } 11let point pos = { start = pos; stop = pos } 12 13let merge a b = 14 let start = 15 if Position.compare a.start b.start <= 0 then a.start else b.start 16 in 17 let stop = if Position.compare a.stop b.stop >= 0 then a.stop else b.stop in 18 { start; stop } 19 20let extend span pos = { span with stop = pos } 21 22let pp fmt t = 23 if t.start.line = t.stop.line then 24 Format.fprintf fmt "line %d, columns %d-%d" t.start.line t.start.column 25 t.stop.column 26 else Format.fprintf fmt "lines %d-%d" t.start.line t.stop.line 27 28let to_string t = Format.asprintf "%a" pp t 29 30let compare a b = 31 let c = Position.compare a.start b.start in 32 if c <> 0 then c else Position.compare a.stop b.stop 33 34let equal a b = Position.equal a.start b.start && Position.equal a.stop b.stop