[m-rev.] Re: [m-dev.] Commas considered optional
Fergus Henderson
fjh at cs.mu.OZ.AU
Thu Nov 29 21:05:24 AEDT 2001
On 29-Nov-2001, Ralph Becket <rafe at cs.mu.OZ.AU> wrote:
> A common topic for debate is how to improve the syntax of Mercury.
> Possibly for the first time ever in the history of such discussions, we
> suggest taking something out: the commas.
>
> We've just conducted an experiment on the parser making the use of
> commas optional, interpreting simple juxtaposition as indicating an
> implicit intervening comma. We've used this change to successfully
> compile some test programs (including non-trivial programs such as
> samples/calculator.m) written without commas.
FWIW, here's the diff. This passes bootcheck.
Estimated hours taken: 1
library/parser.m:
Treat term juxtaposition as equivalent to ",".
Workspace: /home/earth/fjh/ws-earth4/mercury
Index: library/parser.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/parser.m,v
retrieving revision 1.38
diff -u -d -r1.38 parser.m
--- library/parser.m 8 Nov 2001 15:30:38 -0000 1.38
+++ library/parser.m 29 Nov 2001 04:15:03 -0000
@@ -480,6 +480,31 @@
TermContext) },
parser__parse_rest(MaxPriority, IsArg, OpPriority, OpTerm, Term)
;
+ % juxtaposition -- treat like ","
+ { IsArg = no },
+ { Op = "," },
+ parser__get_ops_table(OpTable),
+ { ops__lookup_infix_op(OpTable, Op,
+ OpPriority, LeftAssoc, RightAssoc) },
+ { OpPriority =< MaxPriority },
+ { parser__check_priority(LeftAssoc, OpPriority, LeftPriority) },
+ { parser__adjust_priority(RightAssoc, OpPriority,
+ RightPriority) },
+ parser__parse_term_2(RightPriority, IsArg, RightTerm0),
+ { RightTerm0 = ok(RightTerm) }
+ ->
+ { LeftTerm = term__functor(_, _, LeftContext) ->
+ TermContext = LeftContext
+ ; RightTerm = term__functor(_, _, RightContext) ->
+ TermContext = RightContext
+ ;
+ term__context_init(TermContext)
+ },
+ { OpTerm = term__functor(term__atom(Op),
+ [LeftTerm, RightTerm], TermContext) },
+ parser__parse_rest(MaxPriority, IsArg, OpPriority,
+ OpTerm, Term)
+ ;
{ Term = ok(LeftTerm) }
).
@@ -705,6 +730,15 @@
{ List = ok(term__functor(term__atom("[|]"), [Arg, Tail],
TermContext)) }
;
+ % check for arguments juxtaposed without any intervening
+ % comma
+ parser__unget_token(Token, Context),
+ parser__parse_list(Tail0),
+ { Tail0 = ok(Tail) }
+ ->
+ { List = ok(term__functor(term__atom("[|]"),
+ [Arg, Tail], TermContext)) }
+ ;
parser__unexpected_tok(Token, Context,
"expected comma, `|', `]', or operator", List)
)
@@ -736,6 +770,14 @@
)
; { Token = close } ->
{ List = ok([Arg]) }
+ ;
+ % check for arguments juxtaposed without any intervening
+ % comma
+ parser__unget_token(Token, Context),
+ parser__parse_args(Tail0),
+ { Tail0 = ok(Tail) }
+ ->
+ { List = ok([Arg|Tail]) }
;
parser__unexpected_tok(Token, Context,
"expected `,', `)', or operator", List)
--
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