[m-rev.] Change compiler output to use `.' as module separator
Fergus Henderson
fjh at cs.mu.OZ.AU
Tue Dec 24 14:56:58 AEDT 2002
On 24-Dec-2002, Ralph Becket <rafe at cs.mu.OZ.AU> wrote:
> Fergus Henderson, Thursday, 19 December 2002:
> > On 19-Dec-2002, Ralph Becket <rafe at cs.mu.OZ.AU> wrote:
> > > +++ library/term_io.m 5 Dec 2002 05:22:10 -0000
> > > @@ -346,6 +346,14 @@
> > > + ; { 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, since otherwise it will
> > > + % not be seen as an operator by the parser.)
> > > + %
> > > + io__write_string(".")
> >
> > 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...
>
> I agree. Also, it's not clear to me whether a file containing
> | 1.
> | 2.
> will be read as containing one term, '.'(1, 2), or two terms, 1 and 2.
It will be read as two terms. A token consisting of a period followed
by whitespace is treated as an end-of-term indicator. A token starting
with a period not followed by whitespace is treated as a graphic-token.
> Any thoughts?
The simplest thing is for term_io.m to just quote all dot operators,
i.e. output the three characters "'.'". So '.'(1,2)
would be output as "1'.'2" and list.append would be output as
"list'.'append". But that would lead to quite ugly output.
Nicer-looking output would be a little more work.
I guess it wouldn't be too hard to traverse the left-hand operand
to see whether it could expand to something ending in a number token,
and to traverse the right-hand operand to see whether it could
expand to something starting with a number token, and only quote the dot
operator if either of those is true.
e.g. (pseudo-code)
could_end_in_number(term__functor(term__integer(_), _, _)).
could_end_in_number(term__functor(term__float(_), _, _)).
could_end_in_number(term__functor(Op, [X], _)) :-
Op is a unary prefix operator,
could_end_in_number(X).
could_end_in_number(term__functor(Op, [X, Y], _)) :-
Op is an infix or binary prefix operator,
could_end_in_number(Y).
--
Fergus Henderson <fjh at cs.mu.oz.au> | "I have always known that the pursuit
The University of Melbourne | of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh> | -- the last words of T. S. Garp.
--------------------------------------------------------------------------
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