lustrec / src / parse.ml @ 45f0f48d
History | View | Annotate | Download (2.33 KB)
1 |
(********************************************************************) |
---|---|
2 |
(* *) |
3 |
(* The LustreC compiler toolset / The LustreC Development Team *) |
4 |
(* Copyright 2012 - -- ONERA - CNRS - INPT *) |
5 |
(* *) |
6 |
(* LustreC is free software, distributed WITHOUT ANY WARRANTY *) |
7 |
(* under the terms of the GNU Lesser General Public License *) |
8 |
(* version 2.1. *) |
9 |
(* *) |
10 |
(********************************************************************) |
11 |
open Format |
12 |
open LustreSpec |
13 |
open Corelang |
14 |
|
15 |
type error = |
16 |
| Undefined_token of string |
17 |
| Unexpected_eof |
18 |
| Unfinished_string |
19 |
| Unfinished_comment |
20 |
| Syntax_error |
21 |
| Unfinished_annot |
22 |
| Unfinished_node_spec |
23 |
| Annot_error of string |
24 |
| Node_spec_error of string |
25 |
|
26 |
exception Error of (Location.t * error) |
27 |
|
28 |
|
29 |
let pp_error fmt err = |
30 |
match err with |
31 |
| Unexpected_eof -> fprintf fmt "unexpected end of file" |
32 |
| Undefined_token tok -> fprintf fmt "undefined token '%s'" tok |
33 |
| Unfinished_string -> fprintf fmt "unfinished string" |
34 |
| Unfinished_comment -> fprintf fmt "unfinished comment" |
35 |
| Syntax_error -> fprintf fmt "" |
36 |
| Unfinished_annot -> fprintf fmt "unfinished annotation" |
37 |
| Unfinished_node_spec -> fprintf fmt "unfinished node specification" |
38 |
| Annot_error s -> fprintf fmt "impossible to parse the following annotation:@.%s@.@?" s |
39 |
| Node_spec_error s -> fprintf fmt "Impossible to parse the following node specification:@.%s@.@?" s |
40 |
|
41 |
let report_error (loc, err) = |
42 |
eprintf "Syntax error: %a%a@." |
43 |
pp_error err |
44 |
Location.pp_loc loc |
45 |
|
46 |
let header parsing_fun token_fun lexbuf = |
47 |
try |
48 |
let ast = parsing_fun token_fun lexbuf in |
49 |
Parsing.clear_parser (); |
50 |
ast |
51 |
with |
52 |
| Parsing.Parse_error -> |
53 |
let loc = Location.curr lexbuf in |
54 |
raise (Error (loc, Syntax_error)) |
55 |
|
56 |
let prog parsing_fun token_fun lexbuf = |
57 |
try |
58 |
let ast = parsing_fun token_fun lexbuf in |
59 |
Parsing.clear_parser (); |
60 |
ast |
61 |
with |
62 |
| Parsing.Parse_error -> |
63 |
let loc = Location.curr lexbuf in |
64 |
raise (Error (loc, Syntax_error)) |
65 |
|
66 |
(* Local Variables: *) |
67 |
(* compile-command:"make -C .." *) |
68 |
(* End: *) |