Commit c58bf1e1 authored by POTTIER Francois's avatar POTTIER Francois

Updated --interpret-error and --list-errors to produce the same format.

Introduced a ## marker for auto-generated comments.
parent d6065040
......@@ -10,8 +10,6 @@
collect performance data
correlate with star size and alphabet size, etc.
create separate graphs for 3 modes: --lalr, pager, --canonical
Improve --interpret-error by printing not just the state number
but also its description (items)
Could --interpret-error obey --trace?
In --list-errors and --interpret-error:
improve output by WARNING about any spurious reductions
......
......@@ -1135,22 +1135,6 @@ let data : (Nonterminal.t * W.word * Lr1.node) list ref =
let reachable =
ref Lr1.NodeSet.empty
(* [display] displays one data item. The format is that of a [.messages]
file, which the user can then edit to customize the error messages. *)
let display (nt, w, s') : unit =
(* Print the sentence, followed with a few comments, followed with a
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"
(Nonterminal.print false nt)
(W.print w)
(W.length w)
(Lr1.number s')
(Lr0.print "# " (Lr1.state s')) (* TEMPORARY [print] or [print_closure]? *)
Interpret.default_message
(* Perform the forward search. *)
let _, _ =
......@@ -1176,11 +1160,13 @@ let _, _ =
(* Sort and output the data. *)
let () =
let compare (nt1, w1, _) (nt2, w2, _) =
!data
|> List.fast_sort (fun (nt1, w1, _) (nt2, w2, _) ->
let c = Nonterminal.compare nt1 nt2 in
if c <> 0 then c else W.compare w2 w1
in
List.iter display (List.fast_sort compare !data)
)
|> List.map (fun (nt, w, s') -> (nt, W.elements w, s'))
|> List.iter Interpret.print_messages_item
(* ------------------------------------------------------------------------ *)
......
......@@ -29,12 +29,12 @@ type targeted_run = targeted_sentence list * message
(* --------------------------------------------------------------------------- *)
(* Debugging.
(* Display and debugging. *)
let print_sentence (nto, terminals) : string =
let b = Buffer.create 128 in
Option.iter (fun nt ->
Printf.bprintf b "%s: " (Nonterminal.print true nt)
Printf.bprintf b "%s: " (Nonterminal.print false nt)
) nto;
List.iter (fun t ->
Printf.bprintf b "%s " (Terminal.print t)
......@@ -42,14 +42,6 @@ let print_sentence (nto, terminals) : string =
Printf.bprintf b "\n";
Buffer.contents b
let print_sentence sentence : unit =
print_string (print_sentence sentence)
let print_located_sentence (_, sentence) : unit =
print_sentence sentence
*)
(* --------------------------------------------------------------------------- *)
(* [stream] turns a finite list of terminals into a stream of terminals. *)
......@@ -191,8 +183,35 @@ let interpret_error_aux poss ((_, terminals) as sentence) fail succeed =
fail "A syntax error occurs before the last token is reached."
| OUnexpectedAccept ->
fail "No syntax error occurs; in fact, this input is accepted."
| OK state ->
succeed state
| OK s' ->
succeed nt terminals s'
(* --------------------------------------------------------------------------- *)
(* 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. *)
let default_message =
"<YOUR SYNTAX ERROR MESSAGE HERE>\n"
(* [print_messages_item] displays one data item. The item is of the form [nt,
w, s'], which means that beginning at the start symbol [nt], the sentence
[w] ends in an error in state [s']. The display obeys the [.messages] file
format. *)
let print_messages_item (nt, w, s') : unit =
(* Print the sentence, followed with a few comments, followed with a
blank line, followed with a proposed error message, followed with
another blank line. *)
Printf.printf
"%s##\n## Ends in an error in state: %d.\n##\n%s\n%s\n"
(print_sentence (Some nt, w))
(Lr1.number s')
(* [Lr0.print] or [Lr0.print_closure] could be used here. The latter
could sometimes be helpful, but is usually intolerably verbose. *)
(Lr0.print "## " (Lr1.state s'))
default_message
(* --------------------------------------------------------------------------- *)
......@@ -201,14 +220,10 @@ let interpret_error_aux poss ((_, terminals) as sentence) fail succeed =
used by [--interpret-error]. *)
let fail msg =
Printf.printf "BAD\n# %s\n%!" msg;
exit 1
Error.error [] msg
let succeed s =
let s = Lr1.number s in
Printf.printf
"OK %d\n# This sentence ends with a syntax error in state %d.\n%!"
s s;
let succeed nt terminals s' =
print_messages_item (nt, terminals, s');
exit 0
let interpret_error sentence =
......@@ -231,7 +246,7 @@ let target_sentence : located_sentence -> targeted_sentence list =
fun (poss, sentence) ->
interpret_error_aux poss sentence
(fail poss)
(fun s -> [ (poss, sentence), s ])
(fun _nt _terminals s' -> [ (poss, sentence), s' ])
let target_run : run -> targeted_run =
fun (sentences, message) ->
......@@ -461,9 +476,6 @@ 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) ->
......
......@@ -8,3 +8,12 @@
val default_message: string
(* [print_messages_item] displays one data item. The item is of the form [nt,
w, s'], which means that beginning at the start symbol [nt], the sentence
[w] ends in an error in state [s']. The display obeys the [.messages] file
format. *)
open Grammar
val print_messages_item: Nonterminal.t * Terminal.t list * Lr1.node -> unit
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