summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Angeletti <octa@polychoron.fr>2017-08-10 13:03:22 +0200
committerMark Shinwell <mshinwell@gmail.com>2017-08-10 12:03:22 +0100
commitea4e0095330d18dd5af1983bb3a1e3a0d883baff (patch)
tree5024d68a9bfd2bdd02788d92cd2ad59f2e526ccd
parentc34fd899deb6071def0354c821f13371d69537a6 (diff)
downloadocaml-ea4e0095330d18dd5af1983bb3a1e3a0d883baff.tar.gz
GPR#1281: avoid "@." in location print functions (#1281)
-rw-r--r--Changes3
-rw-r--r--parsing/location.ml26
-rw-r--r--testsuite/tools/expect_test.ml2
3 files changed, 19 insertions, 12 deletions
diff --git a/Changes b/Changes
index 895ff08921..fc61b9226e 100644
--- a/Changes
+++ b/Changes
@@ -296,6 +296,9 @@ Working version
included by other header files
(Sébastien Hinderer)
+- GPR#1281: avoid formatter flushes inside exported printers in Location
+ (Florian Angeletti, review by Gabriel Scherer)
+
### Bug fixes
- MPR#248, GPR#1225: unique names for weak type variables
diff --git a/parsing/location.ml b/parsing/location.ml
index f505f77a54..7fd915ce5c 100644
--- a/parsing/location.ml
+++ b/parsing/location.ml
@@ -144,7 +144,7 @@ let highlight_dumb ppf lb loc =
end
done;
(* Print character location (useful for Emacs) *)
- Format.fprintf ppf "Characters %i-%i:@."
+ Format.fprintf ppf "@[<v>Characters %i-%i:@,"
loc.loc_start.pos_cnum loc.loc_end.pos_cnum;
(* Print the input, underlining the location *)
Format.pp_print_string ppf " ";
@@ -155,7 +155,7 @@ let highlight_dumb ppf lb loc =
| '\n' ->
if !line = !line_start && !line = !line_end then begin
(* loc is on one line: underline location *)
- Format.fprintf ppf "@. ";
+ Format.fprintf ppf "@, ";
for _i = !pos_at_bol to loc.loc_start.pos_cnum - 1 do
Format.pp_print_char ppf ' '
done;
@@ -164,7 +164,7 @@ let highlight_dumb ppf lb loc =
done
end;
if !line >= !line_start && !line <= !line_end then begin
- Format.fprintf ppf "@.";
+ Format.fprintf ppf "@,";
if pos < loc.loc_end.pos_cnum then Format.pp_print_string ppf " "
end;
incr line;
@@ -191,7 +191,8 @@ let highlight_dumb ppf lb loc =
else if !line > !line_start && !line < !line_end then
(* intermediate line of multiline loc: print whole line *)
Format.pp_print_char ppf c
- done
+ done;
+ Format.fprintf ppf "@]"
(* Highlight the location using one of the supported modes. *)
@@ -276,7 +277,7 @@ let default_printer ppf loc =
setup_colors ();
if loc.loc_start.pos_fname = "//toplevel//"
&& highlight_locations ppf [loc] then ()
- else fprintf ppf "@{<loc>%a@}%s@." print_loc loc msg_colon
+ else fprintf ppf "@{<loc>%a@}%s@," print_loc loc msg_colon
;;
let printer = ref default_printer
@@ -312,17 +313,19 @@ let default_warning_printer loc ppf w =
| `Inactive -> ()
| `Active { Warnings. number; message; is_error; sub_locs } ->
setup_colors ();
+ fprintf ppf "@[<v>";
print ppf loc;
if is_error
then
- fprintf ppf "%t (%s %d): %s@." print_error_prefix
+ fprintf ppf "%t (%s %d): %s@," print_error_prefix
(String.uncapitalize_ascii warning_prefix) number message
- else fprintf ppf "@{<warning>%s@} %d: %s@." warning_prefix number message;
+ else fprintf ppf "@{<warning>%s@} %d: %s@," warning_prefix number message;
List.iter
(fun (loc, msg) ->
- if loc <> none then fprintf ppf " %a %s@." print loc msg
+ if loc <> none then fprintf ppf " %a %s@," print loc msg
)
- sub_locs
+ sub_locs;
+ fprintf ppf "@]"
;;
let warning_printer = ref default_warning_printer ;;
@@ -417,8 +420,9 @@ let rec default_error_reporter ppf ({loc; msg; sub; if_highlight} as err) =
if highlighted then
Format.pp_print_string ppf if_highlight
else begin
- fprintf ppf "%a %s" print_error loc msg;
- List.iter (Format.fprintf ppf "@\n@[<2>%a@]" default_error_reporter) sub
+ fprintf ppf "@[<v>%a %s" print_error loc msg;
+ List.iter (Format.fprintf ppf "@,@[<2>%a@]" default_error_reporter) sub;
+ fprintf ppf "@]"
end
let error_reporter = ref default_error_reporter
diff --git a/testsuite/tools/expect_test.ml b/testsuite/tools/expect_test.ml
index d841dc27a2..42c3027ac8 100644
--- a/testsuite/tools/expect_test.ml
+++ b/testsuite/tools/expect_test.ml
@@ -136,7 +136,7 @@ module Compiler_messages = struct
Format.fprintf ppf "Line _";
if startchar >= 0 then
Format.fprintf ppf ", characters %d-%d" startchar endchar;
- Format.fprintf ppf ":@."
+ Format.fprintf ppf ":@,"
let capture ppf ~f =
Misc.protect_refs