[m-dev.] Added module qualified backquoted operators to the syntax
Ralph Becket
rafe at cs.mu.OZ.AU
Wed Dec 24 13:04:52 AEDT 2003
Okay, I believe I've addressed your review comments: here's the relative
diff. (N.B. I also renamed infix_qualified_ops.* to
backquoted_qualified_ops.*).
diff -u doc/reference_manual.texi doc/reference_manual.texi
--- doc/reference_manual.texi 22 Dec 2003 05:31:25 -0000
+++ doc/reference_manual.texi 24 Dec 2003 01:26:12 -0000
@@ -367,9 +367,10 @@
is a valid tuple term.
An operator term is a term specified using operator notation, as in Prolog.
-Operators can also be formed by enclosing a variable or (possibly module
-qualified) name between grave accents (backquotes). Any variable or name may
-be used as an operator in this way. If @var{fun} is a variable or name,
+Operators can also be formed by enclosing a name, a module qualified name
+(@pxref{The module system}), or a variable between grave accents (backquotes).
+Any name or variable may be used as an operator in this way.
+If @var{fun} is a variable or name,
then a term of the form @code{@var{X} `@var{fun}` @var{Y}} is equivalent to
@code{@var{fun}(@var{X}, @var{Y})}. The operator is left associative
and binds more tightly than every operator other than @samp{^}
diff -u library/parser.m library/parser.m
--- library/parser.m 22 Dec 2003 05:30:04 -0000
+++ library/parser.m 24 Dec 2003 02:01:15 -0000
@@ -513,7 +513,7 @@
:- mode parse_backquoted_operator(out, out, out, in, out) is semidet.
parse_backquoted_operator(Qualifier, OpName, VariableTerm) -->
- parser__get_token(Token, _),
+ parser__get_token(Token, Context),
(
{ Token = variable(VariableOp) },
{ Qualifier = no },
@@ -523,38 +523,41 @@
;
{ Token = name(OpName0) },
{ VariableTerm = [] },
- parse_backquoted_operator_2(no, Qualifier, OpName0, OpName)
+ parser__get_term_context(Context, OpCtxt0),
+ parse_backquoted_operator_2(no, Qualifier,
+ OpCtxt0, OpName0, OpName)
).
:- pred parse_backquoted_operator_2(maybe(term(T)), maybe(term(T)),
- string, string,
+ term__context, string, string,
parser__state(Ops, T), parser__state(Ops, T)) <= op_table(Ops).
-:- mode parse_backquoted_operator_2(in, out, in, out, in, out) is semidet.
+:- mode parse_backquoted_operator_2(in, out, in, in, out, in, out) is semidet.
-parse_backquoted_operator_2(Qualifier0, Qualifier, OpName0, OpName) -->
+parse_backquoted_operator_2(Qualifier0, Qualifier, OpCtxt0, OpName0, OpName) -->
( if
- parser__get_token(name(ModuleSeparator), _),
+ parser__get_token(name(ModuleSeparator), SepContext),
{
ModuleSeparator = "."
;
ModuleSeparator = ":"
},
- parser__get_token(name(OpName1), Context),
+ parser__get_token(name(OpName1), NameContext),
{ OpName1 \= "`" }
then
- parser__get_term_context(Context, TermContext),
- { QTerm1 = term__functor(atom(OpName0), [], TermContext) },
+ parser__get_term_context(SepContext, SepCtxt),
+ parser__get_term_context(NameContext, OpCtxt1),
+ { QTerm1 = term__functor(atom(OpName0), [], OpCtxt0) },
{
Qualifier0 = no,
Qualifier1 = yes(QTerm1)
;
Qualifier0 = yes(QTerm0),
Qualifier1 = yes(functor(atom("."), [QTerm0, QTerm1],
- TermContext))
+ SepCtxt))
},
parse_backquoted_operator_2(Qualifier1, Qualifier,
- OpName1, OpName)
+ OpCtxt1, OpName1, OpName)
else
{ Qualifier = Qualifier0 },
{ OpName = OpName0 }
diff -u tests/hard_coded/Mmakefile tests/hard_coded/Mmakefile
--- tests/hard_coded/Mmakefile 22 Dec 2003 02:47:41 -0000
+++ tests/hard_coded/Mmakefile 24 Dec 2003 01:41:36 -0000
@@ -8,6 +8,7 @@
address_of_builtins \
agg \
any_free_unify \
+ backquoted_qualified_ops \
bidirectional \
brace \
builtin_inst_rename \
@@ -91,7 +92,6 @@
impossible_unify \
impure_foreign \
impure_prune \
- infix_qualified_ops \
integer_test \
intermod_c_code \
intermod_foreign_type \
reverted:
--- tests/hard_coded/infix_qualified_ops.exp 22 Dec 2003 02:47:56 -0000
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1 +0,0 @@
-2 + 2 = 4
reverted:
--- tests/hard_coded/infix_qualified_ops.m 22 Dec 2003 02:47:24 -0000
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,39 +0,0 @@
-%-----------------------------------------------------------------------------%
-% infix_qualified_ops.m
-% Ralph Becket <rafe at cs.mu.oz.au>
-% Mon Dec 22 13:45:14 EST 2003
-% vim: ft=mercury ts=4 sw=4 et wm=0 tw=0
-%
-% Tests that the parser recognises backquoted, module-qualified operator
-% names.
-%
-%-----------------------------------------------------------------------------%
-
-:- module infix_qualified_ops.
-
-:- interface.
-
-:- import_module io.
-
-
-
-:- pred main(io :: di, io :: uo) is det.
-
-%-----------------------------------------------------------------------------%
-%-----------------------------------------------------------------------------%
-
-:- implementation.
-
-:- import_module int, string, list.
-
-%-----------------------------------------------------------------------------%
-
-main(!IO) :-
- io.format("2 + 2 = %d\n", [i(2 `infix_qualified_ops.add` 2)]).
-
-:- func int `infix_qualified_ops.add` int = int.
-
-X `infix_qualified_ops.add` Y = X + Y.
-
-%-----------------------------------------------------------------------------%
-%-----------------------------------------------------------------------------%
only in patch2:
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ tests/hard_coded/backquoted_qualified_ops.m 24 Dec 2003 01:57:46 -0000
@@ -0,0 +1,76 @@
+%-----------------------------------------------------------------------------%
+% backquoted_qualified_ops.m
+% Ralph Becket <rafe at cs.mu.oz.au>
+% Mon Dec 22 13:45:14 EST 2003
+% vim: ft=mercury ts=4 sw=4 et wm=0 tw=0
+%
+% Tests that the parser recognises backquoted, module-qualified operator
+% names.
+%
+%-----------------------------------------------------------------------------%
+
+:- module backquoted_qualified_ops.
+
+:- interface.
+
+:- import_module io.
+
+
+
+:- pred main(io :: di, io :: uo) is det.
+
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
+
+:- implementation.
+
+:- import_module int, string, list.
+:- import_module backquoted_qualified_ops.a.
+:- import_module backquoted_qualified_ops.a.b.
+:- import_module backquoted_qualified_ops.a.b.c.
+
+%-----------------------------------------------------------------------------%
+
+ :- module a.
+ :- interface.
+ :- func int `add` int = int.
+
+ :- module b.
+ :- interface.
+ :- func int `mul` int = int.
+
+ :- module c.
+ :- interface.
+ :- func int `div` int = int.
+
+ :- end_module c.
+
+ :- end_module b.
+
+ :- end_module a.
+
+ :- module a.
+ :- implementation.
+ X `add` Y = X + Y.
+
+ :- module b.
+ :- implementation.
+ X `mul` Y = X * Y.
+
+ :- module c.
+ :- implementation.
+ X `div` Y = X / Y.
+ :- end_module c.
+
+ :- end_module b.
+
+ :- end_module a.
+
+%-----------------------------------------------------------------------------%
+
+main(!IO) :-
+ io.format("2 `a.add` 2 = %d\n2 `a.b.mul` 2 = %d\n2 `a.b.c.div` 2 = %d\n",
+ [i(2 `a.plus` 2), i(2 `a.b.mul` 2), i(2 `a.b.c.div` 2)]).
+
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
only in patch2:
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ tests/hard_coded/backquoted_qualified_ops.exp 24 Dec 2003 01:59:21 -0000
@@ -0,0 +1,3 @@
+2 `a.add` 2 = 4
+2 `a.b.mul` 2 = 4
+2 `a.b.c.div` 2 = 1
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to: mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions: mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------
More information about the developers
mailing list