-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathError.ml
40 lines (31 loc) · 885 Bytes
/
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
38
39
40
open Lexing
type place =
position * position
let place lexbuf : place =
lexbuf.lex_start_p, lexbuf.lex_curr_p
let line p : int =
p.pos_lnum
let column p : int =
p.pos_cnum - p.pos_bol
let show place : string =
let startp, endp = place in
Format.sprintf "File \"%s\", line %d, characters %d-%d"
startp.pos_fname
(line startp)
(column startp)
(endp.pos_cnum - startp.pos_bol) (* intentionally [startp.pos_bol] *)
let display continuation header place format =
Format.eprintf "%s:\n" (show place);
Format.kfprintf
continuation
Format.err_formatter
(header ^^ format ^^ "\n%!")
let error place format =
display
(fun _ -> exit 1)
"Error: "
place format
let set_filename lexbuf filename =
lexbuf.lex_curr_p <- { lexbuf.lex_curr_p with pos_fname = filename }
let pp_place formatter _place =
Format.fprintf formatter "<>"