[m-dev.] diff: fix for bootstrapping problems (2)
Fergus Henderson
fjh at cs.mu.oz.au
Thu May 1 19:55:46 AEST 1997
Zoltan Somogyi, you wrote:
>
> > +:- pred term_io__write_quoted_string(string, io__state, io__state).
> > +:- mode term_io__write_quoted_string(in, di, uo) is det.
> > + % Given a string S, write S, with characters
> > + % escaped if necessary, to stdout.
> > + % The string is not enclosed in quotes.
>
> This seems error prone. Surely a better name would be write_escaped_string?
library/term_io.m:
compiler/mercury_to_mercury.m:
Fix some misleading predicate names:
Rename term_io__quote_single_char as term_io__write_escaped_char and
rename term_io__write_quoted_string as term_io__write_escaped_string.
For backwards compatibility I didn't actually remove
term_io__quote_single_char, I just declared it `pragma obsolete'
and changed the code to forward to term_io__write_escaped_char.
Index: term_io.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/library/term_io.m,v
retrieving revision 1.44
diff -u -r1.44 term_io.m
--- term_io.m 1997/05/01 09:09:50 1.44
+++ term_io.m 1997/05/01 09:48:33
@@ -76,17 +76,23 @@
% Given a character C, write C in single-quotes,
% escaped if necessary, to stdout.
-:- pred term_io__quote_single_char(character, io__state, io__state).
-:- mode term_io__quote_single_char(in, di, uo) is det.
+:- pred term_io__write_escaped_char(character, io__state, io__state).
+:- mode term_io__write_escaped_char(in, di, uo) is det.
% Given a character C, write C, escaped if necessary, to stdout.
% The character is not enclosed in quotes.
-:- pred term_io__write_quoted_string(string, io__state, io__state).
-:- mode term_io__write_quoted_string(in, di, uo) is det.
+:- pred term_io__write_escaped_string(string, io__state, io__state).
+:- mode term_io__write_escaped_string(in, di, uo) is det.
% Given a string S, write S, with characters
% escaped if necessary, to stdout.
% The string is not enclosed in quotes.
+ % `term_io__quote_single_char' is the old (misleading) name for
+ % `term_io__write_escaped_char'. Use the latter instead.
+:- pragma obsolete(term_io__quote_single_char/3).
+:- pred term_io__quote_single_char(character, io__state, io__state).
+:- mode term_io__quote_single_char(in, di, uo) is det.
+
%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%
@@ -356,7 +362,7 @@
term_io__quote_char(C) -->
io__write_char(''''),
- term_io__quote_single_char(C),
+ term_io__write_escaped_char(C),
io__write_char('''').
term_io__quote_atom(S) -->
@@ -392,25 +398,28 @@
;
% anything else must be output as a quoted token (6.4.2)
io__write_char(''''),
- term_io__write_quoted_string(S),
+ term_io__write_escaped_string(S),
io__write_char('''')
).
term_io__quote_string(S) -->
io__write_char('"'),
- term_io__write_quoted_string(S),
+ term_io__write_escaped_string(S),
io__write_char('"').
-term_io__write_quoted_string(S0) -->
+term_io__write_escaped_string(S0) -->
( { string__first_char(S0, Char, S1) } ->
- term_io__quote_single_char(Char),
- term_io__write_quoted_string(S1)
+ term_io__write_escaped_char(Char),
+ term_io__write_escaped_string(S1)
;
[]
).
term_io__quote_single_char(Char) -->
- ( { mercury_quote_special_char(Char, QuoteChar) } ->
+ term_io__write_escaped_char(Char).
+
+term_io__write_escaped_char(Char) -->
+ ( { mercury_escape_special_char(Char, QuoteChar) } ->
io__write_char('\\'),
io__write_char(QuoteChar)
; { is_mercury_source_char(Char) } ->
@@ -495,15 +504,20 @@
%-----------------------------------------------------------------------------%
-:- pred mercury_quote_special_char(character, character).
-:- mode mercury_quote_special_char(in, out) is semidet.
-
-mercury_quote_special_char('''', '''').
-mercury_quote_special_char('"', '"').
-mercury_quote_special_char('\\', '\\').
-mercury_quote_special_char('\n', 'n').
-mercury_quote_special_char('\t', 't').
-mercury_quote_special_char('\b', 'b').
+ % mercury_escape_special_char(Char, EscapeChar)
+ % is true iff Char is character for which there is a special
+ % backslash-escape character EscapeChar that can be used
+ % after a backslash in string literals or atoms to represent Char.
+
+:- pred mercury_escape_special_char(character, character).
+:- mode mercury_escape_special_char(in, out) is semidet.
+
+mercury_escape_special_char('''', '''').
+mercury_escape_special_char('"', '"').
+mercury_escape_special_char('\\', '\\').
+mercury_escape_special_char('\n', 'n').
+mercury_escape_special_char('\t', 't').
+mercury_escape_special_char('\b', 'b').
%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%
Index: mercury_to_mercury.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/mercury_to_mercury.m,v
retrieving revision 1.102
diff -u -r1.102 mercury_to_mercury.m
--- mercury_to_mercury.m 1997/05/01 09:10:21 1.102
+++ mercury_to_mercury.m 1997/05/01 09:39:21
@@ -1182,7 +1182,7 @@
\+ lexer__graphic_token_char(Char)) }
->
io__write_string("'"),
- term_io__write_quoted_string(Name),
+ term_io__write_escaped_string(Name),
io__write_string("'")
;
term_io__quote_atom(Name)
--
Fergus Henderson <fjh at cs.mu.oz.au> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3 | -- the last words of T. S. Garp.
More information about the developers
mailing list