2019-05-13 00:46:25 +04:00
|
|
|
(* type file_location = { *)
|
|
|
|
(* filename : string ; *)
|
|
|
|
(* start_line : int ; *)
|
|
|
|
(* start_column : int ; *)
|
|
|
|
(* end_line : int ; *)
|
|
|
|
(* end_column : int ; *)
|
|
|
|
(* } *)
|
|
|
|
|
|
|
|
type virtual_location = string
|
|
|
|
|
|
|
|
type t =
|
|
|
|
| File of Region.t (* file_location *)
|
|
|
|
| Virtual of virtual_location
|
|
|
|
|
2019-06-03 14:33:13 +04:00
|
|
|
let pp = fun ppf t ->
|
|
|
|
match t with
|
2020-06-12 15:33:14 +04:00
|
|
|
| Virtual _s -> Format.fprintf ppf ""
|
2019-06-03 14:33:13 +04:00
|
|
|
| File f -> Format.fprintf ppf "%s" (f#to_string `Point)
|
|
|
|
|
2020-05-22 05:22:35 +04:00
|
|
|
let compare a b = match a,b with
|
|
|
|
| (File a, File b) -> Region.compare a b
|
|
|
|
| (File _, Virtual _) -> -1
|
|
|
|
| (Virtual _, File _) -> 1
|
|
|
|
| (Virtual a, Virtual b) -> String.compare a b
|
|
|
|
|
2019-06-03 14:33:13 +04:00
|
|
|
|
2019-05-13 00:46:25 +04:00
|
|
|
let make (start_pos:Lexing.position) (end_pos:Lexing.position) : t =
|
|
|
|
(* TODO: give correct unicode offsets (the random number is here so
|
|
|
|
that searching for wrong souce locations appearing in messages
|
|
|
|
will quickly lead here *)
|
|
|
|
File (Region.make
|
|
|
|
~start:(Pos.make ~byte:start_pos ~point_num:(-1897000) ~point_bol:(-1897000))
|
|
|
|
~stop:(Pos.make ~byte:end_pos ~point_num:(-1897000) ~point_bol:(-1897000)))
|
|
|
|
|
|
|
|
let virtual_location s = Virtual s
|
|
|
|
let dummy = virtual_location "dummy"
|
2019-05-28 19:36:14 +04:00
|
|
|
let generated = virtual_location "generated"
|
2019-05-13 00:46:25 +04:00
|
|
|
|
|
|
|
type 'a wrap = {
|
|
|
|
wrap_content : 'a ;
|
|
|
|
location : t ;
|
|
|
|
}
|
|
|
|
|
2020-05-22 05:22:35 +04:00
|
|
|
let compare_wrap ~compare:compare_content { wrap_content = wca ; location = la } { wrap_content = wcb ; location = lb } =
|
|
|
|
match compare_content wca wcb with
|
|
|
|
| 0 -> compare la lb
|
|
|
|
| c -> c
|
|
|
|
|
2020-06-30 23:31:04 +04:00
|
|
|
let compare_content ~compare:compare_content wa wb =
|
|
|
|
compare_content wa.wrap_content wb.wrap_content
|
|
|
|
|
|
|
|
let equal_content ~equal:equal_content wa wb =
|
|
|
|
equal_content wa.wrap_content wb.wrap_content
|
|
|
|
|
2019-05-28 19:36:14 +04:00
|
|
|
let wrap ?(loc = generated) wrap_content = { wrap_content ; location = loc }
|
2019-05-28 21:02:40 +04:00
|
|
|
let get_location x = x.location
|
2019-05-13 00:46:25 +04:00
|
|
|
let unwrap { wrap_content ; _ } = wrap_content
|
|
|
|
let map f x = { x with wrap_content = f x.wrap_content }
|
|
|
|
let pp_wrap f ppf { wrap_content ; _ } = Format.fprintf ppf "%a" f wrap_content
|
|
|
|
|
|
|
|
let lift_region : 'a Region.reg -> 'a wrap = fun x ->
|
|
|
|
wrap ~loc:(File x.region) x.value
|
2019-05-28 19:36:14 +04:00
|
|
|
let lift : Region.region -> t = fun x -> File x
|
2019-06-03 14:33:13 +04:00
|
|
|
let pp_lift = fun ppf r -> pp ppf @@ lift r
|
2019-05-28 19:36:14 +04:00
|
|
|
|
|
|
|
let r_extract : 'a Region.reg -> t = fun x -> File x.region
|
|
|
|
let r_split : 'a Region.reg -> ('a * t) = fun x -> x.value , File x.region
|