let print ppf (name, position, ctx, exn) =
let name = if name = "" then !default else name in
let pp x =
fprintf ppf "@?@[<2>While %s %S in a position of %S:" x
name position in
let () =
match ctx with
| Finding ->
(pp "finding quotation";
if !expanders_table = []
then
fprintf ppf
"@ There is no quotation expander available."
else
(fprintf ppf
"@ @[<hv2>Available quotation expanders are:@\n";
List.iter
(fun ((s, t), _) ->
fprintf ppf
"@[<2>%s@ (in@ a@ position@ of %a)@]@ " s
Exp_key.print_tag t)
!expanders_table;
fprintf ppf "@]"))
| Expanding -> pp "expanding quotation"
| Locating -> pp "parsing"
| ParsingResult (loc, str) ->
let () = pp "parsing result of quotation"
in
(match !dump_file with
| Some dump_file ->
let () = fprintf ppf " dumping result...\n"
in
(try
let oc = open_out_bin dump_file
in
(output_string oc str;
output_string oc "\n";
flush oc;
close_out oc;
fprintf ppf "%a:" Loc.print
(Loc.set_file_name dump_file loc))
with
| _ ->
fprintf ppf
"Error while dumping result in file %S; dump aborted"
dump_file)
| None ->
fprintf ppf
"\n(consider setting variable Quotation.dump_file, or using the -QD option)")
in fprintf ppf "@\n%a@]@." ErrorHandler.print exn