diff: fix for bootstrapping problems (2)
Fergus Henderson
fjh at hydra.cs.mu.oz.au
Thu May 1 19:07:45 AEST 1997
Fix some more bugs that stopped the compiler from bootstrapping.
(This time all the problems are fixed; it really does bootstrap now.)
library/term_io.m:
library/io.m:
Fix a bug in term_io__quote_atom: if comma is used as an atom,
it needs to be quoted -- only when it is used as an infix operator
should it be unquoted. Also, don't bother to quote '{}'.
library/term_io.m:
Export term_io__write_quoted_string, for use by
compiler/mercury_to_mercury.m.
compiler/mercury_to_mercury.m:
Use term_io__write_quoted_string rather than io__write_string
in mercury_output_symname, since we need to escape backslashes.
cvs diff: Diffing .
Index: io.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/library/io.m,v
retrieving revision 1.118
diff -u -r1.118 io.m
--- io.m 1997/04/30 10:37:48 1.118
+++ io.m 1997/05/01 08:21:40
@@ -1342,9 +1342,13 @@
maybe_write_char('(', Priority, OpPriority),
{ adjust_priority(OpPriority, LeftAssoc, LeftPriority) },
io__write_univ(Arg1, LeftPriority),
- io__write_char(' '),
- term_io__quote_atom(Functor),
- io__write_char(' '),
+ ( { Functor = "," } ->
+ io__write_string(", ")
+ ;
+ io__write_char(' '),
+ term_io__quote_atom(Functor),
+ io__write_char(' ')
+ ),
{ adjust_priority(OpPriority, RightAssoc, RightPriority) },
io__write_univ(Arg2, RightPriority),
maybe_write_char(')', Priority, OpPriority)
Index: term_io.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/library/term_io.m,v
retrieving revision 1.43
diff -u -r1.43 term_io.m
--- term_io.m 1997/05/01 08:08:50 1.43
+++ term_io.m 1997/05/01 08:18:26
@@ -1,5 +1,5 @@
%---------------------------------------------------------------------------%
-% Copyright (C) 1995 University of Melbourne.
+% Copyright (C) 1994-1997 University of Melbourne.
% This file may only be copied under the terms of the GNU Library General
% Public License - see the file COPYING.LIB in the Mercury distribution.
%---------------------------------------------------------------------------%
@@ -81,6 +81,12 @@
% 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.
+ % Given a string S, write S, with characters
+ % escaped if necessary, to stdout.
+ % The string is not enclosed in quotes.
+
%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%
@@ -223,9 +229,13 @@
{ adjust_priority(OpPriority, LeftAssoc, LeftPriority) },
term_io__write_term_3(Arg1, LeftPriority,
VarSet0, N0, VarSet1, N1),
- io__write_char(' '),
- term_io__write_constant(Functor),
- io__write_char(' '),
+ ( { OpName = "," } ->
+ io__write_string(", ")
+ ;
+ io__write_char(' '),
+ term_io__write_constant(Functor),
+ io__write_char(' ')
+ ),
{ adjust_priority(OpPriority, RightAssoc, RightPriority) },
term_io__write_term_3(Arg2, RightPriority,
VarSet1, N1, VarSet, N),
@@ -351,28 +361,36 @@
term_io__quote_atom(S) -->
(
- % I didn't make these rules up: see ISO Prolog 6.4.2
+ % I didn't make these rules up: see ISO Prolog 6.3.1.3
+ % and 6.4.2.
(
+ % letter digit token (6.4.2)
{ string__first_char(S, FirstChar, Rest) },
{ char__is_lower(FirstChar) },
{ string__is_alnum_or_underscore(Rest) }
;
+ % semicolon token (6.4.2)
{ S = ";" }
;
+ % cut token (6.4.2)
{ S = "!" }
;
- { S = "," }
- ;
- { S = "[]" }
- ;
+ % graphic token (6.4.2)
{ string__to_char_list(S, Chars) },
{ \+ ( list__member(Char, Chars),
\+ lexer__graphic_token_char(Char)) },
- { S \= "" }
+ { Chars \= [] }
+ ;
+ % 6.3.1.3: atom = open list, close list ;
+ { S = "[]" }
+ ;
+ % 6.3.1.3: atom = open curly, close curly ;
+ { S = "{}" }
)
->
io__write_string(S)
;
+ % anything else must be output as a quoted token (6.4.2)
io__write_char(''''),
term_io__write_quoted_string(S),
io__write_char('''')
@@ -382,9 +400,6 @@
io__write_char('"'),
term_io__write_quoted_string(S),
io__write_char('"').
-
-:- pred term_io__write_quoted_string(string, io__state, io__state).
-:- mode term_io__write_quoted_string(in, di, uo) is det.
term_io__write_quoted_string(S0) -->
( { string__first_char(S0, Char, S1) } ->
Index: mercury_to_mercury.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/mercury_to_mercury.m,v
retrieving revision 1.101
diff -u -r1.101 mercury_to_mercury.m
--- mercury_to_mercury.m 1997/05/01 02:32:27 1.101
+++ mercury_to_mercury.m 1997/05/01 07:35:14
@@ -1159,27 +1159,33 @@
( { Name = qualified(ModuleName, PredName) },
mercury_output_bracketed_constant(term__atom(ModuleName)),
io__write_char(':'),
- %
- % If the symname is composed of only graphic token chars,
- % then term_io__quote_atom will not quote it; but since
- % ':' is a graphic token char, it needs to be quoted,
- % otherwise the ':' would be considered part of the
- % symbol name (e.g. "int:<" tokenizes as ["int", ":<"].)
- %
- (
- { string__to_char_list(PredName, Chars) },
- { \+ ( list__member(Char, Chars),
- \+ lexer__graphic_token_char(Char)) }
- ->
- io__write_string("'"),
- io__write_string(PredName),
- io__write_string("'")
- ;
- term_io__quote_atom(PredName)
- )
+ mercury_quote_qualified_atom(PredName)
;
{ Name = unqualified(PredName) },
term_io__quote_atom(PredName)
+ ).
+
+:- pred mercury_quote_qualified_atom(string, io__state, io__state).
+:- mode mercury_quote_qualified_atom(in, di, uo) is det.
+
+mercury_quote_qualified_atom(Name) -->
+ %
+ % If the symname is composed of only graphic token chars,
+ % then term_io__quote_atom will not quote it; but since
+ % ':' is a graphic token char, it needs to be quoted,
+ % otherwise the ':' would be considered part of the
+ % symbol name (e.g. "int:<" tokenizes as ["int", ":<"].)
+ %
+ (
+ { string__to_char_list(Name, Chars) },
+ { \+ ( list__member(Char, Chars),
+ \+ lexer__graphic_token_char(Char)) }
+ ->
+ io__write_string("'"),
+ term_io__write_quoted_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