Project

General

Profile

Download (2.45 KB) Statistics
| Branch: | Tag: | Revision:
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 Lustre_types
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
  | String_Syntax_error of string
22
  | 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
  | Syntax_error               -> fprintf fmt "syntax error"
37
  | String_Syntax_error s              -> fprintf fmt "syntax error in %s" s
38
  | 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

    
48
let header parsing_fun token_fun lexbuf =
49
  try
50
    let ast = parsing_fun token_fun lexbuf in
51
    Parsing.clear_parser ();
52
    ast
53
  with
54
  | Parsing.Parse_error ->
55
    let loc = Location.curr lexbuf in
56
    raise (Error (loc, Syntax_error))
57

    
58
let prog parsing_fun token_fun lexbuf =
59
  try
60
    let ast = parsing_fun token_fun lexbuf in
61
    Parsing.clear_parser ();
62
    ast
63
  with
64
  | Parsing.Parse_error ->
65
    let loc = Location.curr lexbuf in
66
    raise (Error (loc, Syntax_error))
67

    
68
(* Local Variables: *)
69
(* compile-command:"make -C .." *)
70
(* End: *)
(56-56/73)