1995-08-09 08:06:35 -07:00
|
|
|
(***********************************************************************)
|
|
|
|
(* *)
|
2011-07-27 07:17:02 -07:00
|
|
|
(* OCaml *)
|
1995-08-09 08:06:35 -07:00
|
|
|
(* *)
|
|
|
|
(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
|
|
|
|
(* *)
|
1996-04-30 07:53:58 -07:00
|
|
|
(* Copyright 1996 Institut National de Recherche en Informatique et *)
|
1999-11-17 10:59:06 -08:00
|
|
|
(* en Automatique. All rights reserved. This file is distributed *)
|
|
|
|
(* under the terms of the Q Public License version 1.0. *)
|
1995-08-09 08:06:35 -07:00
|
|
|
(* *)
|
|
|
|
(***********************************************************************)
|
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
(* Entry points in the parser *)
|
|
|
|
|
|
|
|
(* 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
|
1997-04-16 06:19:12 -07:00
|
|
|
with
|
2012-05-30 07:52:37 -07:00
|
|
|
| Lexer.Error (Lexer.Unterminated_comment _, _) -> ()
|
2002-11-01 09:06:47 -08:00
|
|
|
| Lexer.Error (Lexer.Unterminated_string, _) -> ()
|
2012-05-30 07:52:37 -07:00
|
|
|
| Lexer.Error (Lexer.Unterminated_string_in_comment _, _) -> ()
|
2002-11-01 09:06:47 -08:00
|
|
|
| Lexer.Error (Lexer.Illegal_character _, _) -> skip_phrase lexbuf
|
1999-10-15 11:34:04 -07:00
|
|
|
;;
|
1995-05-04 03:15:53 -07:00
|
|
|
|
|
|
|
let maybe_skip_phrase lexbuf =
|
|
|
|
if Parsing.is_current_lookahead Parser.SEMISEMI
|
2000-12-28 05:07:42 -08:00
|
|
|
|| Parsing.is_current_lookahead Parser.EOF
|
1995-05-04 03:15:53 -07:00
|
|
|
then ()
|
|
|
|
else skip_phrase lexbuf
|
|
|
|
|
|
|
|
let wrap parsing_fun lexbuf =
|
|
|
|
try
|
2012-05-30 07:52:37 -07:00
|
|
|
Lexer.init ();
|
1997-07-02 11:16:15 -07:00
|
|
|
let ast = parsing_fun Lexer.token lexbuf in
|
|
|
|
Parsing.clear_parser();
|
|
|
|
ast
|
1995-05-04 03:15:53 -07:00
|
|
|
with
|
2012-05-30 07:52:37 -07:00
|
|
|
| Lexer.Error(Lexer.Unterminated_comment _, _) as err -> raise err
|
2002-11-01 09:06:47 -08:00
|
|
|
| Lexer.Error(Lexer.Unterminated_string, _) as err -> raise err
|
2012-05-30 07:52:37 -07:00
|
|
|
| Lexer.Error(Lexer.Unterminated_string_in_comment _, _) as err -> raise err
|
2002-11-01 09:06:47 -08:00
|
|
|
| Lexer.Error(Lexer.Illegal_character _, _) as err ->
|
2011-08-04 07:59:13 -07:00
|
|
|
if !Location.input_name = "//toplevel//" then skip_phrase lexbuf;
|
1999-10-15 11:34:04 -07:00
|
|
|
raise err
|
|
|
|
| Syntaxerr.Error _ as err ->
|
2011-08-04 07:59:13 -07:00
|
|
|
if !Location.input_name = "//toplevel//" then maybe_skip_phrase lexbuf;
|
1999-10-15 11:34:04 -07:00
|
|
|
raise err
|
|
|
|
| Parsing.Parse_error | Syntaxerr.Escape_error ->
|
2002-11-01 09:06:47 -08:00
|
|
|
let loc = Location.curr lexbuf in
|
2011-08-04 07:59:13 -07:00
|
|
|
if !Location.input_name = "//toplevel//"
|
1999-10-15 11:34:04 -07:00
|
|
|
then maybe_skip_phrase lexbuf;
|
|
|
|
raise(Syntaxerr.Error(Syntaxerr.Other loc))
|
|
|
|
;;
|
1995-05-04 03:15:53 -07:00
|
|
|
|
1995-11-01 10:12:24 -08:00
|
|
|
let implementation = wrap Parser.implementation
|
1995-05-04 03:15:53 -07:00
|
|
|
and interface = wrap Parser.interface
|
1995-11-01 10:12:24 -08:00
|
|
|
and toplevel_phrase = wrap Parser.toplevel_phrase
|
|
|
|
and use_file = wrap Parser.use_file
|
2013-03-29 02:45:45 -07:00
|
|
|
and core_type = wrap Parser.parse_core_type
|
|
|
|
and expression = wrap Parser.parse_expression
|
|
|
|
and pattern = wrap Parser.parse_pattern
|