Commit 30d7562a authored by POTTIER Francois's avatar POTTIER Francois

Fail less abruptly when a conflict cannot be explained.

parent ef0aa0e3
......@@ -335,6 +335,7 @@ let () =
if Settings.explain then begin
Lr1.conflicts (fun toks node ->
(* Construct a partial LR(1) automaton, looking for a conflict
in a state that corresponds to this node. Because Pager's
......@@ -468,6 +469,24 @@ let () =
flush out
with Lr1partial.Oops ->
(* Ha ha! We were unable to explain this conflict. This could happen
because the automaton was butchered by conflict resolution directives,
or because [--lalr] was enabled and we have unexplainable LALR conflicts.
Anyway, send the error message to the .conflicts file and continue. *)
let out = Lazy.force out in
Printf.fprintf out "\n\
** Conflict (unexplainable) in state %d.\n\
** Token%s involved: %s\n\
** Internal failure (Pager's theorem).\n\
** Please send your grammar to Menhir's developers.\n%!"
(Lr1.number node)
(if TerminalSet.cardinal toks > 1 then "s" else "")
(TerminalSet.print toks)
Time.tick "Explaining conflicts"
open Grammar
exception Oops
module Run (X : sig
(* A restricted set of tokens of interest. *)
......@@ -184,13 +186,7 @@ end) = struct
canonical automaton as well. Otherwise, Pager's construction
is incorrect. *)
Printf.fprintf stderr "** Internal failure (Pager's theorem).\n";
Printf.fprintf stderr "** Tokens of interest: %s\n" (TerminalSet.print X.tokens);
Printf.fprintf stderr "** Goal state: %d\n" (Lr1.number X.goal);
Printf.fprintf stderr "** Please send your grammar to Menhir's developers.\n%!";
exit 1
raise Oops
with Goal (node, tok) ->
node, tok
open Grammar
(* This exception is raised by [Run] if we fail to reach the goal state.
This is known to happen in a few pathological cases (e.g., when a
shift/reduce conflict is solved in favor of reduction, the only path
towards the goal state may disappear). So we report this situation
gracefully in the .conflicts file instead of failing abruptly. *)
exception Oops
module Run (X : sig
(* A restricted set of tokens of interest. *)
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