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
module Builder = Ppxlib.Ast_builder.Default
let make ~description ~examples ~link =
let examples =
match examples with
| Some examples ->
Printf.sprintf "\n\nExample:\n %s" (String.concat "\n " examples)
| None -> ""
in
let link =
match link with
| Some link -> Printf.sprintf "\n\nMore info: %s" link
| None -> ""
in
Printf.sprintf "%s%s%s" description examples link
let expr ~loc ?examples ?link description =
let message = make ~description ~examples ~link in
Builder.pexp_extension ~loc
@@ Ppxlib.Location.Error.to_extension
@@ Ppxlib.Location.Error.make ~loc message ~sub:[]
let raise ~loc ?examples ?link description =
let message = make ~description ~examples ~link in
raise @@ Ppxlib.Location.raise_errorf ~loc "%s" message