blob: fdb3ec6d9030f4f9b8c5c3bb26a260bf64348ea7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
(***********************************************************************)
(* *)
(* Caml Special Light *)
(* *)
(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
(* *)
(* Copyright 1995 Institut National de Recherche en Informatique et *)
(* Automatique. Distributed only by permission. *)
(* *)
(***********************************************************************)
(* $Id$ *)
(* Entry points in the parser *)
exception Error of int * int (* Syntax error *)
(* Skip tokens to the end of the phrase *)
let rec skip_phrase lexbuf =
try
match Lexer.token lexbuf with
Parser.SEMISEMI | Parser.EOF -> ()
| _ -> skip_phrase lexbuf
with Lexer.Error(_,_,_) ->
skip_phrase lexbuf
let maybe_skip_phrase lexbuf =
if Parsing.is_current_lookahead Parser.SEMISEMI
or Parsing.is_current_lookahead Parser.EOF
then ()
else skip_phrase lexbuf
let wrap parsing_fun lexbuf =
try
parsing_fun Lexer.token lexbuf
with
Lexer.Error(_, _, _) as err ->
if !Location.input_name = "" then skip_phrase lexbuf;
raise err
| Parsing.Parse_error ->
let start = Lexing.lexeme_start lexbuf
and stop = Lexing.lexeme_end lexbuf in
if !Location.input_name = ""
then maybe_skip_phrase lexbuf;
raise(Error(start, stop))
let implementation = wrap Parser.implementation
and interface = wrap Parser.interface
and toplevel_phrase = wrap Parser.toplevel_phrase
and use_file = wrap Parser.use_file
|