Source file syntax_error.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
open! Stdppx
module Error = Astlib.Location.Error
type t = Error.t
let createf ~loc fmt =
Format.kasprintf
(fun txt -> Error.make { loc = { loc with loc_ghost = true }; txt } ~sub:[])
fmt
;;
let combine (hd :: tl : _ Nonempty_list.t) =
if List.is_empty tl
then hd
else
Error.make
(Error.main_msg hd)
~sub:
(Error.sub_msgs hd
@ List.concat_map tl ~f:(fun err -> Error.main_msg err :: Error.sub_msgs err))
;;
let loc_of_ppxlib_error err : string Ppxlib.loc =
{ loc = Ppxlib.Location.Error.get_location err
; txt = Ppxlib.Location.Error.message err
}
;;
let of_location_errors (err, errs) =
Error.make (loc_of_ppxlib_error err) ~sub:(List.map ~f:loc_of_ppxlib_error errs)
;;
let to_extension = Ppxlib_ast.Location_error.to_extension