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:
1 file changed
+14
+14
@@ -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) }
|
||||||
Reference in new issue
Block a user