Files
mercury/extras/moose/samples/try_expr.m
Julien Fischer 144145573e Don't use "cute" operator overloadings in moose - this allows us to compile it
Branches: main, 11.01

Don't use "cute" operator overloadings in moose - this allows us to compile it
with the non-C backends, some of which don't currently do the name mangling
which would otherwise be required.

Make the moose samples work again.

extras/moose/misc.m:
	Delete this module -- overloading operators in this way was
	never a particuarly good idea, especially as several of the
	overloaded operators (now) mean other things in Mercury.

extras/moose/check.m:
extras/moose/grammar.m:
extras/moose/lalr.m:
extras/moose/mercury_syntax.m:
extras/moose/moose.m:
extras/moose/tables.m:
	Conform to the above changes.

	Import each module on its own line.

extras/moose/options.m:
	As above.

	Use the "multi" form of the option_ops type.

extras/moose/samples/try_alpha.m:
extras/moose/samples/try_expr.m:
	Make these examples work again -- as written the typeclass
	instance they contain does not satisfy the current restrictions
	on the form of instance arguments.

	Syntax and formatting cleanups.
2011-01-18 13:03:59 +00:00

59 lines
1.6 KiB
Mathematica

%-----------------------------------------------------------------------------%
% vim: ft=mercury ts=4 sw=4 et wm=0 tw=0
%-----------------------------------------------------------------------------%
:- module try_expr.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is det.
%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%
:- implementation.
:- import_module expr.
:- import_module list.
%-----------------------------------------------------------------------------%
% We need to wrap this up using a notag type in order to satisfy the
% requirements on the form that type class instance arguments can take.
%
:- type token_list
---> token_list(list(token)).
:- instance parser_state(token_list) where [
get_token(eof, token_list([]), token_list([])),
get_token(T, token_list([T | Ts]), token_list(Ts)),
unget_token(T, token_list(Ts)) = token_list([T | Ts])
].
main(!IO) :-
read_line(Res0, !IO),
(
Res0 = ok(Chars),
scan(Chars, Toks),
parse(Res, token_list(Toks), token_list(RemainingToks)),
io.write(Res, !IO),
io.nl(!IO),
io.write(RemainingToks, !IO),
io.nl(!IO),
main(!IO)
;
Res0 = eof
;
Res0 = error(Err),
io.error_message(Err, Msg),
io.write_string(Msg, !IO),
io.nl(!IO)
).
%-----------------------------------------------------------------------------%
:- end_module try_expr.
%-----------------------------------------------------------------------------%