better error reporting
This commit is contained in:
parent
5a13387210
commit
a71db86d88
|
@ -52,7 +52,15 @@ let with_file_in fn ~f =
|
|||
protectx (open_in fn) ~finally:close_in ~f
|
||||
|
||||
let with_lexbuf_from_file fn ~f =
|
||||
with_file_in fn ~f:(fun ic -> f (Lexing.from_channel ic))
|
||||
with_file_in fn ~f:(fun ic ->
|
||||
let lb = Lexing.from_channel ic in
|
||||
lb.lex_curr_p <-
|
||||
{ pos_fname = fn
|
||||
; pos_lnum = 1
|
||||
; pos_bol = 0
|
||||
; pos_cnum = 0
|
||||
};
|
||||
f lb)
|
||||
|
||||
let lines_of_file fn =
|
||||
let rec loop ic acc =
|
||||
|
|
15
src/main.ml
15
src/main.ml
|
@ -7,7 +7,7 @@ let internal argv =
|
|||
| _ ->
|
||||
()
|
||||
|
||||
let () =
|
||||
let main () =
|
||||
let argv = Sys.argv in
|
||||
let argc = Array.length argv in
|
||||
let compact () =
|
||||
|
@ -19,3 +19,16 @@ let () =
|
|||
match argv.(1) with
|
||||
| "internal" -> internal (compact ())
|
||||
| _ -> ()
|
||||
|
||||
let () =
|
||||
try
|
||||
main ()
|
||||
with
|
||||
| Loc.Error ({ start; stop }, msg) ->
|
||||
let start_c = start.pos_cnum - start.pos_bol in
|
||||
let stop_c = stop.pos_cnum - start.pos_bol in
|
||||
Printf.eprintf
|
||||
"File \"%s\", line %d, characters %d-%d:\n\
|
||||
Error: %s\n%!"
|
||||
start.pos_fname start.pos_lnum start_c stop_c msg
|
||||
|
||||
|
|
Loading…
Reference in New Issue