[m-rev.] for review: tuple syntax fix
Fergus Henderson
fjh at cs.mu.OZ.AU
Fri Mar 8 08:44:42 AEDT 2002
I was unpleasantly surprised to find that `{(x,y)}' parses as '{}'/2
rather than as '{}'/1. If I explicitly write the parentheses, then
the compiler should not ignore them. Hence the following patch.
----------
Estimated hours taken: 1
Branches: main
library/parser.m:
Change the parsing for tuples to be similar to the parsing
for functor arguments, so that e.g. "{(x,y)}" parses as
"'{}'(','(x,y))" rather than as "'{}'(x,y)", and "{ x :- y }"
parses successfully as is, rather than needing to be rewritten as
"{ (x :- y) }".
Workspace: /home/ceres/fjh/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 7 Mar 2002 19:45:50 -0000
@@ -593,32 +593,41 @@
% it as "'{}'(1,2,3)". This makes the
% structure of tuple functors the same
% as other functors.
- parser__parse_term(SubTerm0),
- ( { SubTerm0 = ok(SubTerm) } ->
- { conjunction_to_list(SubTerm, ArgTerms) },
- ( parser__get_token(close_curly) ->
- { Term = ok(term__functor(term__atom("{}"),
- ArgTerms, TermContext)) }
- ;
- parser__unexpected("expecting `}' or operator",
- Term)
- )
- ;
- % propagate error upwards
- { Term = SubTerm0 }
- )
+ parser__parse_tuple_args(ArgTerms)
).
-:- pred parser__conjunction_to_list(term(T), list(term(T))).
-:- mode parser__conjunction_to_list(in, out) is det.
+:- pred parser__parse_tuple_args(parse(list(term(T))),
+ parser__state(Ops, T), parser__state(Ops, T)) <= op_table(Ops).
+:- mode parser__parse_tuple_args(out, in, out) is det.
-parser__conjunction_to_list(Term, ArgTerms) :-
- ( Term = term__functor(term__atom(","), [LeftTerm, RightTerm], _) ->
- parser__conjunction_to_list(RightTerm, ArgTerms0),
- ArgTerms = [LeftTerm | ArgTerms0]
+parser__parse_tuple_args(List) -->
+ parser__parse_arg(Arg0),
+ ( { Arg0 = ok(Arg) },
+ ( parser__get_token(Token, Context) ->
+ ( { Token = comma } ->
+ parser__parse_tuple_args(Tail0),
+ ( { Tail0 = ok(Tail) } ->
+ { List = ok([Arg|Tail]) }
+ ;
+ % propagate error upwards
+ { List = Tail0 }
+ )
+ ; { Token = close } ->
+ { List = ok([Arg]) }
+ ;
+ parser__unexpected_tok(Token, Context,
+ "expected `,', `}', or operator", List)
+ )
+ ;
+ parser__error("unexpected end-of-file in tuple argument list",
+ List)
+ )
;
- ArgTerms = [Term]
+ { Arg0 = error(Message, Tokens) },
+ % propagate error upwards
+ { List = error(Message, Tokens) }
).
+
:- pred parser__check_for_higher_order_term(parse(term(T)), token_context,
parse(term(T)), parser__state(Ops, T),
--
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