Project

General

Profile

Revision 3b2bd83d src/parse.ml

View differences:

src/parse.ml
8 8
(*  version 2.1.                                                    *)
9 9
(*                                                                  *)
10 10
(********************************************************************)
11

  
12
exception Syntax_err of Location.t
13

  
14 11
open Format
15 12
open LustreSpec
16 13
open Corelang
17 14

  
18
let report_error loc =
19
  Location.print loc;
20
  print_string "Syntax error\n"
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
21 45

  
22 46
let header parsing_fun token_fun lexbuf =
23 47
  try
......
27 51
  with
28 52
  | Parsing.Parse_error ->
29 53
    let loc = Location.curr lexbuf in
30
    raise (Syntax_err loc)
54
    raise (Error (loc, Syntax_error))
31 55

  
32 56
let prog parsing_fun token_fun lexbuf =
33 57
  try
......
37 61
  with
38 62
  | Parsing.Parse_error ->
39 63
    let loc = Location.curr lexbuf in
40
    raise (Syntax_err loc)
64
    raise (Error (loc, Syntax_error))
41 65

  
42 66
(* Local Variables: *)
43 67
(* compile-command:"make -C .." *)

Also available in: Unified diff