Project

General

Profile

Download (2.31 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

    
13
type error =
14
  | Undefined_token of string
15
  | Unexpected_eof
16
  | Unfinished_string
17
  | Unfinished_comment
18
  | Syntax_error
19
  | String_Syntax_error of string
20
  | Unfinished_annot
21
  | Unfinished_node_spec 
22
  | Annot_error of string
23
  | Node_spec_error of string
24

    
25
exception Error of (Location.t * error)
26

    
27
let pp_error fmt err =
28
  match err with
29
  | Unexpected_eof ->
30
    fprintf fmt "unexpected end of file"
31
  | Undefined_token tok ->
32
    fprintf fmt "undefined token '%s'" tok
33
  | Unfinished_string ->
34
    fprintf fmt "unfinished string"
35
  | Unfinished_comment ->
36
    fprintf fmt "unfinished comment"
37
  | Syntax_error ->
38
    fprintf fmt "syntax error"
39
  | String_Syntax_error s ->
40
    fprintf fmt "syntax error in %s" s
41
  | Unfinished_annot ->
42
    fprintf fmt "unfinished annotation"
43
  | Unfinished_node_spec ->
44
    fprintf fmt "unfinished node specification"
45
  | Annot_error s ->
46
    fprintf fmt "impossible to parse the following annotation:@.%s@.@?" s
47
  | Node_spec_error s ->
48
    fprintf fmt "Impossible to parse the following node specification:@.%s@.@?" s
49

    
50
let report_error (loc, err) =
51
  eprintf "Syntax error: %a@."
52
    (* pp_error err *)
53
    Location.pp_loc loc
54

    
55
let header parsing_fun token_fun lexbuf =
56
  try parsing_fun token_fun lexbuf with _ ->
57
    let loc = Location.curr lexbuf in
58
    let e = loc, Syntax_error in
59
    report_error e;
60
    raise (Error e)
61

    
62
let prog parsing_fun token_fun lexbuf =
63
  try parsing_fun token_fun lexbuf with err ->
64
    let loc = Location.curr lexbuf in
65
    let e = loc, Syntax_error in
66
    report_error e;
67
    raise (Error e)
68

    
69
(* Local Variables: *)
70
(* compile-command:"make -C .." *)
71
(* End: *)
(5-5/7)