Commit 339d6f81 authored by POTTIER Francois's avatar POTTIER Francois

Produce an error message when --inspection is set but the type [nonterminal]

cannot be generated because the type of some nonterminal symbol is unknown.
parent 84348b9a
...@@ -19,12 +19,13 @@ let tnonterminalgadtdata nt = ...@@ -19,12 +19,13 @@ let tnonterminalgadtdata nt =
(* This is the definition of the nonterminal GADT. Here, the data (* This is the definition of the nonterminal GADT. Here, the data
constructors have no value argument, but have a type index. *) constructors have no value argument, but have a type index. *)
exception MissingOCamlType exception MissingOCamlType of string
let nonterminalgadtdef grammar = let nonterminalgadtdef grammar =
assert Settings.inspection; assert Settings.inspection;
let comment, datadefs = let comment, datadefs =
try try
"The indexed type of nonterminal symbols.", "The indexed type of nonterminal symbols.",
List.fold_left (fun defs nt -> List.fold_left (fun defs nt ->
let index = let index =
...@@ -32,7 +33,7 @@ let nonterminalgadtdef grammar = ...@@ -32,7 +33,7 @@ let nonterminalgadtdef grammar =
| Some t -> | Some t ->
TypTextual t TypTextual t
| None -> | None ->
raise MissingOCamlType raise (MissingOCamlType nt)
in in
{ {
dataname = tnonterminalgadtdata nt; dataname = tnonterminalgadtdata nt;
...@@ -40,14 +41,28 @@ let nonterminalgadtdef grammar = ...@@ -40,14 +41,28 @@ let nonterminalgadtdef grammar =
datatypeparams = Some [ index ] datatypeparams = Some [ index ]
} :: defs } :: defs
) [] (nonterminals grammar) ) [] (nonterminals grammar)
with MissingOCamlType ->
with MissingOCamlType nt ->
(* If the type of some nonterminal symbol is unknown, give up (* If the type of some nonterminal symbol is unknown, give up
and define ['a nonterminal] as an abstract type. This is and define ['a nonterminal] as an abstract type. This is
useful when we are in [--(raw)-depend] mode and we do not useful when we are in [--(raw)-depend] mode and we do not
wish to fail. Instead, we produce a mock [.mli] file that wish to fail. Instead, we produce a mock [.mli] file that
is an approximation of the real [.mli] file. *) is an approximation of the real [.mli] file. When we are
"The indexed type of nonterminal symbols (mock!).", not in [--(raw)-depend] mode, though, this is a problem.
[] We display an error message and stop. *)
match Settings.depend with
| Settings.OMRaw
| Settings.OMPostprocess ->
"The indexed type of nonterminal symbols (mock!).",
[]
| Settings.OMNone ->
Error.error [] (Printf.sprintf "\
the type of the nonterminal symbol %s is unknown.\n\
When --inspection is set, the type of every nonterminal symbol must be known.\n\
Please use --infer or specify the type of every symbol via %%type declarations."
nt
)
in in
[ [
IIComment comment; IIComment comment;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment