1997-08-22 01:55:41 -07:00
|
|
|
(***********************************************************************)
|
|
|
|
(* *)
|
2011-07-27 07:17:02 -07:00
|
|
|
(* OCaml *)
|
1997-08-22 01:55:41 -07:00
|
|
|
(* *)
|
|
|
|
(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
|
|
|
|
(* *)
|
|
|
|
(* Copyright 1997 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. *)
|
1997-08-22 01:55:41 -07:00
|
|
|
(* *)
|
|
|
|
(***********************************************************************)
|
|
|
|
|
|
|
|
(* Auxiliary type for reporting syntax errors *)
|
|
|
|
|
|
|
|
type error =
|
|
|
|
Unclosed of Location.t * string * Location.t * string
|
2012-10-16 07:04:33 -07:00
|
|
|
| Expecting of Location.t * string
|
2013-04-11 06:52:06 -07:00
|
|
|
| Not_expecting of Location.t * string
|
2009-07-15 07:06:37 -07:00
|
|
|
| Applicative_path of Location.t
|
2012-03-22 19:20:24 -07:00
|
|
|
| Variable_in_scope of Location.t * string
|
1997-08-22 01:55:41 -07:00
|
|
|
| Other of Location.t
|
|
|
|
|
|
|
|
exception Error of error
|
1997-11-12 04:32:53 -08:00
|
|
|
exception Escape_error
|
1997-08-22 01:55:41 -07:00
|
|
|
|
2013-09-11 11:10:59 -07:00
|
|
|
let prepare_error = function
|
2000-03-06 14:12:09 -08:00
|
|
|
| Unclosed(opening_loc, opening, closing_loc, closing) ->
|
2013-09-11 11:10:59 -07:00
|
|
|
Location.errorf ~loc:closing_loc
|
|
|
|
~sub:[
|
|
|
|
Location.error ~loc:opening_loc
|
|
|
|
(Printf.sprintf "Error: This '%s' might be unmatched" opening)
|
|
|
|
]
|
|
|
|
~if_highlight:
|
|
|
|
(Printf.sprintf "Syntax error: '%s' expected, \
|
|
|
|
the highlighted '%s' might be unmatched"
|
|
|
|
closing opening)
|
|
|
|
"Error: Syntax error: '%s' expected" closing
|
|
|
|
|
2012-10-16 07:04:33 -07:00
|
|
|
| Expecting (loc, nonterm) ->
|
2013-09-11 11:10:59 -07:00
|
|
|
Location.errorf ~loc "Error: Syntax error: %s expected." nonterm
|
2013-04-11 06:52:06 -07:00
|
|
|
| Not_expecting (loc, nonterm) ->
|
2013-09-11 11:10:59 -07:00
|
|
|
Location.errorf ~loc "Error: Syntax error: %s not expected." nonterm
|
2009-07-15 07:06:37 -07:00
|
|
|
| Applicative_path loc ->
|
2013-09-11 11:10:59 -07:00
|
|
|
Location.errorf ~loc
|
|
|
|
"Error: Syntax error: applicative paths of the form F(X).t \
|
2011-10-28 14:26:01 -07:00
|
|
|
are not supported when the option -no-app-func is set."
|
2012-03-22 19:20:24 -07:00
|
|
|
| Variable_in_scope (loc, var) ->
|
2013-09-11 11:10:59 -07:00
|
|
|
Location.errorf ~loc
|
|
|
|
"Error: In this scoped type, variable '%s@ \
|
|
|
|
is reserved for the local type %s."
|
|
|
|
var var
|
1997-08-22 01:55:41 -07:00
|
|
|
| Other loc ->
|
2013-09-11 11:10:59 -07:00
|
|
|
Location.error ~loc "Error: Syntax error"
|
|
|
|
|
|
|
|
let () =
|
|
|
|
Location.register_error_of_exn
|
|
|
|
(function
|
|
|
|
| Error err -> Some (prepare_error err)
|
|
|
|
| _ -> None
|
|
|
|
)
|
|
|
|
|
2012-10-16 07:04:33 -07:00
|
|
|
|
2013-09-11 11:10:59 -07:00
|
|
|
let report_error ppf err =
|
|
|
|
Location.report_error ppf (prepare_error err)
|
2012-10-16 07:04:33 -07:00
|
|
|
|
|
|
|
let location_of_error = function
|
|
|
|
| Unclosed(l,_,_,_)
|
|
|
|
| Applicative_path l
|
|
|
|
| Variable_in_scope(l,_)
|
|
|
|
| Other l
|
2013-04-11 06:52:06 -07:00
|
|
|
| Not_expecting (l, _)
|
2012-10-16 07:04:33 -07:00
|
|
|
| Expecting (l, _) -> l
|