Debian Codegraph @

coqpp/coqpp_parser.ml

raw symbols SCIP
1 (************************************************************************)
2 (* * The Rocq Prover / The Rocq Development Team *)
3 (* v * Copyright INRIA, CNRS and contributors *)
4 (* <O___,, * (see version control and CREDITS file for authors & dates) *)
5 (* \VV/ **************************************************************)
6 (* // * This file is distributed under the terms of the *)
7 (* * GNU Lesser General Public License Version 2.1 *)
8 (* * (see LICENSE file for the text of the license) *)
9 (************************************************************************)
10
11 open Lexing
12 open Coqpp_ast
13
14 let pr_loc loc =
15 let file = loc.loc_start.pos_fname in
16 let line = loc.loc_start.pos_lnum in
17 let bpos = loc.loc_start.pos_cnum - loc.loc_start.pos_bol in
18 let epos = loc.loc_end.pos_cnum - loc.loc_start.pos_bol in
19 Printf.sprintf "File \"%s\", line %d, characters %d-%d:" file line bpos epos
20
21
22 let fatal msg =
23 let () = Format.eprintf "Error: %s@\n%!" msg in
24 exit 1
25
26 let parse_file f =
27 let chan = open_in f in
28 let lexbuf = Lexing.from_channel chan in
29 let () = lexbuf.lex_curr_p <- { lexbuf.lex_curr_p with pos_fname = f } in
30 let ans =
31 try Coqpp_parse.file Coqpp_lex.token lexbuf
32 with
33 | Coqpp_lex.Lex_error (loc, msg) ->
34 let () = close_in chan in
35 let () = Printf.eprintf "%s\n%!" (pr_loc loc) in
36 fatal msg
37 | Parsing.Parse_error ->
38 let () = close_in chan in
39 let loc = Coqpp_lex.loc lexbuf in
40 let () = Printf.eprintf "%s\n%!" (pr_loc loc) in
41 fatal "syntax error"
42 in
43 let () = close_in chan in
44 ans