[m-rev.] diff: fix more issues with character escapes
Julien Fischer
jfischer at opturion.com
Fri Jun 15 14:06:19 AEST 2018
Fix more issues with character escapes.
Update a out-of-date link in some comments.
runtime/mercury_trace_base.c:
Handle missing character escapes.
Add an XXX; the comment here says that MR_trace_write_quoted_atom
is supposed to be equivalent to term_io.quote_atom but it is currently
not.
library/term_io.m:
Update comments about keeping code in this modules in sync with some
that was *previously* in compiler/mercury_to_mercury.
Julien.
diff --git a/library/term_io.m b/library/term_io.m
index f9fd75c..eeaef88 100644
--- a/library/term_io.m
+++ b/library/term_io.m
@@ -728,7 +728,7 @@ write_escaped_char(Char, !IO) :-
write_escaped_char(Stream, Char, !State) :-
% Note: the code of add_escaped_char and write_escaped_char
% should be kept in sync. The code of both is similar to code in
- % compiler/mercury_to_mercury.m; any changes here may require
+ % compiler/parse_tree_out_pragma.m; any changes here may require
% similar changes there.
( if mercury_escape_special_char(Char, QuoteChar) then
stream.put(Stream, ('\\'), !State),
@@ -773,8 +773,12 @@ string_is_escaped_char(Char::out, String::in) :-
% Succeed if Char is a character which is allowed in Mercury string
% and character literals.
%
- % Note: the code here is similar to code in compiler/mercury_to_mercury.m;
- % any changes here may require similar changes there.
+ % Note: the code here is similar to code in the following spots:
+ %
+ % - compiler/parse_tree_out_pragma.m.
+ % - runtime/mercury_trace_base.c
+ %
+ % Any changes here may require similar changes there.
%
:- pred is_mercury_source_char(char::in) is semidet.
@@ -786,7 +790,7 @@ is_mercury_source_char(Char) :-
%---------------------------------------------------------------------------%
-% Note: the code here is similar to code in compiler/mercury_to_mercury.m;
+% Note: the code here is similar to code in compiler/parse_tree_out_pragma.m;
% any changes here may require similar changes there.
quote_string(S, !IO) :-
@@ -817,7 +821,7 @@ escaped_string(String) =
add_escaped_char(Char, Strings0) = Strings :-
% Note: the code of add_escaped_char and write_escaped_char
% should be kept in sync. The code of both is similar to code in
- % compiler/mercury_to_mercury.m; any changes here may require
+ % compiler/parse_tree_out_pragma.m; any changes here may require
% similar changes there.
( if mercury_escape_special_char(Char, QuoteChar) then
Strings = [from_char_list(['\\', QuoteChar]) | Strings0]
diff --git a/runtime/mercury_trace_base.c b/runtime/mercury_trace_base.c
index 454574b..cbedf30 100644
--- a/runtime/mercury_trace_base.c
+++ b/runtime/mercury_trace_base.c
@@ -613,9 +613,12 @@ MR_trace_name_count_port_ensure_init()
}
}
-// The output of this is supposed to be equivalent to term_io__quote_atom
+// The output of this is supposed to be equivalent to term_io.quote_atom
// except that it always uses quotes, even if not strictly necessary.
-
+//
+// XXX term_io does *not* escape codepoints >= 0x80 whereas this always
+// does - juliensf.
+//
static void
MR_trace_write_quoted_atom(FILE *fp, const char *atom)
{
@@ -642,11 +645,23 @@ MR_trace_write_quoted_atom(FILE *fp, const char *atom)
case '\b':
fputs("\\b", fp);
break;
+ case '\a':
+ fputs("\\a", fp);
+ break;
+ case '\r':
+ fputs("\\r", fp);
+ break;
+ case '\f':
+ fputs("\\f", fp);
+ break;
+ case '\v':
+ fputs("\\v", fp);
+ break;
default:
- // This assumes isalnum is the same as char__isalnum.
+ // This assumes isalnum is the same as char.isalnum.
// The line noise is the equivalent of
// is_mercury_punctuation_char in library/term_io.m
- // and compiler/mercury_to_mercury.m; any changes here
+ // and compiler/parse_tree_out_pragma.m; any changes here
// may require similar changes there.
if (MR_isalnum(*c) ||
@@ -688,6 +703,18 @@ MR_trace_write_string(FILE *fp, const char *atom)
case '\b':
fputs("\\b", fp);
break;
+ case '\a':
+ fputs("\\a", fp);
+ break;
+ case '\r':
+ fputs("\\b", fp);
+ break;
+ case '\f':
+ fputs("\\f", fp);
+ break;
+ case '\v':
+ fputs("\\v", fp);
+ break;
default:
fputc(*c, fp);
break;
More information about the reviews
mailing list