[m-rev.] Change compiler output to use `.' as module separator

Ralph Becket rafe at cs.mu.OZ.AU
Fri Jan 3 16:41:26 AEDT 2003


Fergus Henderson, Thursday, 19 December 2002:
> 
> I think that will do the wrong thing for terms such as '.'(1,2).
> Note that term_io is used for parsing Prolog code, not just Mercury code...

Okay, here's the fix:

Index: library/term_io.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/term_io.m,v
retrieving revision 1.65
diff -u -r1.65 term_io.m
--- library/term_io.m	30 May 2002 04:39:48 -0000	1.65
+++ library/term_io.m	2 Jan 2003 00:49:53 -0000
@@ -346,6 +346,19 @@
 				VarSet0, N0, VarSet1, N1),
 		( { OpName = "," } ->
 			io__write_string(", ")
+		; { OpName = "." } ->
+				% If the operator is '.'/2 then we must
+				% not put spaces around it (or at the
+				% very least, we should not put spaces
+				% afterwards which would make it appear
+				% as the end-of-term token.)  However,
+				% we do have to quote it if the right
+				% hand side can begin with a digit.
+				%
+			io__write_string(
+				if starts_with_digit(Arg2) then "'.'"
+							   else  "."
+			)
 		;
 			io__write_char(' '),
 			term_io__write_constant(Functor),
@@ -445,6 +458,27 @@
 		io__write_string(" | "),
 		term_io__write_term_2(Ops, Term, VarSet0, N0, VarSet, N)
 	).
+
+	% Succeeds iff outputting the given term would start with a digit.
+	% (This is a safe, conservative approximation and is used to decide
+	% whether or not to quote infix '.'/2.)
+	%
+:- pred starts_with_digit(term(T)).
+:- mode starts_with_digit(in     ) is semidet.
+
+starts_with_digit(functor(integer(_), _, _)).
+
+starts_with_digit(functor(float(_), _, _)).
+
+starts_with_digit(functor(atom(Op), Args, _)) :-
+	(
+		Args = [Arg, _],
+		ops__lookup_infix_op(ops__init_mercury_op_table, Op, _, _, _)
+	;
+		Args = [Arg],
+		ops__lookup_postfix_op(ops__init_mercury_op_table, Op, _, _)
+	),
+	starts_with_digit(Arg).
 
 %-----------------------------------------------------------------------------%
 
- Ralph
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list