1 |
a2d97a3e
|
ploc
|
(********************************************************************)
|
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 |
22fe1c93
|
ploc
|
open Format
|
12 |
8446bf03
|
ploc
|
open Lustre_types
|
13 |
b1655a21
|
xthirioux
|
open Corelang
|
14 |
|
|
|
15 |
04a63d25
|
xthirioux
|
type error =
|
16 |
|
|
| Undefined_token of string
|
17 |
|
|
| Unexpected_eof
|
18 |
|
|
| Unfinished_string
|
19 |
|
|
| Unfinished_comment
|
20 |
|
|
| Syntax_error
|
21 |
9ae027f8
|
ploc
|
| String_Syntax_error of string
|
22 |
04a63d25
|
xthirioux
|
| Unfinished_annot
|
23 |
|
|
| Unfinished_node_spec
|
24 |
|
|
| Annot_error of string
|
25 |
|
|
| Node_spec_error of string
|
26 |
|
|
|
27 |
|
|
exception Error of (Location.t * error)
|
28 |
|
|
|
29 |
|
|
|
30 |
|
|
let pp_error fmt err =
|
31 |
|
|
match err with
|
32 |
|
|
| Unexpected_eof -> fprintf fmt "unexpected end of file"
|
33 |
|
|
| Undefined_token tok -> fprintf fmt "undefined token '%s'" tok
|
34 |
|
|
| Unfinished_string -> fprintf fmt "unfinished string"
|
35 |
|
|
| Unfinished_comment -> fprintf fmt "unfinished comment"
|
36 |
9ae027f8
|
ploc
|
| Syntax_error -> fprintf fmt "syntax error"
|
37 |
|
|
| String_Syntax_error s -> fprintf fmt "syntax error in %s" s
|
38 |
04a63d25
|
xthirioux
|
| Unfinished_annot -> fprintf fmt "unfinished annotation"
|
39 |
|
|
| Unfinished_node_spec -> fprintf fmt "unfinished node specification"
|
40 |
|
|
| Annot_error s -> fprintf fmt "impossible to parse the following annotation:@.%s@.@?" s
|
41 |
|
|
| Node_spec_error s -> fprintf fmt "Impossible to parse the following node specification:@.%s@.@?" s
|
42 |
|
|
|
43 |
|
|
let report_error (loc, err) =
|
44 |
|
|
eprintf "Syntax error: %a%a@."
|
45 |
|
|
pp_error err
|
46 |
|
|
Location.pp_loc loc
|
47 |
ef34b4ae
|
xthirioux
|
|
48 |
|
|
let header parsing_fun token_fun lexbuf =
|
49 |
89b9e25c
|
xthirioux
|
try
|
50 |
ef34b4ae
|
xthirioux
|
let ast = parsing_fun token_fun lexbuf in
|
51 |
89b9e25c
|
xthirioux
|
Parsing.clear_parser ();
|
52 |
|
|
ast
|
53 |
|
|
with
|
54 |
|
|
| Parsing.Parse_error ->
|
55 |
|
|
let loc = Location.curr lexbuf in
|
56 |
04a63d25
|
xthirioux
|
raise (Error (loc, Syntax_error))
|
57 |
22fe1c93
|
ploc
|
|
58 |
89b9e25c
|
xthirioux
|
let prog parsing_fun token_fun lexbuf =
|
59 |
22fe1c93
|
ploc
|
try
|
60 |
|
|
let ast = parsing_fun token_fun lexbuf in
|
61 |
|
|
Parsing.clear_parser ();
|
62 |
|
|
ast
|
63 |
|
|
with
|
64 |
21485807
|
xthirioux
|
| Parsing.Parse_error ->
|
65 |
|
|
let loc = Location.curr lexbuf in
|
66 |
04a63d25
|
xthirioux
|
raise (Error (loc, Syntax_error))
|
67 |
22fe1c93
|
ploc
|
|
68 |
|
|
(* Local Variables: *)
|
69 |
|
|
(* compile-command:"make -C .." *)
|
70 |
|
|
(* End: *)
|