Project

General

Profile

« Previous | Next » 

Revision 57c96fb7

Added by LĂ©lio Brun 11 months ago

setup tests for dune

View differences:

src/parsers/parse.ml
24 24

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

  
27

  
28 27
let pp_error fmt err =
29 28
  match err with
30
  | Unexpected_eof          -> fprintf fmt "unexpected end of file"
31
  | Undefined_token tok   -> fprintf fmt "undefined token '%s'" tok
32
  | Unfinished_string        -> fprintf fmt "unfinished string"
33
  | Unfinished_comment  -> fprintf fmt "unfinished comment"
34
  | Syntax_error               -> fprintf fmt "syntax error"
35
  | String_Syntax_error s              -> fprintf fmt "syntax error in %s" s
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
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
40 49

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

  
46 55
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 ->
56
  try parsing_fun token_fun lexbuf with _ ->
53 57
    let loc = Location.curr lexbuf in
54
    raise (Error (loc, Syntax_error))
58
    let e = loc, Syntax_error in
59
    report_error e;
60
    raise (Error e)
55 61

  
56 62
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
  try parsing_fun token_fun lexbuf with err ->
63 64
    let loc = Location.curr lexbuf in
64
    raise (Error (loc, Syntax_error))
65
    let e = loc, Syntax_error in
66
    report_error e;
67
    raise (Error e)
65 68

  
66 69
(* Local Variables: *)
67 70
(* compile-command:"make -C .." *)

Also available in: Unified diff