aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBernhard Schommer <bschommer@users.noreply.github.com>2015-11-05 13:02:47 +0100
committerBernhard Schommer <bschommer@users.noreply.github.com>2015-11-05 13:02:47 +0100
commite5aeeb137cfd95289ec9388318f65df6f5b08db6 (patch)
treeb6e7f44f5ae1fb22b23661e0f25b3e9bf08ae8c2
parentcbff6d5b0f84090e2ff7f74bfb6eb7f3e3a29ef9 (diff)
parent2ca1282f84c5da41328b1251ac7bbcfa417b9be6 (diff)
downloadcompcert-kvx-e5aeeb137cfd95289ec9388318f65df6f5b08db6.tar.gz
compcert-kvx-e5aeeb137cfd95289ec9388318f65df6f5b08db6.zip
Merge pull request #67 from fpottier/compress
When printing a fragment of source text as part of an error message, …
-rw-r--r--cparser/ErrorReports.ml10
1 files changed, 9 insertions, 1 deletions
diff --git a/cparser/ErrorReports.ml b/cparser/ErrorReports.ml
index 4bbf3ded..a8976e42 100644
--- a/cparser/ErrorReports.ml
+++ b/cparser/ErrorReports.ml
@@ -92,6 +92,14 @@ let extract text (pos1, pos2) : string =
(* -------------------------------------------------------------------------- *)
+(* [compress text] replaces every run of at least one whitespace character
+ with exactly one space character. *)
+
+let compress text =
+ Str.global_replace (Str.regexp "[ \t\n\r]+") " " text
+
+(* -------------------------------------------------------------------------- *)
+
(* [sanitize text] eliminates any special characters from the text [text].
They are (arbitrarily) replaced with a single dot character. *)
@@ -182,7 +190,7 @@ let range text (e : element) : string =
(* Get the underlying source text fragment. *)
let fragment = extract text (pos1, pos2) in
(* Sanitize it and limit its length. Enclose it in single quotes. *)
- "'" ^ shorten width (sanitize fragment) ^ "'"
+ "'" ^ shorten width (sanitize (compress fragment)) ^ "'"
(* -------------------------------------------------------------------------- *)