[m-rev.] diff: remove unnecessary import_module in moose generated code
Fergus Henderson
fjh at cs.mu.OZ.AU
Tue Feb 24 11:39:41 AEDT 2004
On 23-Feb-2004, Peter Ross <pro at missioncriticalit.com> wrote:
> Estimated hours taken: 0.1
> Branches: main
>
> extras/moose/moose.m:
> Remove an unnecessary import_module in the generated code.
It's not unnecessary.
It just belongs in the implementation section rather than the interface
section.
----------
Estimated hours taken: 1
Branches: main
extras/moose/moose.m:
Fix a bug introduced by petr's last change: put back the
`:- import_module list.' declaration, since it is needed for
the references to `[]', `[|]', `list', and `list_skel'.
But put it back in the implementation section rather than in
the interface section, because it is not needed by the interface.
extras/moose/tests/Mmakefile:
extras/moose/tests/array_based.moo:
Add a regression test.
Workspace: /home/jupiter/fjh/ws-jupiter/mercury
Index: extras/moose/moose.m
===================================================================
RCS file: /home/mercury1/repository/mercury/extras/moose/moose.m,v
retrieving revision 1.8
diff -u -d -r1.8 moose.m
--- extras/moose/moose.m 23 Feb 2004 16:23:51 -0000 1.8
+++ extras/moose/moose.m 24 Feb 2004 00:27:51 -0000
@@ -657,6 +657,8 @@
true
),
io__format("\
+:- import_module list.
+
parse(Result, Toks0, Toks) :-
parse(Toks0, Toks, [0], [], Result).
Index: extras/moose/tests/Mmakefile
===================================================================
RCS file: extras/moose/tests/Mmakefile
diff -N extras/moose/tests/Mmakefile
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ extras/moose/tests/Mmakefile 24 Feb 2004 00:33:00 -0000
@@ -0,0 +1,17 @@
+
+.SUFFIXES: .m .moo
+
+default_target : all
+
+depend : array_based.depend
+
+array_based.depend: array_based.m
+
+all: array_based.c
+
+.moo.m:
+ ../moose $<
+
+realclean:
+ rm -f array_based.m
+
Index: extras/moose/tests/array_based.moo
===================================================================
RCS file: extras/moose/tests/array_based.moo
diff -N extras/moose/tests/array_based.moo
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ extras/moose/tests/array_based.moo 24 Feb 2004 00:37:05 -0000
@@ -0,0 +1,81 @@
+% This is a regression test. It tests that Moo supports parsers that do not
+% use lists.
+
+:- module array_based.
+
+:- interface.
+
+:- import_module char, int, array.
+
+:- type token
+ ---> ('+')
+ ; num(int)
+ ; ('(')
+ ; (')')
+ ; eof
+ .
+
+:- parse(exprn/1, token, eof, xx, in, out).
+
+:- pred scan(array(char), array(token)).
+:- mode scan(in, out) is det.
+
+:- implementation.
+
+:- import_module string, require.
+
+:- rule exprn(int).
+exprn(Num) ---> exprn(A), [+], term(B), { Num = A + B }.
+exprn(Term) ---> term(Term).
+
+:- rule term(int).
+term(Num) ---> factor(Num).
+
+:- rule factor(int).
+factor(Num) ---> ['('], exprn(Num), [')'].
+factor(Num) ---> [num(Num)].
+
+scan(Chars, Toks) :-
+ scan(Chars, array__make_empty_array, Toks0),
+ Toks = array_reverse(Toks0).
+
+:- pred scan(array(char), array(token), array(token)).
+:- mode scan(in, in, out) is det.
+
+scan(Cs0, Toks0, Toks) :-
+ ( array__size(Cs0) = 0 ->
+ Toks = array_cons(eof, Toks0)
+ ;
+ C = Cs0^elem(0),
+ Cs = array_tail(Cs0),
+ (if
+ char__is_whitespace(C)
+ then
+ scan(Cs, Toks0, Toks)
+ else if
+ char__digit_to_int(C, Num)
+ then
+ scan(Cs, array_cons(num(Num), Toks0), Toks)
+ else if
+ C = ('+')
+ then
+ scan(Cs, array_cons('+', Toks0), Toks)
+ else if
+ C = ('(')
+ then
+ scan(Cs, array_cons('(', Toks0), Toks)
+ else if
+ C = (')')
+ then
+ scan(Cs, array_cons(')', Toks0), Toks)
+ else
+ error("expr: syntax error in input")
+ )
+ ).
+
+:- func array_cons(T, array(T)) = array(T).
+:- external(array_cons/2).
+:- func array_reverse(array(T)) = array(T).
+:- external(array_reverse/1).
+:- func array_tail(array(T)) = array(T).
+:- external(array_tail/1).
--
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