-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patherror.ml
More file actions
34 lines (28 loc) · 978 Bytes
/
Copy patherror.ml
File metadata and controls
34 lines (28 loc) · 978 Bytes
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
open Lexing
open Ast
open Format
type error =
| Lexical_error of string
| Syntax_error of string option
| Interpretation_error
(*| Unknown_identifier of string*)
exception Error of error * Ast.position
let report_loc fmt file (b,e) =
if b = dummy_pos || e = dummy_pos then
fprintf fmt "File \"%s\"\nerror: " file
else
let l = b.pos_lnum in
let fc = b.pos_cnum - b.pos_bol + 1 in
let lc = e.pos_cnum - b.pos_bol + 1 in
fprintf fmt "File \"%s\", line %d, characters %d-%d\nerror: " file l fc lc
let to_string e =
match e with
| Lexical_error s -> sprintf "lexical error: %s" s
| Syntax_error None -> sprintf "syntax error"
| Syntax_error (Some s) -> sprintf "syntax error: %s" s
| Interpretation_error -> sprintf "interpretation error"
(*| Unknown_identifier id -> sprintf "unknown identifier %s" id*)
let print fmt f e p =
report_loc fmt f p;
fprintf fmt "%s\n@." (to_string e)
let error e p = raise (Error (e, p))