Commit 48ba456c authored by POTTIER Francois's avatar POTTIER Francois

Improved --compare-messages to also compare the messages (if non-default).

parent 9ac0d3bc
......@@ -1143,13 +1143,13 @@ let display (nt, w, s') : unit =
blank line, followed with a proposed error message, followed with
another blank line. *)
Printf.printf
"%s: %s\n# Length: %d\n# Leads to an error in state: %d.\n%s\n%s\n\n"
"%s: %s\n# Length: %d\n# Leads to an error in state: %d.\n%s\n%s\n"
(Nonterminal.print false nt)
(W.print w)
(W.length w)
(Lr1.number s')
(Lr0.print_closure "# " (Lr1.state s'))
"Syntax error."
Interpret.default_message
(* Perform the forward search. *)
......
......@@ -3,8 +3,8 @@
an error, a minimal path (starting in some initial state) that actually
triggers this error. *)
(* The result of this analysis is written to the standard output channel.
No result is returned. *)
(* The result of this analysis is a [.messages] file. It is written to the
standard output channel. No result is returned. *)
module Run (X : sig
(* If [verbose] is set, produce various messages on [stderr]. *)
......
......@@ -461,6 +461,9 @@ let () =
state that appears on the left-hand side appears on the right-hand side as
well. *)
let default_message =
"<YOUR SYNTAX ERROR MESSAGE HERE>\n"
let () =
Settings.compare_errors |> Option.iter (fun (filename1, filename2) ->
......@@ -484,15 +487,23 @@ let () =
(* Check that [table1] is a subset of [table2], that is, for every state
[s] in the domain of [table1], [s] is mapped by [table1] and [table2]
to the same error message. *)
to the same error message. As an exception, if the message found in
[table1] is the default message, then no comparison takes place. This
allows using [--list-errors] and [--compare-errors] in conjunction to
ensure that a [.messages] file is complete, without seeing warnings
about different messages. *)
table1 |> Lr1.NodeMap.iter (fun s ((poss1, _), message1) ->
let (poss2, _), message2 = Lr1.NodeMap.find s table2 in
if message1 <> message2 then
Error.warning (poss1 @ poss2) (Printf.sprintf
"These sentences lead to an error in state %d.\n\
The corresponding messages in \"%s\" and \"%s\" differ."
(Lr1.number s) filename1 filename2
)
if message1 <> default_message then
try
let (poss2, _), message2 = Lr1.NodeMap.find s table2 in
if message1 <> message2 then
Error.warning (poss1 @ poss2) (Printf.sprintf
"These sentences lead to an error in state %d.\n\
The corresponding messages in \"%s\" and \"%s\" differ."
(Lr1.number s) filename1 filename2
)
with Not_found ->
()
);
if Error.errors() then exit 1;
......
(* This module is in charge of handling the [--interpret] option,
if it is present. It offers no functionality. *)
(* This module is in charge of handling several command line options, namely
[--interpret], [--interpret-error], [--compile-errors], [--compare-errors].
If any of these options is present, the execution of Menhir stops here. *)
(* This default error message is produced by [--list-errors] when it creates a
[.messages] file, and is recognized by [--compare-errors] when it compares
two such files. *)
val default_message: string
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