-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsupport.ml
72 lines (54 loc) · 1.78 KB
/
support.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
open Format
module Error =
struct
open Lexing
type 'a with_pos = {p:position; v:'a}
type range = {frm:position; to_:position}
type 'a with_ran = {r:range; v:'a}
let dummy_range = {frm=dummy_pos; to_=dummy_pos}
let join_range r1 r2 = {frm=r1.frm; to_=r2.to_}
let print_pos ppf pos =
(if pos.pos_fname = "" then
fprintf ppf "line %d, character %d"
else
fprintf ppf "File \"%s\", line %d, character %d" pos.pos_fname)
pos.pos_lnum
(pos.pos_cnum - pos.pos_bol)
let string_of_pos pos =
(if pos.pos_fname = "" then
Printf.sprintf "line %d, character %d"
else
Printf.sprintf "File \"%s\", line %d, character %d" pos.pos_fname)
pos.pos_lnum
(pos.pos_cnum - pos.pos_bol)
let print_ran ppf {frm=pos1; to_=pos2} =
(if pos1.pos_fname = "" then
fprintf ppf "line %d, character %d -- line %d, character %d"
else
fprintf ppf "File \"%s\", line %d, character %d -- line %d, character %d" pos1.pos_fname)
pos1.pos_lnum
(pos1.pos_cnum - pos1.pos_bol)
pos2.pos_lnum
(pos2.pos_cnum - pos2.pos_bol)
let err ppf s =
fprintf ppf "\n%s\n" s;
exit 0
let errAt ppf pos s =
fprintf ppf "\n%a" print_pos pos;
err ppf s
let errBtw ppf ran s =
fprintf ppf "\n%a" print_ran ran;
err ppf s
let warning ppf s =
fprintf ppf "\n%s\n@?" s
let warningAt ppf pos s =
fprintf ppf "\n%a%a" print_pos pos warning s
let warningBtw ppf ran s =
fprintf ppf "\n%a%a" print_ran ran warning s
let err s = err std_formatter s
let errAt pos s = errAt std_formatter pos s
let errBtw ran s = errBtw std_formatter ran s
let warning s = warning std_formatter s
let warningAt pos s = warningAt std_formatter pos s
let warningBtw ran s = warningBtw std_formatter ran s
end