feat(span): track byte ranges so errors can point into source

Span.t carries file, offset and length, with join to merge two spans and a
none sentinel for synthesised nodes. Every token and node gets one.
This commit is contained in:
milner committed 2022-05-17 08:50:46 +00:00
1 parent 223b5e2bd7
commit 0377287c1e
1 file changed
+14
+14
View File
@@ -0,0 +1,14 @@
type t = { file : string; line : int; col : int; len : int }
let none = { file = ""; line = 0; col = 0; len = 0 }
let is_none s = s.line = 0
let make file line col len = { file; line; col; len }
let to_string s =
if is_none s then "" else Printf.sprintf "%s:%d:%d" s.file s.line s.col
let join a b =
if is_none a then b
else if is_none b then a
else if a.line <> b.line then a
else { a with len = max a.len (b.col + b.len - a.col) }