diff: check syntax of `some' goals
Fergus Henderson
fjh at cs.mu.OZ.AU
Fri Oct 30 01:52:05 AEDT 1998
Estimated hours taken: 0.5
Report an error if the first argument of a `some' goal
is not a list of variables.
compiler/prog_io.m:
compiler/prog_io_util.m:
Move `parse_list_of_vars' from prog_io.m to prog_io_util.m.
compiler/prog_io_goal.m:
Check to make sure that the first argument to a some
goal is a list of variables. (If not, we don't report
an error here -- the error will be reported by typecheck.m.)
compiler/typecheck.m:
Report an proper error message if there is a call to an
undefined predicate `some/2'.
Also add `some/2' and `all/2' to the list of language builtins
for which we report a special error message if they occur as
undefined function symbols.
Index: compiler/prog_io.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/prog_io.m,v
retrieving revision 1.176
diff -u -r1.176 prog_io.m
--- prog_io.m 1998/10/29 08:53:06 1.176
+++ prog_io.m 1998/10/29 14:23:27
@@ -1044,14 +1044,6 @@
quantifier(univ, TVarsList), Decl) :-
parse_list_of_vars(TVars, TVarsList).
-:- pred parse_list_of_vars(term, list(var)).
-:- mode parse_list_of_vars(in, out) is semidet.
-
-parse_list_of_vars(term__functor(term__atom("[]"), [], _), []).
-parse_list_of_vars(term__functor(term__atom("."), [Head, Tail], _), [V|Vs]) :-
- Head = term__variable(V),
- parse_list_of_vars(Tail, Vs).
-
:- pred check_no_attributes(maybe1(item), decl_attrs, maybe1(item)).
:- mode check_no_attributes(in, in, out) is det.
Index: compiler/prog_io_goal.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/prog_io_goal.m,v
retrieving revision 1.12
diff -u -r1.12 prog_io_goal.m
--- prog_io_goal.m 1998/06/09 02:14:28 1.12
+++ prog_io_goal.m 1998/10/29 14:35:58
@@ -193,7 +193,7 @@
parse_goal(B0, V1, B, V).
parse_goal_2("some", [Vars0, A0], V0, some(Vars, A), V):-
- term__vars(Vars0, Vars),
+ parse_list_of_vars(Vars0, Vars),
parse_goal(A0, V0, A, V).
% The following is a temporary hack to handle `is' in
@@ -227,9 +227,10 @@
parse_some_vars_goal(A0, VarSet0, Vars, A, VarSet) :-
(
- A0 = term__functor(term__atom("some"), [Vars0, A1], _Context)
+ A0 = term__functor(term__atom("some"), [Vars0, A1], _Context),
+ parse_list_of_vars(Vars0, Vars1)
->
- term__vars(Vars0, Vars),
+ Vars = Vars1,
parse_goal(A1, VarSet0, A, VarSet)
;
Vars = [],
Index: compiler/prog_io_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/prog_io_util.m,v
retrieving revision 1.10
diff -u -r1.10 prog_io_util.m
--- prog_io_util.m 1998/03/27 18:52:33 1.10
+++ prog_io_util.m 1998/10/29 14:25:33
@@ -42,6 +42,14 @@
:- pred add_context(maybe1(item), term__context, maybe_item_and_context).
:- mode add_context(in, in, out) is det.
+%
+% Various predicates to parse small bits of syntax.
+% These predicates simply fail if they encounter a syntax error.
+%
+
+:- pred parse_list_of_vars(term, list(var)).
+:- mode parse_list_of_vars(in, out) is semidet.
+
:- pred convert_mode_list(list(term), list(mode)).
:- mode convert_mode_list(in, out) is semidet.
@@ -51,9 +59,6 @@
:- pred convert_inst_list(list(term), list(inst)).
:- mode convert_inst_list(in, out) is semidet.
- % Parse an inst.
- % Fails on syntax errors.
- %
:- pred convert_inst(term, inst).
:- mode convert_inst(in, out) is semidet.
@@ -101,6 +106,11 @@
add_context(error(M, T), _, error(M, T)).
add_context(ok(Item), Context, ok(Item, Context)).
+
+parse_list_of_vars(term__functor(term__atom("[]"), [], _), []).
+parse_list_of_vars(term__functor(term__atom("."), [Head, Tail], _), [V|Vs]) :-
+ Head = term__variable(V),
+ parse_list_of_vars(Tail, Vs).
convert_mode_list([], []).
convert_mode_list([H0|T0], [H|T]) :-
Index: compiler/typecheck.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/typecheck.m,v
retrieving revision 1.254
diff -u -r1.254 typecheck.m
--- typecheck.m 1998/10/29 09:20:00 1.254
+++ typecheck.m 1998/10/29 14:34:02
@@ -4706,6 +4706,14 @@
[]
)
;
+ { PredName = unqualified("some"), Arity = 2 }
+ ->
+ io__write_string(
+ " syntax error in existential quantification: first\n"),
+ prog_out__write_context(Context),
+ io__write_string(
+ " argument of `some' should be a list of variables.\n")
+ ;
io__write_string(" error: undefined predicate `"),
hlds_out__write_pred_call_id(PredCallId),
io__write_string("'"),
@@ -4977,6 +4985,8 @@
language_builtin("call", _).
language_builtin("impure", 1).
language_builtin("semipure", 1).
+language_builtin("all", 2).
+language_builtin("some", 2).
:- pred write_call_context(term__context, pred_call_id, int, unify_context,
io__state, io__state).
--
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