[m-rev.] diff: Fix bug and update syntax in extras/moose
Paul Bone
pbone at csse.unimelb.edu.au
Sat Feb 21 22:31:04 AEDT 2009
Estimated hours taken: 1
Corrected a bug in moose whereby it failed to return a non-zero exit code when
a critical error occured.
Converted moose to modern syntax with regard to DCGs and State Variables and
module delimters such as '__' vs '.'. Converted some indentation to four
spaces.
extras/moose/check.m:
extras/moose/grammar.m:
extras/moose/lalr.m:
extras/moose/mercury_syntax.m:
extras/moose/misc.m:
extras/moose/moose.m:
extras/moose/options.m:
extras/moose/tables.m:
As above.
extras/moose/BUGS
Noted a new bug.
extras/moose/TODO
Corrected a spelling mistake.
Index: extras/moose/BUGS
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/extras/moose/BUGS,v
retrieving revision 1.2
diff -u -r1.2 BUGS
--- extras/moose/BUGS 8 Dec 2003 16:13:00 -0000 1.2
+++ extras/moose/BUGS 21 Feb 2009 11:27:37 -0000
@@ -1,4 +1,6 @@
+Copyright (C) 2009 The University of Melbourne
+
Doesn't handle epsilon productions properly -- throws an exception
when computing the action table:
@@ -31,4 +33,6 @@
init_declarator(init_declarator(D, Init)) --->
declarator(D) ; { Init = no }.
+If there is some error in the grammar moose will write an empty or broken .m
+file. This may be a problem in some cases.
Index: extras/moose/TODO
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/extras/moose/TODO,v
retrieving revision 1.3
diff -u -r1.3 TODO
--- extras/moose/TODO 19 Feb 2002 07:49:01 -0000 1.3
+++ extras/moose/TODO 21 Feb 2009 11:27:37 -0000
@@ -1,3 +1,6 @@
+
+Copyright (C) 2009 The University of Melbourne
+
To make moose more useful:
- allow parsing actions to be semidet to allow the imposition
of semantic conditions during parsing.
@@ -16,7 +19,7 @@
Wish list:
- introduce new nonterminals for disjunctions in productions.
- This is quite difficult because it requres correct computation
+ This is quite difficult because it requires correct computation
of the nonlocal variables of goals (including all the nasty
cases like pred expressions).
Index: extras/moose/check.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/extras/moose/check.m,v
retrieving revision 1.5
diff -u -r1.5 check.m
--- extras/moose/check.m 21 Apr 2006 04:03:21 -0000 1.5
+++ extras/moose/check.m 21 Feb 2009 11:27:37 -0000
@@ -28,23 +28,23 @@
:- import_module grammar.
:- import_module io, list, string, term.
-:- type check__error
+:- type check.error
---> error(list(string), context).
-:- pred check_rule_decls(list(rule_decl), rule_decls, list(check__error)).
+:- pred check_rule_decls(list(rule_decl), rule_decls, list(check.error)).
:- mode check_rule_decls(in, out, out) is det.
-:- pred check_clauses(list(clause), rule_decls, clauses, list(check__error)).
+:- pred check_clauses(list(clause), rule_decls, clauses, list(check.error)).
:- mode check_clauses(in, in, out, out) is det.
-:- pred check_useless(nonterminal, clauses, rule_decls, list(check__error)).
+:- pred check_useless(nonterminal, clauses, rule_decls, list(check.error)).
:- mode check_useless(in, in, in, out) is det.
-:- pred check_inf_derivations(clauses, rule_decls, list(check__error)).
+:- pred check_inf_derivations(clauses, rule_decls, list(check.error)).
:- mode check_inf_derivations(in, in, out) is det.
% write an error message to stderr.
-:- pred write_error(check__error, io__state, io__state).
+:- pred write_error(check.error, io.state, io.state).
:- mode write_error(in, di, uo) is det.
:- implementation.
@@ -55,53 +55,53 @@
%------------------------------------------------------------------------------%
check_rule_decls(DeclList, Decls, Errors) :-
- map__init(Decls0),
+ map.init(Decls0),
check_rule_decls(DeclList, Decls0, Decls, Errors).
:- pred check_rule_decls(list(rule_decl), rule_decls, rule_decls,
- list(check__error)).
+ list(check.error)).
:- mode check_rule_decls(in, in, out, out) is det.
check_rule_decls([], !Decls, []).
check_rule_decls([Decl | DeclList], !Decls, Errors) :-
Decl = rule(DeclId, _Args, _VarSet, DeclContext),
% Look to see if we already have a declaration for this rule.
- ( map__search(!.Decls, DeclId, PrevDecl) ->
+ ( map.search(!.Decls, DeclId, PrevDecl) ->
PrevDecl = rule(_, _, _, PrevDeclContext),
id(DeclId, Name, Arity),
- string__format("The previous declaration for %s/%d is here.",
+ string.format("The previous declaration for %s/%d is here.",
[s(Name), i(Arity)], Msg0),
Err0 = error([Msg0], PrevDeclContext),
- string__format("Duplicate declaration for %s/%d.",
+ string.format("Duplicate declaration for %s/%d.",
[s(Name), i(Arity)], Msg1),
Err1 = error([Msg1], DeclContext),
Errors = [Err0, Err1 | Errors0],
check_rule_decls(DeclList, !Decls, Errors0)
;
- map__set(!.Decls, DeclId, Decl, !:Decls),
+ map.set(!.Decls, DeclId, Decl, !:Decls),
check_rule_decls(DeclList, !Decls, Errors)
).
%------------------------------------------------------------------------------%
check_clauses(ClauseList, Decls, Clauses, Errors) :-
- map__init(Clauses0),
+ map.init(Clauses0),
check_clauses0(ClauseList, Decls, Clauses0, Clauses, Errors0),
- map__keys(Decls, DeclIds),
- set__sorted_list_to_set(DeclIds, DeclSet),
- map__keys(Clauses, ClauseIds),
- set__sorted_list_to_set(ClauseIds, ClauseSet),
+ map.keys(Decls, DeclIds),
+ set.sorted_list_to_set(DeclIds, DeclSet),
+ map.keys(Clauses, ClauseIds),
+ set.sorted_list_to_set(ClauseIds, ClauseSet),
NoDeclSet = ClauseSet - DeclSet,
NoClauseSet = DeclSet - ClauseSet,
% Productions that have no rule declaration.
- set__to_sorted_list(NoDeclSet, NoDeclList),
- list__map((pred(NoDeclId::in, NoDeclError::out) is det :-
- map__lookup(Clauses, NoDeclId, List),
+ set.to_sorted_list(NoDeclSet, NoDeclList),
+ list.map((pred(NoDeclId::in, NoDeclError::out) is det :-
+ map.lookup(Clauses, NoDeclId, List),
( List = [clause(_, _, _, NoDeclContext)|_] ->
id(NoDeclId, NoDeclName, NoDeclArity),
- string__format("No rule declaration for %s/%d.",
+ string.format("No rule declaration for %s/%d.",
[s(NoDeclName), i(NoDeclArity)], NoDeclMsg),
NoDeclError = error([NoDeclMsg], NoDeclContext)
;
@@ -110,46 +110,46 @@
), NoDeclList, Errors1),
% Rules that have no productions.
- set__to_sorted_list(NoClauseSet, NoClauseList),
- list__map((pred(NoClauseId::in, NoClauseError::out) is det :-
- map__lookup(Decls, NoClauseId, Decl),
+ set.to_sorted_list(NoClauseSet, NoClauseList),
+ list.map((pred(NoClauseId::in, NoClauseError::out) is det :-
+ map.lookup(Decls, NoClauseId, Decl),
Decl = rule(_, _, _, NoClauseContext),
id(NoClauseId, NoClauseName, NoClauseArity),
- string__format("No productions for %s/%d.",
+ string.format("No productions for %s/%d.",
[s(NoClauseName), i(NoClauseArity)], NoClauseMsg),
NoClauseError = error([NoClauseMsg], NoClauseContext)
), NoClauseList, Errors2),
- list__condense([Errors0, Errors1, Errors2], Errors).
+ list.condense([Errors0, Errors1, Errors2], Errors).
:- pred check_clauses0(list(clause), rule_decls, clauses, clauses,
- list(check__error)).
+ list(check.error)).
:- mode check_clauses0(in, in, in, out, out) is det.
check_clauses0([], _Decls, !Clauses, []).
check_clauses0([Clause | ClauseList], Decls, !Clauses, Errors) :-
Clause = clause(Head, Prod, _, Context),
Id = nonterminal(Head),
- ( map__search(!.Clauses, Id, ClauseList0) ->
- list__append(ClauseList0, [Clause], ClauseList1)
+ ( map.search(!.Clauses, Id, ClauseList0) ->
+ list.append(ClauseList0, [Clause], ClauseList1)
;
ClauseList1 = [Clause]
),
- map__set(!.Clauses, Id, ClauseList1, !:Clauses),
+ map.set(!.Clauses, Id, ClauseList1, !:Clauses),
% Look for used nonterminals that are not declared.
solutions((pred(NonTermId::out) is nondet :-
% XXX performance
nonterminals(Prod, NonTermIds),
- list__member(NonTermId, NonTermIds),
+ list.member(NonTermId, NonTermIds),
not contains(Decls, NonTermId)
), UnDeclaredIds),
- list__map((pred(UnDeclaredId::in, UnDeclaredError::out) is det :-
+ list.map((pred(UnDeclaredId::in, UnDeclaredError::out) is det :-
id(Id, CN, CA),
id(UnDeclaredId, NN, NA),
- string__format("In production for %s/%d,",
+ string.format("In production for %s/%d,",
[s(CN), i(CA)], Msg0),
- string__format(" the nonterminal %s/%d is undeclared.",
+ string.format(" the nonterminal %s/%d is undeclared.",
[s(NN), i(NA)], Msg1),
UnDeclaredError = error([Msg0, Msg1], Context)
), UnDeclaredIds, Errors0),
@@ -160,7 +160,7 @@
% Not tail recursive, so only do it if we have to.
Errors0 = [_|_],
check_clauses0(ClauseList, Decls, !Clauses, Errors1),
- list__append(Errors0, Errors1, Errors)
+ list.append(Errors0, Errors1, Errors)
).
%------------------------------------------------------------------------------%
@@ -168,17 +168,17 @@
check_useless(Start, Clauses, Decls, Errors) :-
StartSet = { Start },
useful(StartSet, Clauses, StartSet, UsefulSet),
- map__keys(Clauses, AllIds),
- set__sorted_list_to_set(AllIds, AllSet),
+ map.keys(Clauses, AllIds),
+ set.sorted_list_to_set(AllIds, AllSet),
UselessSet = AllSet - UsefulSet,
- set__to_sorted_list(UselessSet, UselessList),
- list__filter_map((pred(UselessId::in, Error::out) is semidet :-
+ set.to_sorted_list(UselessSet, UselessList),
+ list.filter_map((pred(UselessId::in, Error::out) is semidet :-
% Use search rather than lookup in case
% it was an undeclared rule.
- map__search(Decls, UselessId, Decl),
+ map.search(Decls, UselessId, Decl),
Decl = rule(_Id, _Args, _VarSet, Context),
UselessId = Name / Arity,
- string__format("Grammar rule %s/%d is not used.",
+ string.format("Grammar rule %s/%d is not used.",
[s(Name), i(Arity)], Msg),
Error = error([Msg], Context)
), UselessList, Errors).
@@ -189,13 +189,13 @@
:- mode useful(in, in, in, out) is det.
useful(New0, Clauses, !Useful) :-
- ( set__empty(New0) ->
+ ( set.empty(New0) ->
true
;
solutions_set((pred(UId::out) is nondet :-
- set__member(Id, New0),
- map__search(Clauses, Id, ClauseList),
- list__member(Clause, ClauseList),
+ set.member(Id, New0),
+ map.search(Clauses, Id, ClauseList),
+ list.member(Clause, ClauseList),
Clause = clause(_Head, Prod, _VarSet, _Context),
nonterminal(UId, Prod)
), NewSet),
@@ -224,18 +224,18 @@
%------------------------------------------------------------------------------%
check_inf_derivations(Clauses, Decls, Errors) :-
- map__keys(Clauses, AllIds),
- set__sorted_list_to_set(AllIds, InfSet0),
- set__init(FinSet0),
+ map.keys(Clauses, AllIds),
+ set.sorted_list_to_set(AllIds, InfSet0),
+ set.init(FinSet0),
finite(InfSet0, FinSet0, Clauses, InfSet),
- set__to_sorted_list(InfSet, InfList),
- list__filter_map((pred(InfId::in, Error::out) is semidet :-
+ set.to_sorted_list(InfSet, InfList),
+ list.filter_map((pred(InfId::in, Error::out) is semidet :-
% Use search rather than lookup in case
% it was an undeclared rule.
- map__search(Decls, InfId, Decl),
+ map.search(Decls, InfId, Decl),
Decl = rule(_Id, _Args, _VarSet, Context),
InfId = Name / Arity,
- string__format("Rule %s/%d does not have any finite derivations.",
+ string.format("Rule %s/%d does not have any finite derivations.",
[s(Name), i(Arity)], Msg),
Error = error([Msg], Context)
), InfList, Errors).
@@ -245,12 +245,12 @@
finite(!.Inf, Fin0, Clauses, !:Inf) :-
solutions_set((pred(NewFinId::out) is nondet :-
- set__member(NewFinId, !.Inf),
+ set.member(NewFinId, !.Inf),
% search rather than lookup in case the nonterminal
% doesn't have any clauses. This may lead to
% spurious infinite derivations.
- map__search(Clauses, NewFinId, ClauseList),
- list__member(Clause, ClauseList),
+ map.search(Clauses, NewFinId, ClauseList),
+ list.member(Clause, ClauseList),
Clause = clause(_Head, Prod, _VarSet, _Context),
nonterminals(Prod, NonTerms),
(
@@ -258,13 +258,13 @@
;
NonTerms = [_|_],
all [NId] (
- list__member(NId, NonTerms) =>
- set__member(NId, Fin0)
+ list.member(NId, NonTerms) =>
+ set.member(NId, Fin0)
)
)
), NewFinSet),
NewFin = NewFinSet - Fin0,
- ( set__empty(NewFin) ->
+ ( set.empty(NewFin) ->
true
;
!:Inf = !.Inf - NewFin,
@@ -300,13 +300,13 @@
%------------------------------------------------------------------------------%
write_error(error(MsgLines, Context), !IO) :-
- Context = term__context(File, Line),
- string__format("%s:%d: ", [s(File), i(Line)], ContextMsg),
- io__stderr_stream(StdErr, !IO),
- list__foldl((pred(Msg::in, !.IO::di, !:IO::uo) is det :-
- io__write_string(StdErr, ContextMsg, !IO),
- io__write_string(StdErr, Msg, !IO),
- io__nl(StdErr, !IO)
+ Context = term.context(File, Line),
+ string.format("%s:%d: ", [s(File), i(Line)], ContextMsg),
+ io.stderr_stream(StdErr, !IO),
+ list.foldl((pred(Msg::in, !.IO::di, !:IO::uo) is det :-
+ io.write_string(StdErr, ContextMsg, !IO),
+ io.write_string(StdErr, Msg, !IO),
+ io.nl(StdErr, !IO)
), MsgLines, !IO).
%------------------------------------------------------------------------------%
Index: extras/moose/grammar.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/extras/moose/grammar.m,v
retrieving revision 1.9
diff -u -r1.9 grammar.m
--- extras/moose/grammar.m 30 Mar 2006 01:21:17 -0000 1.9
+++ extras/moose/grammar.m 21 Feb 2009 11:27:37 -0000
@@ -159,7 +159,7 @@
Atom = atom("--->"),
Args = [Head, Body],
Head = functor(atom(Name), HeadArgs, _),
- list__length(HeadArgs, Arity),
+ list.length(HeadArgs, Arity),
Id = Name/Arity,
Rule = clause(Head, Prod, VarSet, Context),
term_to_prod(Body, Prod).
@@ -179,7 +179,7 @@
; Atom = atom("{}"), Args = [Goal] ->
Prod = action(Goal)
; Atom = atom("{}"), Args = [Goal | Goals] ->
- list__foldl(
+ list.foldl(
(pred(G::in, Left::in, (Left, action(G))::out) is det),
Goals, action(Goal), Prod)
; Atom = atom("[]"), Args = [] ->
@@ -205,26 +205,26 @@
%------------------------------------------------------------------------------%
add_clause(Clauses0, Id, Clause, Clauses) :-
- ( map__search(Clauses0, Id, These0) ->
+ ( map.search(Clauses0, Id, These0) ->
These = [Clause|These0]
;
These = [Clause]
),
- map__set(Clauses0, Id, These, Clauses).
+ map.set(Clauses0, Id, These, Clauses).
%------------------------------------------------------------------------------%
construct_grammar(Start, AllClauses, XForms, Grammar) :-
- map__to_assoc_list(AllClauses, ClauseList),
+ map.to_assoc_list(AllClauses, ClauseList),
Nont0 = 1,
start_rule(Start, StartRule),
- map__from_assoc_list([0 - StartRule], Rules0),
- map__init(ClauseIndex0),
- map__init(First0),
- map__init(Follow0),
+ map.from_assoc_list([0 - StartRule], Rules0),
+ map.init(ClauseIndex0),
+ map.init(First0),
+ map.init(Follow0),
Grammar0 = grammar(Rules0, AllClauses, XForms, Nont0, ClauseIndex0,
First0, Follow0),
- list__foldl(transform_clause_list, ClauseList, Grammar0, Grammar1),
+ list.foldl(transform_clause_list, ClauseList, Grammar0, Grammar1),
compute_first0(Grammar1, Grammar2),
compute_follow0(Grammar2, Grammar3),
Grammar3 = grammar(Rules3, AllClauses3, XForms3, Nont3, ClauseIndex3,
@@ -232,9 +232,9 @@
% Keep the nonterminals in reverse sorted order
% for efficient processing in lalr.m
- map__map_values((pred(_K::in, V0::in, V::out) is det :-
- list__sort(V0, V1),
- list__reverse(V1, V)
+ map.map_values((pred(_K::in, V0::in, V::out) is det :-
+ list.sort(V0, V1),
+ list.reverse(V1, V)
), ClauseIndex3, ClauseIndex4),
Grammar = grammar(Rules3, AllClauses3, XForms3, Nont3, ClauseIndex4,
First3, Follow3).
@@ -249,16 +249,16 @@
Id = start,
error("epsilon start rule")
),
- varset__init(VarSet0),
- varset__new_vars(VarSet0, Arity, Vars, VarSet1),
- list__foldl((pred(V::in, VS0::in, VS::out) is det :-
- term__var_to_int(V, I),
- string__format("V%d", [i(I)], N),
- varset__name_var(VS0, V, N, VS)
+ varset.init(VarSet0),
+ varset.new_vars(VarSet0, Arity, Vars, VarSet1),
+ list.foldl((pred(V::in, VS0::in, VS::out) is det :-
+ term.var_to_int(V, I),
+ string.format("V%d", [i(I)], N),
+ varset.name_var(VS0, V, N, VS)
), Vars, VarSet1, VarSet),
- term__var_list_to_term_list(Vars, Args),
+ term.var_list_to_term_list(Vars, Args),
Context = context("foobie", 1),
- string__append(Name, "'", NewName),
+ string.append(Name, "'", NewName),
NewId = start,
Head = functor(atom(NewName), Args, Context),
Body = array([nonterminal(Id)]),
@@ -270,7 +270,7 @@
:- mode transform_clause_list(in, in, out) is det.
transform_clause_list(Id - Clauses, !Grammar) :-
- list__foldl(transform_clause(Id), Clauses, !Grammar).
+ list.foldl(transform_clause(Id), Clauses, !Grammar).
:- pred transform_clause(nonterminal, clause, grammar, grammar).
:- mode transform_clause(in, in, in, out) is det.
@@ -278,7 +278,7 @@
transform_clause(Id, Clause, !Grammar) :-
Clause = clause(Head, Prod, Varset, Context),
solutions(transform_prod(Prod), Bodies),
- list__foldl(add_rule(Id, Head, Varset, Context), Bodies, !Grammar).
+ list.foldl(add_rule(Id, Head, Varset, Context), Bodies, !Grammar).
:- pred add_rule(nonterminal, term, varset, context,
pair(list(bodyterm), list(term)), grammar, grammar).
@@ -286,7 +286,7 @@
add_rule(Id, Head, Varset, Context, BodyTerms - Actions, !Grammar) :-
!.Grammar = grammar(Rules0, C, Xfs, Nont0, ClauseIndex0, F, L),
- list__map((pred(BodyTerm::in, BodyId::out) is det :-
+ list.map((pred(BodyTerm::in, BodyId::out) is det :-
(
BodyTerm = terminal(Term),
( Term = functor(atom(Name), Args, _) ->
@@ -311,12 +311,12 @@
Varset, Context),
add_rule(Rules0, Nont0, Rule, Rules),
Nont = Nont0 + 1,
- ( map__search(ClauseIndex0, Id, Prods0) ->
+ ( map.search(ClauseIndex0, Id, Prods0) ->
Prods = [Nont0|Prods0]
;
Prods = [Nont0]
),
- map__set(ClauseIndex0, Id, Prods, ClauseIndex),
+ map.set(ClauseIndex0, Id, Prods, ClauseIndex),
!:Grammar = grammar(Rules, C, Xfs, Nont, ClauseIndex, F, L).
:- pred transform_prod(prod, pair(list(bodyterm), list(term))).
@@ -328,8 +328,8 @@
transform_prod((ProdA, ProdB), Body - Actions) :-
transform_prod(ProdA, BodyA - ActionsA),
transform_prod(ProdB, BodyB - ActionsB),
- list__append(BodyA, BodyB, Body),
- list__append(ActionsA, ActionsB, Actions).
+ list.append(BodyA, BodyB, Body),
+ list.append(ActionsA, ActionsB, Actions).
transform_prod((ProdA ; ProdB), Result) :-
(
transform_prod(ProdA, Result)
@@ -381,12 +381,12 @@
compute_first(Rules, First) :-
collect_nonterminals(Rules, Nonterminals),
- map__init(First0),
+ map.init(First0),
Stuff0 = stuff(no, Nonterminals, Rules, First0),
until((pred(Stuff1::in, Stuff3::out) is det :-
Stuff1 = stuff(_, N1, R1, F1),
Stuff2 = stuff(no, N1, R1, F1),
- map__foldl(compute_first, Rules, Stuff2, Stuff3)
+ map.foldl(compute_first, Rules, Stuff2, Stuff3)
),
(pred(StuffN::in) is semidet :-
StuffN = stuff(no, _, _, _)
@@ -398,13 +398,13 @@
compute_first(_RuleNum, Rule, Stuff0, Stuff) :-
Rule = rule(Id, _Head, Elems, _Body, _Actions, _Varset, _Context),
- array__max(Elems, Max),
+ array.max(Elems, Max),
( Max >= 0 ->
% If there are literals in the body of the
% rule, then compute the first set that derives
% from what we currently know...
Stuff0 = stuff(_, _, _, TmpFirst),
- set__init(Emp),
+ set.init(Emp),
compute_first(0, Max, Elems, TmpFirst, Emp, ComputedFirst)
;
% There were no literals in the body of the rule,
@@ -446,18 +446,18 @@
compute_first(I, IMax, Elems, First, Set0, Set) :-
( I =< IMax ->
- array__lookup(Elems, I, Elem),
+ array.lookup(Elems, I, Elem),
(
% If we get to a terminal, then we add it
% to the first set, and remove epsilon (if
% it was there in the first place), since
% this rule is certainly not nullable.
Elem = terminal(Id),
- set__insert(Set0, Id, Set1),
- set__difference(Set1, { epsilon }, Set)
+ set.insert(Set0, Id, Set1),
+ set.difference(Set1, { epsilon }, Set)
;
Elem = nonterminal(Id),
- ( map__search(First, Id, Set1) ->
+ ( map.search(First, Id, Set1) ->
% If we know some information about
% the nonterminal, then add it to
% what we already know. If it is
@@ -465,12 +465,12 @@
% not nullable, and we're done. If
% it is nullable, then we look at
% the next literal in the body.
- set__union(Set0, Set1, Set2),
- ( set__member(epsilon, Set1) ->
+ set.union(Set0, Set1, Set2),
+ ( set.member(epsilon, Set1) ->
compute_first(I + 1, IMax, Elems, First,
Set2, Set)
;
- set__difference(Set2, { epsilon }, Set)
+ set.difference(Set2, { epsilon }, Set)
)
;
% If we don't know anything about
@@ -486,9 +486,9 @@
:- mode collect_terminals(in, out) is det.
collect_terminals(Rules, Terminals) :-
- map__foldl((pred(_RN::in, Rule::in, Ts0::in, Ts::out) is det :-
+ map.foldl((pred(_RN::in, Rule::in, Ts0::in, Ts::out) is det :-
Rule = rule(_Id, _Head, Elems, _, _, _, _),
- Ts = array__foldl((func(Elem, Ts1) = Ts2 :-
+ Ts = array.foldl((func(Elem, Ts1) = Ts2 :-
(
Elem = terminal(Id),
Ts2 = [Id|Ts1]
@@ -498,18 +498,18 @@
)
), Elems, Ts0)
), Rules, [], TerminalsList),
- set__list_to_set(TerminalsList, Terminals).
+ set.list_to_set(TerminalsList, Terminals).
:- pred collect_nonterminals(rules, list(nonterminal)).
:- mode collect_nonterminals(in, out) is det.
collect_nonterminals(Rules, Nonterminals) :-
- map__foldl((pred(_RN ::in, Rule::in, Ts0::in, Ts::out) is det :-
+ map.foldl((pred(_RN ::in, Rule::in, Ts0::in, Ts::out) is det :-
Rule = rule(Id, _Head, _Elems, _, _, _Varset, _Context),
Ts = [Id|Ts0]
), Rules, [], NonterminalsList),
- set__list_to_set(NonterminalsList, Nonterminals0),
- set__to_sorted_list(Nonterminals0, Nonterminals).
+ set.list_to_set(NonterminalsList, Nonterminals0),
+ set.to_sorted_list(Nonterminals0, Nonterminals).
% YYY This probably belongs in the library somewhere.
:- pred while(pred(T), pred(T, T), T, T).
@@ -558,9 +558,9 @@
).
compute_follow(Rules, Start, EOF, First, Follow) :-
- map__init(Follow0),
+ map.init(Follow0),
% Rule 1
- map__set(Follow0, Start, { EOF }, Follow1),
+ map.set(Follow0, Start, { EOF }, Follow1),
collect_nonterminals(Rules, Ns),
Stuff0 = stuff(no, Ns, Rules, First, Follow1),
until((pred(Stuff1::in, Stuff3::out) is det :-
@@ -579,7 +579,7 @@
compute_follow(_RuleNum, Rule, Stuff0, Stuff) :-
Rule = rule(Id, _Head, Elems, _, _, _Varset, _Context),
Stuff0 = stuff(_, _, _, First, _),
- array__max(Elems, Max),
+ array.max(Elems, Max),
% Apply Rule 2
compute_follow2(0, Max, First, Elems, Stuff0, Stuff1),
compute_follow3(Max, First, Id, Elems, Stuff1, Stuff).
@@ -608,12 +608,12 @@
compute_follow3(I, First, MyId, Elems, Stuff0, Stuff) :-
( I >= 0 ->
- array__lookup(Elems, I, Elem),
+ array.lookup(Elems, I, Elem),
( Elem = nonterminal(Id) ->
get_follow(MyId, MyFollow, Stuff0, _),
add_follow(Id, MyFollow, Stuff0, Stuff1),
- map__lookup(First, Id, IdFirst),
- ( set__member(epsilon, IdFirst) ->
+ map.lookup(First, Id, IdFirst),
+ ( set.member(epsilon, IdFirst) ->
compute_follow3(I - 1, First, MyId, Elems,
Stuff1, Stuff)
;
@@ -634,7 +634,7 @@
( search(Follow, Id, IdFollow0) ->
IdFollow = IdFollow0
;
- set__init(IdFollow)
+ set.init(IdFollow)
).
:- pred add_follow(nonterminal, set(terminal), follow_stuff, follow_stuff).
@@ -661,18 +661,18 @@
%------------------------------------------------------------------------------%
first(First, Elems, I) = FirstI :-
- array__max(Elems, Max),
+ array.max(Elems, Max),
( I =< Max ->
- array__lookup(Elems, I, Elem),
+ array.lookup(Elems, I, Elem),
(
Elem = terminal(Id),
FirstI = { Id }
;
Elem = nonterminal(Id),
- map__lookup(First, Id, FirstI0),
- ( set__member(epsilon, FirstI0) ->
+ map.lookup(First, Id, FirstI0),
+ ( set.member(epsilon, FirstI0) ->
RestFirst = first(First, Elems, I+1),
- set__union(FirstI0, RestFirst, FirstI)
+ set.union(FirstI0, RestFirst, FirstI)
;
FirstI = FirstI0
)
@@ -687,6 +687,6 @@
:- mode add_rule(in, in, in, out) is det.
add_rule(Rules0, Num, Rule, Rules) :-
- map__set(Rules0, Num, Rule, Rules).
+ map.set(Rules0, Num, Rule, Rules).
%------------------------------------------------------------------------------%
Index: extras/moose/lalr.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/extras/moose/lalr.m,v
retrieving revision 1.5
diff -u -r1.5 lalr.m
--- extras/moose/lalr.m 30 Mar 2006 01:21:17 -0000 1.5
+++ extras/moose/lalr.m 21 Feb 2009 11:27:37 -0000
@@ -48,7 +48,7 @@
:- mode lr0items(in, in, out, out) is det.
:- pred lookaheads(set(items), gotos, rules, first, index, lookaheads,
- io__state, io__state).
+ io.state, io.state).
:- mode lookaheads(in, in, in, in, in, out, di, uo) is det.
:- implementation.
@@ -70,9 +70,9 @@
prodnums(Productions, ProdNums),
reaching(ProdNums, Productions, First, no, !Reaching).
reaching([ProdNum|ProdNums], Productions, First, !.Change, !Reaching) :-
- map__lookup(Productions, ProdNum, Prod),
+ map.lookup(Productions, ProdNum, Prod),
Prod = rule(NonTerminal, _Head, Symbols, _, _, _V, _C),
- array__max(Symbols, PMax),
+ array.max(Symbols, PMax),
reaching_2(0, PMax, Symbols, First, NonTerminal, !Change, !Reaching),
reaching(ProdNums, Productions, First, !.Change, !Reaching).
@@ -84,21 +84,21 @@
( SN > Max ->
true
;
- array__lookup(Symbols, SN, Symbol),
+ array.lookup(Symbols, SN, Symbol),
(
Symbol = terminal(_)
;
Symbol = nonterminal(A),
reaches(C, A, !Change, !Reaching),
- ( map__search(!.Reaching, A, AR) ->
- set__to_sorted_list(AR, ARList),
- list__foldl2(reaches(C), ARList, !Change,
+ ( map.search(!.Reaching, A, AR) ->
+ set.to_sorted_list(AR, ARList),
+ list.foldl2(reaches(C), ARList, !Change,
!Reaching)
;
true
),
- map__lookup(First, A, FirstA),
- ( set__member(epsilon, FirstA) ->
+ map.lookup(First, A, FirstA),
+ ( set.member(epsilon, FirstA) ->
reaching_2(SN + 1, Max, Symbols, First, C,
!Change, !Reaching)
;
@@ -111,18 +111,18 @@
:- mode reaches(in, in, in, out, in, out) is det.
reaches(C, A, !Change, !Reaching) :-
- ( map__search(!.Reaching, C, As0) ->
- ( set__member(A, As0) ->
+ ( map.search(!.Reaching, C, As0) ->
+ ( set.member(A, As0) ->
true
;
!:Change = yes,
As = As0 \/ { A },
- map__set(!.Reaching, C, As, !:Reaching)
+ map.set(!.Reaching, C, As, !:Reaching)
)
;
!:Change = yes,
As = { A },
- map__set(!.Reaching, C, As, !:Reaching)
+ map.set(!.Reaching, C, As, !:Reaching)
).
%------------------------------------------------------------------------------%
@@ -131,7 +131,7 @@
I0 = { item(0, 0) },
C0 = { I0 },
Pending = { I0 },
- map__init(Gotos0),
+ map.init(Gotos0),
lr0items1(Pending, Productions, Reaching, Gotos0, Gotos, C0, C).
:- pred lr0items1(set(items), rules, reaching, gotos, gotos,
@@ -139,17 +139,17 @@
:- mode lr0items1(in, in, in, in, out, in, out) is det.
lr0items1(Pending0, Productions, Reaching, !Gotos, !C) :-
- ( set__remove_least(Pending0, J, Pending1) ->
- set__to_sorted_list(J, JList),
+ ( set.remove_least(Pending0, J, Pending1) ->
+ set.to_sorted_list(J, JList),
lr0items_1(JList, J, Productions, Reaching, !Gotos, empty,
NewSet),
- set__to_sorted_list(NewSet, NewItems),
- list__map((pred(Pair::in, J0::out) is det :-
+ set.to_sorted_list(NewSet, NewItems),
+ list.map((pred(Pair::in, J0::out) is det :-
Pair = I0 - X,
- map__lookup(!.Gotos, I0, I0Gotos),
- map__lookup(I0Gotos, X, J0)
+ map.lookup(!.Gotos, I0, I0Gotos),
+ map.lookup(I0Gotos, X, J0)
), NewItems, PendingList),
- set__list_to_set(PendingList, NewPending0),
+ set.list_to_set(PendingList, NewPending0),
NewPending = NewPending0 - !.C,
!:C = !.C \/ NewPending,
Pending = Pending1 \/ NewPending,
@@ -166,13 +166,13 @@
lr0items_1([], _I, _Productions, _Reaching, !Gotos, !New).
lr0items_1([BItem | RestItems], I, Productions, Reaching, !Gotos, !New) :-
BItem = item(BProdNum, BDot),
- map__lookup(Productions, BProdNum, BProd),
+ map.lookup(Productions, BProdNum, BProd),
BProd = rule(_NonTerminal, _Head, BSyms, _, _, _V, _C),
- array__max(BSyms, BMax),
+ array.max(BSyms, BMax),
(
BDot =< BMax
->
- array__lookup(BSyms, BDot, X),
+ array.lookup(BSyms, BDot, X),
addgoto(I, X, item(BProdNum, BDot + 1), !Gotos, !New)
;
true
@@ -181,8 +181,8 @@
BDot =< BMax,
lookup(BSyms, BDot, nonterminal(C))
->
- ( map__search(Reaching, C, As) ->
- set__to_sorted_list(As, AXList)
+ ( map.search(Reaching, C, As) ->
+ set.to_sorted_list(As, AXList)
;
AXList = []
),
@@ -196,12 +196,12 @@
:- mode addgoto(in, in, in, in, out, in, out) is det.
addgoto(I, X, NewItem, !Gotos, !New) :-
- ( map__search(!.Gotos, I, IGotos0) ->
+ ( map.search(!.Gotos, I, IGotos0) ->
IGotos1 = IGotos0
;
init(IGotos1)
),
- ( map__search(IGotos1, X, GotoIX0) ->
+ ( map.search(IGotos1, X, GotoIX0) ->
GotoIX1 = GotoIX0
;
GotoIX1 = empty
@@ -230,13 +230,13 @@
addAs_2([], _A, _I, _Productions, !Gotos, !New).
addAs_2([Pn|Pns], A, I, Productions, !Gotos, !New) :-
- map__lookup(Productions, Pn, Prod),
+ map.lookup(Productions, Pn, Prod),
(
Prod = rule(A, _Head, Symbols, _, _, _V, _C),
- array__max(Symbols, Max),
+ array.max(Symbols, Max),
Max >= 0
->
- array__lookup(Symbols, 0, X),
+ array.lookup(Symbols, 0, X),
addgoto(I, X, item(Pn, 1), !Gotos, !New)
;
true
@@ -246,10 +246,10 @@
%------------------------------------------------------------------------------%
lookaheads(C, Gotos, Rules, First, Index, !:Lookaheads, !IO) :-
- map__from_assoc_list([item(0, 0) - { ($) }], I0),
- map__from_assoc_list([{item(0, 0)} - I0], !:Lookaheads),
- map__init(Propaheads0),
- set__to_sorted_list(C, CList),
+ map.from_assoc_list([item(0, 0) - { ($) }], I0),
+ map.from_assoc_list([{item(0, 0)} - I0], !:Lookaheads),
+ map.init(Propaheads0),
+ set.to_sorted_list(C, CList),
lookaheads(CList, Gotos, Rules, First, Index,
!.Lookaheads - Propaheads0, !:Lookaheads - Propaheads),
%foldl((pred(_I::in, IPs::in, di, uo) is det -->
@@ -263,8 +263,8 @@
% ), ItemsMap), nl
% ), IPs), nl
%), Propaheads),
- io__stderr_stream(StdErr, !IO),
- io__write_string(StdErr, "\tpropagating...\n", !IO),
+ io.stderr_stream(StdErr, !IO),
+ io.write_string(StdErr, "\tpropagating...\n", !IO),
propagate(C, Propaheads, !Lookaheads).
:- pred lookaheads(list(items), gotos, rules, first, index, previews, previews).
@@ -272,7 +272,7 @@
lookaheads([], _Gotos, _Rules, _First, _Index, !Lookaheads).
lookaheads([K | Ks], Gotos, Rules, First, Index, !Lookaheads) :-
- set__to_sorted_list(K, KList),
+ set.to_sorted_list(K, KList),
lookaheads1(KList, K, Gotos, Rules, First, Index, !Lookaheads),
lookaheads(Ks, Gotos, Rules, First, Index, !Lookaheads).
@@ -285,11 +285,11 @@
BItem = item(Bp, Bd),
BItem0 = item(Bp, Bd, (*)),
J0 = closure({ BItem0 }, Rules, First, Index),
- set__to_sorted_list(J0, JList0),
+ set.to_sorted_list(J0, JList0),
% Reverse the list so that in add_spontaneous, the
% set insertions are in reverse sorted order not
% sorted order thereby taking to cost from O(n) to O(1).
- list__reverse(JList0, JList),
+ list.reverse(JList0, JList),
lookaheads2(JList, BItem, I, Gotos, Rules, !Lookaheads),
lookaheads1(BItems, I, Gotos, Rules, First, Index, !Lookaheads).
@@ -302,11 +302,11 @@
:- mode closure(in, in, in, in, in, out) is det.
closure(Rules, First, Index, !.New, I0, I) :-
- set__to_sorted_list(!.New, NewList),
+ set.to_sorted_list(!.New, NewList),
closure1(NewList, Rules, First, Index, [I0], Is),
do_union(Is, I1),
!:New = I1 - I0,
- ( set__empty(!.New) ->
+ ( set.empty(!.New) ->
I = I1
;
closure(Rules, First, Index, !.New, I1, I)
@@ -319,31 +319,31 @@
closure1([], _Rules, _First, _Index, !I).
closure1([AItem | AItems], Rules, First, Index, !I) :-
AItem = item(Ap, Ad, Asym),
- map__lookup(Rules, Ap, rule(_, _, Asyms, _, _, _, _)),
- array__max(Asyms, AMax),
+ map.lookup(Rules, Ap, rule(_, _, Asyms, _, _, _, _)),
+ array.max(Asyms, AMax),
( Ad =< AMax ->
- array__lookup(Asyms, Ad, BSym),
+ array.lookup(Asyms, Ad, BSym),
( BSym = nonterminal(Bn) ->
Bf0 = first(First, Asyms, Ad + 1),
- ( set__member(epsilon, Bf0) ->
- set__delete(Bf0, epsilon, Bf1),
- set__insert(Bf1, Asym, Bf)
+ ( set.member(epsilon, Bf0) ->
+ set.delete(Bf0, epsilon, Bf1),
+ set.insert(Bf1, Asym, Bf)
%Bf = Bf1 \/ { Asym }
;
Bf = Bf0
),
- set__to_sorted_list(Bf, BfList0),
+ set.to_sorted_list(Bf, BfList0),
% Reverse the list so that we construct
% the new items in reverse sorted order
% so that the accumulated list is in
% sorted order. Thus we don't have to
% sort the list to turn it into a set.
% Reduces running time by > 10%
- list__reverse(BfList0, BfList),
- map__lookup(Index, Bn, Bps),
+ list.reverse(BfList0, BfList),
+ map.lookup(Index, Bn, Bps),
make_items(Bps, BfList, [], NList),
- set__sorted_list_to_set(NList, N),
- list__append([N], !I)
+ set.sorted_list_to_set(NList, N),
+ list.append([N], !I)
;
true
)
@@ -388,10 +388,10 @@
lookaheads2([], _B, _I, _Gotos, _Rules, !Lookaheads).
lookaheads2([A | As], B, I, Gotos, Rules, !Lookaheads) :-
A = item(Ap, Ad, Alpha),
- map__lookup(Rules, Ap, rule(_, _, ASyms, _, _, _, _)),
- array__max(ASyms, AMax),
+ map.lookup(Rules, Ap, rule(_, _, ASyms, _, _, _, _)),
+ array.max(ASyms, AMax),
( Ad =< AMax ->
- array__lookup(ASyms, Ad, X),
+ array.lookup(ASyms, Ad, X),
( Gix = goto(Gotos, I, X) ->
Ad1 = Ad + 1,
( Alpha = (*) ->
@@ -422,63 +422,63 @@
make_items1(_, [], !Items).
make_items1(Bp, [Bt | Bts], !Items) :-
- list__append([item(Bp, 0, Bt)], !Items),
+ list.append([item(Bp, 0, Bt)], !Items),
make_items1(Bp, Bts, !Items).
:- func goto(gotos, items, symbol) = items.
:- mode (goto(in, in, in) = out) is semidet.
goto(Gotos, I, X) = A :-
- map__search(Gotos, I, IXs),
- map__search(IXs, X, A).
+ map.search(Gotos, I, IXs),
+ map.search(IXs, X, A).
:- pred add_propagated(items, item, items, item, previews, previews).
:- mode add_propagated(in, in, in, in, in, out) is det.
add_propagated(I, B, Ia, A, L - P0, L - P) :-
- ( map__search(P0, I, X0) ->
+ ( map.search(P0, I, X0) ->
X1 = X0
;
- map__init(X1)
+ map.init(X1)
),
- ( map__search(X1, B, Y0) ->
+ ( map.search(X1, B, Y0) ->
Y1 = Y0
;
- map__init(Y1)
+ map.init(Y1)
),
- ( map__search(Y1, Ia, As0) ->
+ ( map.search(Y1, Ia, As0) ->
As1 = As0
;
As1 = empty
),
- set__insert(As1, A, As),
- map__set(Y1, Ia, As, Y),
- map__set(X1, B, Y, X),
- map__set(P0, I, X, P).
+ set.insert(As1, A, As),
+ map.set(Y1, Ia, As, Y),
+ map.set(X1, B, Y, X),
+ map.set(P0, I, X, P).
:- pred add_spontaneous(items, item, terminal, previews, previews).
:- mode add_spontaneous(in, in, in, in, out) is det.
add_spontaneous(I, B, Alpha, L0 - P, L - P) :-
- ( map__search(L0, I, X0) ->
+ ( map.search(L0, I, X0) ->
X1 = X0
;
- map__init(X1)
+ map.init(X1)
),
- ( map__search(X1, B, As0) ->
+ ( map.search(X1, B, As0) ->
As1 = As0
;
As1 = empty
),
- set__insert(As1, Alpha, As),
- map__set(X1, B, As, X),
- map__set(L0, I, X, L).
+ set.insert(As1, Alpha, As),
+ map.set(X1, B, As, X),
+ map.set(L0, I, X, L).
:- pred propagate(set(items), propaheads, lookaheads, lookaheads).
:- mode propagate(in, in, in, out) is det.
propagate(C, Props, !Lookaheads) :-
- set__to_sorted_list(C, CList),
+ set.to_sorted_list(C, CList),
propagate(CList, Props, no, Change, !Lookaheads),
(
Change = no
@@ -492,7 +492,7 @@
propagate([], _Props, !Change, !Lookaheads).
propagate([I | Is], Props, !Change, !Lookaheads) :-
- set__to_sorted_list(I, IList),
+ set.to_sorted_list(I, IList),
propagate1(IList, I, Props, !Change, !Lookaheads),
propagate(Is, Props, !Change, !Lookaheads).
@@ -503,12 +503,12 @@
propagate1([], _I, _Props, !Change, !Lookaheads).
propagate1([Item | Items], I, Props, !Change, !Lookaheads) :-
(
- map__search(!.Lookaheads, I, X),
- map__search(X, Item, Ts),
- map__search(Props, I, Y),
- map__search(Y, Item, Ps)
+ map.search(!.Lookaheads, I, X),
+ map.search(X, Item, Ts),
+ map.search(Props, I, Y),
+ map.search(Y, Item, Ps)
->
- map__keys(Ps, Pkeys),
+ map.keys(Ps, Pkeys),
propagate2(Pkeys, Ps, Ts, !Change, !Lookaheads)
;
true
@@ -521,8 +521,8 @@
propagate2([], _Ps, _Ts, !Change, !Lookaheads).
propagate2([I|Pks], Ps, Ts, !Change, !Lookaheads) :-
- map__lookup(Ps, I, Ips),
- set__to_sorted_list(Ips, IPList),
+ map.lookup(Ps, I, Ips),
+ set.to_sorted_list(Ips, IPList),
propagate3(IPList, I, Ts, !Change, !Lookaheads),
propagate2(Pks, Ps, Ts, !Change, !Lookaheads).
@@ -532,21 +532,21 @@
propagate3([], _I, _Ts, !Change, !Lookaheads).
propagate3([Item | Items], I, Ts0, !Change, !Lookaheads) :-
- ( map__search(!.Lookaheads, I, X0) ->
+ ( map.search(!.Lookaheads, I, X0) ->
X1 = X0
;
- map__init(X1)
+ map.init(X1)
),
- ( map__search(X1, Item, Ts1) ->
+ ( map.search(X1, Item, Ts1) ->
Ts2 = Ts1
;
Ts2 = empty
),
NewTs = Ts0 - Ts2,
- ( not set__empty(NewTs) ->
+ ( not set.empty(NewTs) ->
Ts = Ts2 \/ NewTs,
- map__set(X1, Item, Ts, X),
- map__set(!.Lookaheads, I, X, !:Lookaheads),
+ map.set(X1, Item, Ts, X),
+ map.set(!.Lookaheads, I, X, !:Lookaheads),
!:Change = yes
;
true
@@ -559,6 +559,6 @@
:- mode prodnums(in, out) is det.
prodnums(Rules, ProdNums) :-
- map__keys(Rules, ProdNums).
+ map.keys(Rules, ProdNums).
%------------------------------------------------------------------------------%
Index: extras/moose/mercury_syntax.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/extras/moose/mercury_syntax.m,v
retrieving revision 1.5
diff -u -r1.5 mercury_syntax.m
--- extras/moose/mercury_syntax.m 5 Dec 2006 06:40:03 -0000 1.5
+++ extras/moose/mercury_syntax.m 21 Feb 2009 11:27:37 -0000
@@ -34,17 +34,17 @@
:- type module_error
---> error(string, int).
-:- pred read_module(module_result, io__state, io__state).
+:- pred read_module(module_result, io.state, io.state).
:- mode read_module(out, di, uo) is det.
:- type lines
---> lines
; nolines.
-:- pred write_element(lines, element, io__state, io__state).
+:- pred write_element(lines, element, io.state, io.state).
:- mode write_element(in, in, di, uo) is det.
-:- pred write_module(lines, (module), io__state, io__state).
+:- pred write_module(lines, (module), io.state, io.state).
:- mode write_module(in, in, di, uo) is det.
:- type (type)
@@ -71,7 +71,7 @@
:- pred term_to_goal(term, goal).
:- mode term_to_goal(in, out) is semidet.
-:- pred write_goal(varset, goal, io__state, io__state).
+:- pred write_goal(varset, goal, io.state, io.state).
:- mode write_goal(in, in, di, uo) is det.
:- type vars == list(var).
@@ -85,8 +85,8 @@
read_module(Result, !IO) :-
read_module([], [], Result0, !IO),
Result0 = module(Module0, Errors0),
- list__reverse(Module0, Module),
- list__reverse(Errors0, Errors),
+ list.reverse(Module0, Module),
+ list.reverse(Errors0, Errors),
Result = module(Module, Errors).
:- type element_result
@@ -95,7 +95,7 @@
; error(string, int).
:- pred read_module(module, list(module_error), module_result,
- io__state, io__state).
+ io.state, io.state).
:- mode read_module(in, in, out, di, uo) is det.
read_module(Module, Errors, Result, !IO) :-
@@ -111,7 +111,7 @@
read_module(Module, [error(Msg, Line) | Errors], Result, !IO)
).
-:- pred read_element(element_result, io__state, io__state).
+:- pred read_element(element_result, io.state, io.state).
:- mode read_element(out, di, uo) is det.
read_element(Result, !IO) :-
@@ -148,7 +148,7 @@
Element = mode(ModeDecl, VarSet)
;
Args = [functor(atom("type"), [TypeTerm], _)],
- ( mercury_syntax__term_to_type(TypeTerm, TypeDecl) ->
+ ( mercury_syntax.term_to_type(TypeTerm, TypeDecl) ->
Element = type(TypeDecl, VarSet)
;
Element = misc(Term, VarSet)
@@ -185,7 +185,7 @@
write_module(_Lines, [], !IO).
write_module(Lines, [Element | Module], !IO) :-
write_element(Lines, Element, !IO),
- io__nl(!IO),
+ io.nl(!IO),
write_module(Lines, Module, !IO).
write_element(Lines, pred(PredDecl, VarSet), !IO) :-
@@ -245,13 +245,13 @@
write_element(Lines, clause(Head, Goal, VarSet), !IO) :-
write_term(Lines, 0, VarSet, Head, !IO),
- io__write_string(" :-\n", !IO),
+ io.write_string(" :-\n", !IO),
write_goal(Lines, 1, normal, Goal, VarSet, !IO),
dot_nl(!IO).
write_element(Lines, dcg_clause(Head, Goal, VarSet), !IO) :-
write_term(Lines, 0, VarSet, Head, !IO),
- io__write_string(" -->\n", !IO),
+ io.write_string(" -->\n", !IO),
write_goal(Lines, 1, dcg, Goal, VarSet, !IO),
dot_nl(!IO).
@@ -290,23 +290,23 @@
%------------------------------------------------------------------------------%
-:- pred write_ind(int, io__state, io__state).
+:- pred write_ind(int, io.state, io.state).
:- mode write_ind(in, di, uo) is det.
write_ind(N, !IO) :-
( N > 0 ->
- io__write_string(" ", !IO),
+ io.write_string(" ", !IO),
write_ind(N - 1, !IO)
;
true
).
-:- pred dot_nl(io__state, io__state).
+:- pred dot_nl(io.state, io.state).
:- mode dot_nl(di, uo) is det.
-dot_nl(!IO) :- io__write_string(".\n", !IO).
+dot_nl(!IO) :- io.write_string(".\n", !IO).
-:- pred write_term(lines, int, varset, term, io__state, io__state).
+:- pred write_term(lines, int, varset, term, io.state, io.state).
:- mode write_term(in, in, in, in, di, uo) is det.
write_term(lines, Ind, VarSet, Term, !IO) :-
@@ -314,7 +314,7 @@
( File = "", Line = 0 ->
true
;
- io__format("#%d\n", [i(Line)], !IO)
+ io.format("#%d\n", [i(Line)], !IO)
),
write_ind(Ind, !IO),
write_term(VarSet, Term, !IO).
@@ -442,7 +442,7 @@
write_goal(VarSet, Goal, !IO) :-
write_goal(nolines, 1, normal, Goal, VarSet, !IO).
-:- pred write_goal(lines, int, goal_type, goal, varset, io__state, io__state).
+:- pred write_goal(lines, int, goal_type, goal, varset, io.state, io.state).
:- mode write_goal(in, in, in, in, in, di, uo) is det.
write_goal(Lines, Ind, _GoalType, call(Term), VarSet, !IO) :-
@@ -472,84 +472,84 @@
write_goal(Lines, Ind, GoalType, not(Goal), VarSet, !IO) :-
write_ind(Ind, !IO),
- io__write_string("not (\n", !IO),
+ io.write_string("not (\n", !IO),
write_goal(Lines, Ind + 1, GoalType, Goal, VarSet, !IO),
- io__nl(!IO),
+ io.nl(!IO),
write_ind(Ind, !IO),
- io__write_string(")", !IO).
+ io.write_string(")", !IO).
write_goal(Lines, Ind, GoalType, exists(Vars, Goal), VarSet, !IO) :-
write_ind(Ind, !IO),
- io__write_string("some [", !IO),
+ io.write_string("some [", !IO),
write_vars(Vars, VarSet, !IO),
- io__write_string("] (\n", !IO),
+ io.write_string("] (\n", !IO),
write_goal(Lines, Ind + 1, GoalType, Goal, VarSet, !IO),
- io__nl(!IO),
+ io.nl(!IO),
write_ind(Ind, !IO),
- io__write_string(")", !IO).
+ io.write_string(")", !IO).
write_goal(Lines, Ind, GoalType, forall(Vars, Goal), VarSet, !IO) :-
write_ind(Ind, !IO),
- io__write_string("all [", !IO),
+ io.write_string("all [", !IO),
write_vars(Vars, VarSet, !IO),
- io__write_string("] (\n", !IO),
+ io.write_string("] (\n", !IO),
write_goal(Lines, Ind + 1, GoalType, Goal, VarSet, !IO),
- io__nl(!IO),
+ io.nl(!IO),
write_ind(Ind, !IO),
- io__write_string(")", !IO).
+ io.write_string(")", !IO).
/*
write_goal(Lines, Ind, GoalType, (A => B), VarSet, !IO) :-
write_ind(Ind, !IO),
- io__write_string("((\n", !IO),
+ io.write_string("((\n", !IO),
write_goal(Lines, Ind, GoalType, A, VarSet, !IO),
- io__nl(!IO),
+ io.nl(!IO),
write_ind(Ind, !IO),
- io__write_string(") => (\n", !IO),
+ io.write_string(") => (\n", !IO),
write_goal(Lines, Ind, GoalType, A, VarSet, !IO),
- io__nl(!IO),
+ io.nl(!IO),
write_ind(Ind, !IO),
- io__write_string("))", !IO).
+ io.write_string("))", !IO).
*/
write_goal(Lines, Ind, GoalType, (A <= B), VarSet, !IO) :-
write_ind(Ind, !IO),
- io__write_string("((\n", !IO),
+ io.write_string("((\n", !IO),
write_goal(Lines, Ind, GoalType, A, VarSet, !IO),
- io__nl(!IO),
+ io.nl(!IO),
write_ind(Ind, !IO),
- io__write_string(") <= (\n", !IO),
+ io.write_string(") <= (\n", !IO),
write_goal(Lines, Ind, GoalType, B, VarSet, !IO),
- io__nl(!IO),
+ io.nl(!IO),
write_ind(Ind, !IO),
- io__write_string("))", !IO).
+ io.write_string("))", !IO).
write_goal(Lines, Ind, GoalType, (A <=> B), VarSet, !IO) :-
write_ind(Ind, !IO),
- io__write_string("((\n", !IO),
+ io.write_string("((\n", !IO),
write_goal(Lines, Ind, GoalType, A, VarSet, !IO),
- io__nl(!IO),
+ io.nl(!IO),
write_ind(Ind, !IO),
- io__write_string(") <=> (\n", !IO),
+ io.write_string(") <=> (\n", !IO),
write_goal(Lines, Ind, GoalType, B, VarSet, !IO),
- io__nl(!IO),
+ io.nl(!IO),
write_ind(Ind, !IO),
- io__write_string("))", !IO).
+ io.write_string("))", !IO).
%------------------------------------------------------------------------------%
:- pred write_conj(lines, int, goal_type, list(goal), varset,
- io__state, io__state).
+ io.state, io.state).
:- mode write_conj(in, in, in, in, in, di, uo) is det.
write_conj(_Lines, Ind, Type, [], _VarSet, !IO) :-
write_ind(Ind, !IO),
(
Type = normal,
- io__write_string("true", !IO)
+ io.write_string("true", !IO)
;
Type = dcg,
- io__write_string("{ true }", !IO)
+ io.write_string("{ true }", !IO)
).
write_conj(Lines, Ind, Type, [Goal], VarSet, !IO) :-
@@ -558,44 +558,44 @@
write_conj(Lines, Ind, Type, [Goal|Goals], VarSet, !IO) :-
Goals = [_|_],
write_goal(Lines, Ind, Type, Goal, VarSet, !IO),
- io__write_string(",\n", !IO),
+ io.write_string(",\n", !IO),
write_conj(Lines, Ind, Type, Goals, VarSet, !IO).
%------------------------------------------------------------------------------%
:- pred write_disj(lines, int, goal_type, list(goal), varset,
- io__state, io__state).
+ io.state, io.state).
:- mode write_disj(in, in, in, in, in, di, uo) is det.
write_disj(Lines, Ind, Type, Goals, VarSet, !IO) :-
write_ind(Ind, !IO),
- io__write_string("(\n", !IO),
- write_disj0(Lines, Ind, Type, Goals, VarSet, !IO), io__nl(!IO),
+ io.write_string("(\n", !IO),
+ write_disj0(Lines, Ind, Type, Goals, VarSet, !IO), io.nl(!IO),
write_ind(Ind, !IO),
- io__write_string(")", !IO).
+ io.write_string(")", !IO).
:- pred write_disj0(lines, int, goal_type, list(goal), varset,
- io__state, io__state).
+ io.state, io.state).
:- mode write_disj0(in, in, in, in, in, di, uo) is det.
write_disj0(_Lines, Ind, Type, [], _VarSet, !IO) :-
write_ind(Ind + 1, !IO),
(
Type = normal,
- io__write_string("fail", !IO)
+ io.write_string("fail", !IO)
;
Type = dcg,
- io__write_string("{ fail }", !IO)
+ io.write_string("{ fail }", !IO)
).
write_disj0(Lines, Ind, Type, [Goal], VarSet, !IO) :-
- write_goal(Lines, Ind + 1, Type, Goal, VarSet, !IO), io__nl(!IO).
+ write_goal(Lines, Ind + 1, Type, Goal, VarSet, !IO), io.nl(!IO).
write_disj0(Lines, Ind, Type, [Goal | Goals], VarSet, !IO) :-
Goals = [_|_],
- write_goal(Lines, Ind + 1, Type, Goal, VarSet, !IO), io__nl(!IO),
+ write_goal(Lines, Ind + 1, Type, Goal, VarSet, !IO), io.nl(!IO),
write_ind(Ind, !IO),
- io__write_string(";\n", !IO),
+ io.write_string(";\n", !IO),
write_disj0(Lines, Ind, Type, Goals, VarSet, !IO).
%------------------------------------------------------------------------------%
@@ -613,56 +613,56 @@
).
:- pred write_ite(lines, int, goal_type, list(pair(goal)), goal, varset,
- io__state, io__state).
+ io.state, io.state).
:- mode write_ite(in, in, in, in, in, in, di, uo) is det.
write_ite(Lines, Ind, Type, IfThens, Else, VarSet, !IO) :-
write_ind(Ind, !IO),
- io__write_string("(\n", !IO),
+ io.write_string("(\n", !IO),
write_ite0(Lines, Ind, Type, IfThens, VarSet, !IO),
write_ind(Ind, !IO),
- io__write_string(";\n", !IO),
+ io.write_string(";\n", !IO),
write_goal(Lines, Ind + 1, Type, Else, VarSet, !IO),
- io__nl(!IO),
+ io.nl(!IO),
write_ind(Ind, !IO),
- io__write_string(")", !IO).
+ io.write_string(")", !IO).
:- pred write_ite0(lines, int, goal_type, list(pair(goal)), varset,
- io__state, io__state).
+ io.state, io.state).
:- mode write_ite0(in, in, in, in, in, di, uo) is det.
write_ite0(_Lines, _Ind, _Type, [], _VarSet, !IO) :-
error("no if-thens").
write_ite0(Lines, Ind, Type, [If - Then], VarSet, !IO) :-
write_goal(Lines, Ind + 1, Type, If, VarSet, !IO),
- io__nl(!IO),
+ io.nl(!IO),
write_ind(Ind, !IO),
- io__write_string("->\n", !IO),
+ io.write_string("->\n", !IO),
write_goal(Lines, Ind + 1, Type, Then, VarSet, !IO),
- io__nl(!IO).
+ io.nl(!IO).
write_ite0(Lines, Ind, Type, [If - Then | Rest], VarSet, !IO) :-
Rest = [_|_],
write_goal(Lines, Ind + 1, Type, If, VarSet, !IO),
- io__nl(!IO),
+ io.nl(!IO),
write_ind(Ind, !IO),
- io__write_string("->\n", !IO),
+ io.write_string("->\n", !IO),
write_goal(Lines, Ind + 1, Type, Then, VarSet, !IO),
- io__nl(!IO),
+ io.nl(!IO),
write_ind(Ind, !IO),
- io__write_string(";\n", !IO),
+ io.write_string(";\n", !IO),
write_ite0(Lines, Ind, Type, Rest, VarSet, !IO).
%------------------------------------------------------------------------------%
-:- pred write_vars(vars, varset, io__state, io__state).
+:- pred write_vars(vars, varset, io.state, io.state).
:- mode write_vars(in, in, di, uo) is det.
write_vars([], _, !IO).
write_vars([V], VarSet, !IO) :-
- term_io__write_variable(V, VarSet, !IO).
+ term_io.write_variable(V, VarSet, !IO).
write_vars([V | Vs], VarSet, !IO) :-
Vs = [_|_],
- term_io__write_variable(V, VarSet, !IO),
- io__write_string(", ", !IO),
+ term_io.write_variable(V, VarSet, !IO),
+ io.write_string(", ", !IO),
write_vars(Vs, VarSet, !IO).
Index: extras/moose/misc.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/extras/moose/misc.m,v
retrieving revision 1.3
diff -u -r1.3 misc.m
--- extras/moose/misc.m 30 Mar 2006 01:21:18 -0000 1.3
+++ extras/moose/misc.m 21 Feb 2009 11:27:37 -0000
@@ -30,12 +30,12 @@
:- implementation.
empty = Empty :-
- set__init(Empty).
+ set.init(Empty).
-{ Elem } = Set :- set__singleton_set(Set, Elem).
+{ Elem } = Set :- set.singleton_set(Set, Elem).
-A /\ B = C :- set__intersect(A, B, C).
+A /\ B = C :- set.intersect(A, B, C).
-A \/ B = C :- set__union(A, B, C).
+A \/ B = C :- set.union(A, B, C).
-A - B = C :- set__difference(A, B, C).
+A - B = C :- set.difference(A, B, C).
Index: extras/moose/moose.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/extras/moose/moose.m,v
retrieving revision 1.11
diff -u -r1.11 moose.m
--- extras/moose/moose.m 5 Dec 2006 06:40:03 -0000 1.11
+++ extras/moose/moose.m 21 Feb 2009 11:27:38 -0000
@@ -17,7 +17,7 @@
:- import_module io.
-:- pred main(io__state::di, io__state::uo) is det.
+:- pred main(io::di, io::uo) is det.
:- implementation.
@@ -26,363 +26,364 @@
:- import_module set, pair, string, term, term_io, varset.
main(!IO) :-
- parse_options(MOptions, Args, !IO),
- (
- MOptions = ok(Options),
- lookup_bool_option(Options, help, Help),
- ( Help = yes ->
- help(!IO)
- ;
- main2(Options, Args, !IO)
- )
- ;
- MOptions = error(String),
- io__stderr_stream(StdErr, !IO),
- io__write_string(StdErr, String, !IO),
- nl(StdErr, !IO)
- ).
+ parse_options(MOptions, Args, !IO),
+ (
+ MOptions = ok(Options),
+ lookup_bool_option(Options, help, Help),
+ ( Help = yes ->
+ help(!IO)
+ ;
+ main2(Options, Args, !IO)
+ )
+ ;
+ MOptions = error(String),
+ report_critical_error(String, !IO)
+ ).
-:- pred main2(options::in, list(string)::in, io__state::di, io__state::uo).
+:- pred report_critical_error(string::in, io::di, io::uo) is det.
+
+report_critical_error(Message, !IO) :-
+ io.stderr_stream(StdErr, !IO),
+ io.write_string(StdErr, Message, !IO),
+ io.nl(StdErr, !IO),
+ io.set_exit_status(1, !IO).
+
+:- pred main2(options::in, list(string)::in, io::di, io::uo).
main2(_Options, [], !IO) :-
- io__stderr_stream(StdErr, !IO),
- io__write_string(StdErr, "no input files.\n", !IO),
- help(!IO).
+ report_critical_error("no input files.", !IO),
+ help(!IO).
main2(Options, [Name0 | Names], !IO) :-
- figure_out_names(Name0, InName, OutName),
- io__see(InName, Res0, !IO),
- (
- Res0 = ok,
- io__tell(OutName, Res1, !IO),
- (
- Res1 = ok,
- process(Options, !IO),
- io__told(!IO)
- ;
- Res1 = error(Err),
- io__error_message(Err, Msg),
- io__stderr_stream(StdErr, !IO),
- io__write_string(StdErr, Msg, !IO),
- nl(StdErr, !IO)
- )
- ;
- Res0 = error(Err),
- io__error_message(Err, Msg),
- io__stderr_stream(StdErr, !IO),
- io__write_string(StdErr, Msg, !IO),
- nl(StdErr, !IO)
- ),
- ( Names = [_|_] ->
- main2(Options, Names, !IO)
- ;
- true
- ).
+ figure_out_names(Name0, InName, OutName),
+ io.see(InName, Res0, !IO),
+ (
+ Res0 = ok,
+ io.tell(OutName, Res1, !IO),
+ (
+ Res1 = ok,
+ process(Options, !IO),
+ io.told(!IO)
+ ;
+ Res1 = error(Err),
+ io.error_message(Err, Msg),
+ report_critical_error(Msg, !IO)
+ )
+ ;
+ Res0 = error(Err),
+ io.error_message(Err, Msg),
+ report_critical_error(Msg, !IO)
+ ),
+ ( Names = [_|_] ->
+ main2(Options, Names, !IO)
+ ;
+ true
+ ).
:- pred figure_out_names(string::in, string::out, string::out) is det.
figure_out_names(Name0, InName, OutName) :-
- ( string__remove_suffix(Name0, ".moo", Name1) ->
- Name = Name1
- ;
- Name = Name0
- ),
- string__append(Name, ".moo", InName),
- string__append(Name, ".m", OutName).
+ ( string.remove_suffix(Name0, ".moo", Name1) ->
+ Name = Name1
+ ;
+ Name = Name0
+ ),
+ string.append(Name, ".moo", InName),
+ string.append(Name, ".m", OutName).
:- type whereami
- ---> (interface) ; (implementation) .
+ ---> (interface) ; (implementation) .
:- type parser
- ---> parser(
- whereami,
- nonterminal, % Starting nonterminal.
- term, % EOF token.
- string, % Token type name.
- string, % Naming prefix (unused).
- string, % Parser state input mode.
- string % Parser state output mode.
- ).
+ ---> parser(
+ whereami,
+ nonterminal, % Starting nonterminal.
+ term, % EOF token.
+ string, % Token type name.
+ string, % Naming prefix (unused).
+ string, % Parser state input mode.
+ string % Parser state output mode.
+ ).
-:- pred process(options::in, io__state::di, io__state::uo) is det.
+:- pred process(options::in, io.state::di, io.state::uo) is det.
process(Options, !IO) :-
- lookup_bool_option(Options, verbose, Verbse),
- ( Verbse = yes -> report_stats(!IO) ; true ),
- read_module(Result, !IO),
- Result = module(Module, Errors),
- (
- Errors = [_|_],
- io__stderr_stream(StdErr, !IO),
- list__foldl((pred(Err::in, !.IO::di, !:IO::uo) is det :-
- Err = error(Msg, Line),
- io__format(StdErr, "%d: %s\n", [i(Line), s(Msg)], !IO)
- ), Errors, !IO)
- ;
- Errors = [],
- get_moose_elements(Module, [], Remainder0, (implementation),
- [], MParser, [], RuleDecls, [], ClauseList,
- [], XFormList),
- (
- MParser = [],
- io__stderr_stream(StdErr, !IO),
- io__write_string(StdErr,
- "error: no parse/6 declaration.\n", !IO)
- ;
- MParser = [Parser],
- list__reverse(Remainder0, Remainder),
- process_2(Options, Remainder, Parser,
- RuleDecls, ClauseList, XFormList, !IO)
- ;
- MParser = [_,_|_],
- io__stderr_stream(StdErr, !IO),
- io__write_string(StdErr,
- "error: more than one parse/4 declaration.\n",
- !IO)
- )
- ).
+ lookup_bool_option(Options, verbose, Verbse),
+ ( Verbse = yes -> report_stats(!IO) ; true ),
+ read_module(Result, !IO),
+ Result = module(Module, Errors),
+ (
+ Errors = [_|_],
+ io.stderr_stream(StdErr, !IO),
+ list.foldl((pred(Err::in, !.IO::di, !:IO::uo) is det :-
+ Err = error(Msg, Line),
+ io.format(StdErr, "%d: %s\n", [i(Line), s(Msg)], !IO)
+ ), Errors, !IO),
+ io.set_exit_status(1, !IO)
+ ;
+ Errors = [],
+ get_moose_elements(Module, [], Remainder0, (implementation),
+ [], MParser, [], RuleDecls, [], ClauseList,
+ [], XFormList),
+ (
+ MParser = [],
+ report_critical_error("error: no parse/6 declaration.", !IO)
+ ;
+ MParser = [Parser],
+ list.reverse(Remainder0, Remainder),
+ process_2(Options, Remainder, Parser,
+ RuleDecls, ClauseList, XFormList, !IO)
+ ;
+ MParser = [_,_|_],
+ report_critical_error("error: more than one parse/4 declaration.",
+ !IO)
+ )
+ ).
:- pred process_2(options, (module), parser, list(rule_decl), list(clause),
- list(xform), io__state, io__state).
+ list(xform), io, io).
:- mode process_2(in, in, in, in, in, in, di, uo) is det.
process_2(Options, Module, Parser, Decls0, Clauses0, XFormList, !IO) :-
- lookup_bool_option(Options, verbose, Verbse),
- ( Verbse = yes -> report_stats(!IO) ; true ),
+ lookup_bool_option(Options, verbose, Verbse),
+ ( Verbse = yes -> report_stats(!IO) ; true ),
+
+ check_rule_decls(Decls0, Decls, DeclErrors),
+ list.foldl(write_error, DeclErrors, !IO),
- check_rule_decls(Decls0, Decls, DeclErrors),
- list__foldl(write_error, DeclErrors, !IO),
+ check_clauses(Clauses0, Decls, Clauses, ClauseErrors),
+ list.foldl(write_error, ClauseErrors, !IO),
- check_clauses(Clauses0, Decls, Clauses, ClauseErrors),
- list__foldl(write_error, ClauseErrors, !IO),
+ Parser = parser(WhereAmI, StartId, EndTerm, TokenType, _Prefix, InAtom,
+ OutAtom),
- Parser = parser(WhereAmI, StartId, EndTerm, TokenType, _Prefix, InAtom,
- OutAtom),
-
- check_useless(StartId, Clauses, Decls, UselessErrors),
- list__foldl(write_error, UselessErrors, !IO),
-
- check_inf_derivations(Clauses, Decls, InfErrors),
- list__foldl(write_error, InfErrors, !IO),
-
- (
- DeclErrors = [],
- ClauseErrors = [],
- UselessErrors = [],
- InfErrors = []
- ->
- write_module(nolines, Module, !IO), io__nl(!IO),
- map__lookup(Decls, StartId, StartDecl),
- write_parser(WhereAmI, StartId, StartDecl, TokenType,
- InAtom, OutAtom, !IO),
- write_action_type_class(WhereAmI, XFormList, Decls,
- TokenType, InAtom, OutAtom, !IO),
-
- io__stderr_stream(StdErr, !IO),
- io__write_string(StdErr, "constructing grammar...\n", !IO),
-
- map__init(Xfns0),
- list__foldl((pred(XForm::in, Xf0::in, Xf::out) is det :-
- XForm = xform(XfNt, _),
- map__det_insert(Xf0, XfNt, XForm, Xf)
- ), XFormList, Xfns0, XForms),
-
- construct_grammar(StartId, Clauses, XForms, Grammar),
- Grammar = grammar(Rules, _, Xfns, _, Index, First, _Follow),
- reaching(Rules, First, Reaching),
-
- io__write_string(StdErr, "constructing lr(0) items...\n", !IO),
- lr0items(Rules, Reaching, C, Gotos),
- io__write_string(StdErr, "determining lookaheads...\n", !IO),
- lookaheads(C, Gotos, Rules, First, Index, Lookaheads, !IO),
- io__write_string(StdErr, "computing the action table...\n",
- !IO),
- shifts(C, Rules, First, Reaching, Shifts),
- actions(C, Rules, Lookaheads, Gotos, Shifts, States,
- ActionTable, ActionErrs),
- list__foldl2(
- (pred(Err::in, HasEs0::in, HasEs::out, !.IO::di,
- !:IO::uo) is det :-
- (
- Err = warning(Warning),
- HasEs = HasEs0,
- (
- Warning = shiftreduce(_S, Rp),
- io__write_string(StdErr,
- "shift reduce conflict involving:\n\t", !IO),
- write_rule(StdErr, Rp, Rules, !IO)
- )
- ;
- Err = error(Error),
- HasEs = yes,
- (
- Error = shiftshift(_, _),
- io__write_string(StdErr,
- "shift shift error.\n", !IO)
- ;
- Error = reducereduce(R0, R1),
- io__write_string(StdErr,
- "reduce reduce conflict involving:\n\t",
- !IO),
- write_rule(StdErr, R0, Rules, !IO),
- io__write_string(StdErr, "\t", !IO),
- write_rule(StdErr, R1, Rules, !IO)
- ;
- Error = misc(Ac1, Ac2),
- io__write_string(StdErr,
- "misc conflict involving:\n\t",
- !IO),
- io__write(StdErr, Ac1, !IO),
- io__write_string(StdErr, "\n\t", !IO),
- io__write(StdErr, Ac2, !IO),
- io__write_string(StdErr, "\n", !IO)
- )
- )
- ), ActionErrs, no, _HasErrors, !IO),
- write_action_table(ActionTable, TokenType, EndTerm, !IO),
- io__write_string(StdErr, "computing the goto table...\n", !IO),
- gotos(C, States, Gotos, GotoTable),
- write_goto_table(GotoTable, Decls, !IO),
- write_reductions(Rules, ActionTable, TokenType, InAtom,
- OutAtom, Xfns, !IO)
- ;
- true
- ).
+ check_useless(StartId, Clauses, Decls, UselessErrors),
+ list.foldl(write_error, UselessErrors, !IO),
+
+ check_inf_derivations(Clauses, Decls, InfErrors),
+ list.foldl(write_error, InfErrors, !IO),
+
+ (
+ DeclErrors = [],
+ ClauseErrors = [],
+ UselessErrors = [],
+ InfErrors = []
+ ->
+ write_module(nolines, Module, !IO), io.nl(!IO),
+ map.lookup(Decls, StartId, StartDecl),
+ write_parser(WhereAmI, StartId, StartDecl, TokenType,
+ InAtom, OutAtom, !IO),
+ write_action_type_class(WhereAmI, XFormList, Decls,
+ TokenType, InAtom, OutAtom, !IO),
+
+ io.stderr_stream(StdErr, !IO),
+ io.write_string(StdErr, "constructing grammar...\n", !IO),
+
+ map.init(Xfns0),
+ list.foldl((pred(XForm::in, Xf0::in, Xf::out) is det :-
+ XForm = xform(XfNt, _),
+ map.det_insert(Xf0, XfNt, XForm, Xf)
+ ), XFormList, Xfns0, XForms),
+
+ construct_grammar(StartId, Clauses, XForms, Grammar),
+ Grammar = grammar(Rules, _, Xfns, _, Index, First, _Follow),
+ reaching(Rules, First, Reaching),
+
+ io.write_string(StdErr, "constructing lr(0) items...\n", !IO),
+ lr0items(Rules, Reaching, C, Gotos),
+ io.write_string(StdErr, "determining lookaheads...\n", !IO),
+ lookaheads(C, Gotos, Rules, First, Index, Lookaheads, !IO),
+ io.write_string(StdErr, "computing the action table...\n",
+ !IO),
+ shifts(C, Rules, First, Reaching, Shifts),
+ actions(C, Rules, Lookaheads, Gotos, Shifts, States,
+ ActionTable, ActionErrs),
+ list.foldl2(
+ (pred(Err::in, HasEs0::in, HasEs::out, !.IO::di,
+ !:IO::uo) is det :-
+ (
+ Err = warning(Warning),
+ HasEs = HasEs0,
+ (
+ Warning = shiftreduce(_S, Rp),
+ io.write_string(StdErr,
+ "shift reduce conflict involving:\n\t", !IO),
+ write_rule(StdErr, Rp, Rules, !IO)
+ )
+ ;
+ Err = error(Error),
+ HasEs = yes,
+ (
+ Error = shiftshift(_, _),
+ io.write_string(StdErr,
+ "shift shift error.\n", !IO)
+ ;
+ Error = reducereduce(R0, R1),
+ io.write_string(StdErr,
+ "reduce reduce conflict involving:\n\t",
+ !IO),
+ write_rule(StdErr, R0, Rules, !IO),
+ io.write_string(StdErr, "\t", !IO),
+ write_rule(StdErr, R1, Rules, !IO)
+ ;
+ Error = misc(Ac1, Ac2),
+ io.write_string(StdErr,
+ "misc conflict involving:\n\t",
+ !IO),
+ io.write(StdErr, Ac1, !IO),
+ io.write_string(StdErr, "\n\t", !IO),
+ io.write(StdErr, Ac2, !IO),
+ io.write_string(StdErr, "\n", !IO)
+ ),
+ io.set_exit_status(1, !IO)
+ )
+ ), ActionErrs, no, _HasErrors, !IO),
+ write_action_table(ActionTable, TokenType, EndTerm, !IO),
+ io.write_string(StdErr, "computing the goto table...\n", !IO),
+ gotos(C, States, Gotos, GotoTable),
+ write_goto_table(GotoTable, Decls, !IO),
+ write_reductions(Rules, ActionTable, TokenType, InAtom,
+ OutAtom, Xfns, !IO)
+ ;
+ % XXX: What is this condition? Should an exception be thrown here?!?
+ true,
+ io.set_exit_status(1, !IO)
+ ).
%------------------------------------------------------------------------------%
:- pred write_action_type_class(whereami, list(xform), rule_decls,
- string, string, string, io__state, io__state).
+ string, string, string, io, io).
:- mode write_action_type_class(in, in, in, in, in, in, di, uo) is det.
write_action_type_class(Where, XForms, Decls, TokenType, InAtom, OutAtom,
- !IO) :-
- ( Where = (interface) ->
- io__write_string(":- interface.\n\n", !IO)
- ;
- true
- ),
- io__format("\
+ !IO) :-
+ ( Where = (interface) ->
+ io.write_string(":- interface.\n\n", !IO)
+ ;
+ true
+ ),
+ io.format("\
:- typeclass parser_state(T) where [
- pred get_token(%s, T, T),
- mode get_token(out, %s, %s) is det,
- func unget_token(%s, T) = T,
- mode unget_token(in, %s) = %s is det\
-",
- [s(TokenType), s(InAtom), s(OutAtom),
- s(TokenType), s(InAtom), s(OutAtom)], !IO
- ),
- ( not XForms = [] ->
- io__write_string(",\n", !IO)
- ;
- true
- ),
- WriteIn = (pred(_Anything::in, !.IO::di, !:IO::uo) is det :-
- io__write_string("in", !IO)
- ),
- WriteXForm = (pred(XForm::in, !.IO::di, !:IO::uo) is det :-
- XForm = xform(NT, MethodName),
- map__lookup(Decls, NT, RuleDecl),
- RuleDecl = rule(_NT, Types, VarSet, _Context),
- io__format("\tfunc %s(", [s(MethodName)], !IO),
- io__write_list(Types, ", ", term_io__write_term(VarSet), !IO),
- ( Types \= [] -> io__write_string(", ", !IO) ; true ),
- io__write_string("T) = T,\n", !IO),
-
- io__format("\tmode %s(", [s(MethodName)], !IO),
- io__write_list(Types, ", ", WriteIn, !IO),
- ( Types \= [] -> io__write_string(", ", !IO) ; true ),
- io__format("%s) = %s is det", [s(InAtom), s(OutAtom)], !IO)
- ),
- io__write_list(XForms, ",\n", WriteXForm, !IO),
- io__write_string("\n].\n", !IO),
- ( Where = (interface) ->
- io__write_string(":- implementation.\n\n", !IO)
- ;
- true
- ).
+ pred get_token(%s, T, T),
+ mode get_token(out, %s, %s) is det,
+ func unget_token(%s, T) = T,
+ mode unget_token(in, %s) = %s is det\
+",
+ [s(TokenType), s(InAtom), s(OutAtom),
+ s(TokenType), s(InAtom), s(OutAtom)], !IO
+ ),
+ ( not XForms = [] ->
+ io.write_string(",\n", !IO)
+ ;
+ true
+ ),
+ WriteIn = (pred(_Anything::in, !.IO::di, !:IO::uo) is det :-
+ io.write_string("in", !IO)
+ ),
+ WriteXForm = (pred(XForm::in, !.IO::di, !:IO::uo) is det :-
+ XForm = xform(NT, MethodName),
+ map.lookup(Decls, NT, RuleDecl),
+ RuleDecl = rule(_NT, Types, VarSet, _Context),
+ io.format("\tfunc %s(", [s(MethodName)], !IO),
+ io.write_list(Types, ", ", term_io.write_term(VarSet), !IO),
+ ( Types \= [] -> io.write_string(", ", !IO) ; true ),
+ io.write_string("T) = T,\n", !IO),
+
+ io.format("\tmode %s(", [s(MethodName)], !IO),
+ io.write_list(Types, ", ", WriteIn, !IO),
+ ( Types \= [] -> io.write_string(", ", !IO) ; true ),
+ io.format("%s) = %s is det", [s(InAtom), s(OutAtom)], !IO)
+ ),
+ io.write_list(XForms, ",\n", WriteXForm, !IO),
+ io.write_string("\n].\n", !IO),
+ ( Where = (interface) ->
+ io.write_string(":- implementation.\n\n", !IO)
+ ;
+ true
+ ).
%------------------------------------------------------------------------------%
-:- pred write_rule(output_stream, int, rules, io__state, io__state).
+:- pred write_rule(output_stream, int, rules, io, io).
:- mode write_rule(in, in, in, di, uo) is det.
write_rule(Stream, RN, Rules, !IO) :-
- map__lookup(Rules, RN, Rule),
- io__write_int(Stream, RN, !IO),
- io__write_string(Stream, ": ", !IO),
- Rule = rule(NT, _, Syms, _, _, _, _),
- io__write(Stream, NT, !IO),
- io__write_string(Stream, " ->\t", !IO),
- write_syms(Stream, 0, 999, Syms, !IO),
- io__write_string(Stream, "\n", !IO).
+ map.lookup(Rules, RN, Rule),
+ io.write_int(Stream, RN, !IO),
+ io.write_string(Stream, ": ", !IO),
+ Rule = rule(NT, _, Syms, _, _, _, _),
+ io.write(Stream, NT, !IO),
+ io.write_string(Stream, " ->\t", !IO),
+ write_syms(Stream, 0, 999, Syms, !IO),
+ io.write_string(Stream, "\n", !IO).
-:- pred write_syms(output_stream, int, int, symbols, io__state, io__state).
+:- pred write_syms(output_stream, int, int, symbols, io, io).
:- mode write_syms(in, in, in, in, di, uo) is det.
write_syms(Stream, N, Dot, Syms, !IO) :-
- ( N = Dot ->
- io__write_string(Stream, ". ", !IO)
- ;
- true
- ),
- array__max(Syms, Max),
- ( N =< Max ->
- array__lookup(Syms, N, Sym),
- io__write(Stream, Sym, !IO),
- io__write_string(Stream, " ", !IO),
- write_syms(Stream, N + 1, Dot, Syms, !IO)
- ;
- true
- ).
+ ( N = Dot ->
+ io.write_string(Stream, ". ", !IO)
+ ;
+ true
+ ),
+ array.max(Syms, Max),
+ ( N =< Max ->
+ array.lookup(Syms, N, Sym),
+ io.write(Stream, Sym, !IO),
+ io.write_string(Stream, " ", !IO),
+ write_syms(Stream, N + 1, Dot, Syms, !IO)
+ ;
+ true
+ ).
%------------------------------------------------------------------------------%
:- pred get_moose_elements((module), (module), (module), whereami,
- list(parser), list(parser), list(rule_decl), list(rule_decl),
- list(clause), list(clause), list(xform), list(xform)).
+ list(parser), list(parser), list(rule_decl), list(rule_decl),
+ list(clause), list(clause), list(xform), list(xform)).
:- mode get_moose_elements(in, in, out, in, in, out, in, out, in, out,
- in, out) is det.
+ in, out) is det.
get_moose_elements([], !Remainder, _, !MParser, !RuleDecls, !Clauses, !Actions).
get_moose_elements([Element | Elements], !Remainder, !.WhereAmI, !MParser,
- !RuleDecls, !Clauses, !Actions) :-
- (
- Element = misc(ClauseTerm, ClauseVarSet),
- term_to_clause(ClauseTerm, ClauseVarSet, _, Clause)
- ->
- list.append([Clause], !Clauses)
- ;
- Element = misc(MiscTerm0, _),
- interface_term(MiscTerm0)
- ->
- !:WhereAmI = (interface),
- list.append([Element], !Remainder)
- ;
- Element = misc(MiscTerm1, _),
- implementation_term(MiscTerm1)
- ->
- !:WhereAmI = (implementation),
- list.append([Element], !Remainder)
- ;
- Element = misc(MiscTerm2, MiscVarSet2),
- rule_term(MiscTerm2, MiscVarSet2, RuleDecl)
- ->
- list.append([RuleDecl], !RuleDecls)
- ;
- Element = misc(MiscTerm3, MiscVarSet3),
- parser_term(MiscTerm3, MiscVarSet3, !.WhereAmI, Parser)
- ->
- list.append([Parser], !MParser)
- ;
- Element = misc(MiscTerm4, _),
- xform_term(MiscTerm4, XForm)
- ->
- list.append([XForm], !Actions)
- ;
- list.append([Element], !Remainder)
- ),
- get_moose_elements(Elements, !Remainder, !.WhereAmI, !MParser,
- !RuleDecls, !Clauses, !Actions).
+ !RuleDecls, !Clauses, !Actions) :-
+ (
+ Element = misc(ClauseTerm, ClauseVarSet),
+ term_to_clause(ClauseTerm, ClauseVarSet, _, Clause)
+ ->
+ list.append([Clause], !Clauses)
+ ;
+ Element = misc(MiscTerm0, _),
+ interface_term(MiscTerm0)
+ ->
+ !:WhereAmI = (interface),
+ list.append([Element], !Remainder)
+ ;
+ Element = misc(MiscTerm1, _),
+ implementation_term(MiscTerm1)
+ ->
+ !:WhereAmI = (implementation),
+ list.append([Element], !Remainder)
+ ;
+ Element = misc(MiscTerm2, MiscVarSet2),
+ rule_term(MiscTerm2, MiscVarSet2, RuleDecl)
+ ->
+ list.append([RuleDecl], !RuleDecls)
+ ;
+ Element = misc(MiscTerm3, MiscVarSet3),
+ parser_term(MiscTerm3, MiscVarSet3, !.WhereAmI, Parser)
+ ->
+ list.append([Parser], !MParser)
+ ;
+ Element = misc(MiscTerm4, _),
+ xform_term(MiscTerm4, XForm)
+ ->
+ list.append([XForm], !Actions)
+ ;
+ list.append([Element], !Remainder)
+ ),
+ get_moose_elements(Elements, !Remainder, !.WhereAmI, !MParser,
+ !RuleDecls, !Clauses, !Actions).
:- pred interface_term(term::in) is semidet.
@@ -391,276 +392,275 @@
:- pred implementation_term(term::in) is semidet.
implementation_term(functor(atom(":-"),
- [functor(atom("implementation"), [], _)], _)).
+ [functor(atom("implementation"), [], _)], _)).
:- pred rule_term(term, varset, rule_decl).
:- mode rule_term(in, in, out) is semidet.
rule_term(functor(atom(":-"), [functor(atom("rule"), [RuleTerm], _)], _),
- VarSet, Decl) :-
- RuleTerm = functor(atom(Name), Args, Context),
- list__length(Args, Arity),
- Decl = rule(Name/Arity, Args, VarSet, Context).
+ VarSet, Decl) :-
+ RuleTerm = functor(atom(Name), Args, Context),
+ list.length(Args, Arity),
+ Decl = rule(Name/Arity, Args, VarSet, Context).
:- pred parser_term(term, varset, whereami, parser).
:- mode parser_term(in, in, in, out) is semidet.
parser_term(functor(atom(":-"), [functor(atom("parse"), Args, _)], _),
- _VarSet, WhereAmI, Decl) :-
- Args = [StartIdTerm, TokTerm, EndTerm, PrefixTerm, InAtomTerm,
- OutAtomTerm],
- StartIdTerm = functor(atom("/"), [functor(atom(Name), [], _),
- functor(integer(Arity), _, _)], _),
- StartId = Name / Arity,
- TokTerm = functor(atom(TokAtom), [], _),
- PrefixTerm = functor(atom(PrefixAtom), [], _),
- InAtomTerm = functor(atom(InAtom), [], _),
- OutAtomTerm = functor(atom(OutAtom), [], _),
- Decl = parser(WhereAmI, StartId, EndTerm, TokAtom, PrefixAtom, InAtom,
- OutAtom).
+ _VarSet, WhereAmI, Decl) :-
+ Args = [StartIdTerm, TokTerm, EndTerm, PrefixTerm, InAtomTerm,
+ OutAtomTerm],
+ StartIdTerm = functor(atom("/"), [functor(atom(Name), [], _),
+ functor(integer(Arity), _, _)], _),
+ StartId = Name / Arity,
+ TokTerm = functor(atom(TokAtom), [], _),
+ PrefixTerm = functor(atom(PrefixAtom), [], _),
+ InAtomTerm = functor(atom(InAtom), [], _),
+ OutAtomTerm = functor(atom(OutAtom), [], _),
+ Decl = parser(WhereAmI, StartId, EndTerm, TokAtom, PrefixAtom, InAtom,
+ OutAtom).
:- pred xform_term(term, xform).
:- mode xform_term(in, out) is semidet.
xform_term(Term, XForm) :-
- Term = functor(atom(":-"), [
- functor(atom("action"), [
- functor(atom("/"), [
- functor(atom(Name), [], _),
- functor(integer(Arity), _, _)
- ], _),
- functor(atom(Pred), [], _)
- ], _)
- ], _),
- XForm = xform(Name/Arity, Pred).
+ Term = functor(atom(":-"), [
+ functor(atom("action"), [
+ functor(atom("/"), [
+ functor(atom(Name), [], _),
+ functor(integer(Arity), _, _)
+ ], _),
+ functor(atom(Pred), [], _)
+ ], _)
+ ], _),
+ XForm = xform(Name/Arity, Pred).
%------------------------------------------------------------------------------%
-:- pred help(io__state, io__state).
+:- pred help(io, io).
:- mode help(di, uo) is det.
help(!IO) :-
- io__stderr_stream(StdErr, !IO),
- io__write_string(StdErr, "\
+ io.stderr_stream(StdErr, !IO),
+ io.write_string(StdErr, "\
usage: moose <options> file ...
- -h|--help help
- -a|--dump-action dump the action table
- -f|--dump-first dump the FIRST sets
- -a|--dump-follow dump the FOLLOW sets
- -a|--dump-goto dump the goto table
- -a|--dump-items dump the item sets
- -a|--dump-rules dump the flattened rules
+ -h|--help help
+ -a|--dump-action dump the action table
+ -f|--dump-first dump the FIRST sets
+ -a|--dump-follow dump the FOLLOW sets
+ -a|--dump-goto dump the goto table
+ -a|--dump-items dump the item sets
+ -a|--dump-rules dump the flattened rules
", !IO).
%------------------------------------------------------------------------------%
-:- pred write_action_table(actiontable, string, term, io__state, io__state).
+:- pred write_action_table(actiontable, string, term, io, io).
:- mode write_action_table(in, in, in, di, uo) is det.
write_action_table(Table, TT, End, !IO) :-
- io__format(":- inst state_no --->\n\t\t", [], !IO),
- io__write_list(map__keys(Table), "\n\t;\t", io__write_int, !IO),
- io__format(".\n:- inst state_nos == list_skel(state_no).\n\n", [], !IO),
- io__format("\
+ io.format(":- inst state_no --->\n\t\t", [], !IO),
+ io.write_list(map.keys(Table), "\n\t;\t", io.write_int, !IO),
+ io.format(".\n:- inst state_nos == list_skel(state_no).\n\n", [], !IO),
+ io.format("\
:- type parsing_action
- ---> shift
- ; reduce
- ; accept.
+ ---> shift
+ ; reduce
+ ; accept.
:- pred actions(int, %s, parsing_action, int).
:- mode actions(in(state_no), in, out, out(state_no)) is semidet.
",
- [s(TT)],
- !IO),
- map__foldl((pred(State::in, StateActions::in, !.IO::di,
- !:IO::uo) is det :-
- string__format("0x%x", [i(State)], SS),
- io__format("\
+ [s(TT)],
+ !IO),
+ map.foldl((pred(State::in, StateActions::in, !.IO::di,
+ !:IO::uo) is det :-
+ string.format("0x%x", [i(State)], SS),
+ io.format("\
actions(%s, Tok, Action, Value) :-
- actions%s(Tok, Action, Value).
+ actions%s(Tok, Action, Value).
:- pred actions%s(%s, parsing_action, int).
:- mode actions%s(in, out, out(state_no)) is semidet.
",
- [s(SS), s(SS), s(SS), s(TT), s(SS)],
- !IO),
- write_state_actions(SS, End, StateActions, !IO)
- ), Table, !IO).
+ [s(SS), s(SS), s(SS), s(TT), s(SS)],
+ !IO),
+ write_state_actions(SS, End, StateActions, !IO)
+ ), Table, !IO).
:- pred write_state_actions(string, term, (terminal -> action),
- io__state, io__state).
+ io, io).
:- mode write_state_actions(in, in, in, di, uo) is det.
write_state_actions(SS, End, StateActions, !IO) :-
- string__format("actions%s", [s(SS)], Name),
- map__foldl((pred(Terminal::in, Action::in, !.IO::di, !:IO::uo) is det :-
- terminal_to_term(Terminal, End, Token),
- term__context_init(Ctxt),
- Term = functor(atom(Name),
- [Token,
- functor(atom(Kind), [], Ctxt),
- functor(integer(Val), [], Ctxt)], Ctxt),
- (
- Action = shift(Val),
- Kind = "shift"
- ;
- Action = reduce(Val),
- Kind = "reduce"
- ;
- Action = accept,
- Kind = "accept",
- Val = 0
- ),
- varset__init(Varset),
- term_io__write_term_nl(Varset, Term, !IO)
- ), StateActions, !IO),
- io__nl(!IO).
+ string.format("actions%s", [s(SS)], Name),
+ map.foldl((pred(Terminal::in, Action::in, !.IO::di, !:IO::uo) is det :-
+ terminal_to_term(Terminal, End, Token),
+ term.context_init(Ctxt),
+ Term = functor(atom(Name),
+ [Token,
+ functor(atom(Kind), [], Ctxt),
+ functor(integer(Val), [], Ctxt)], Ctxt),
+ (
+ Action = shift(Val),
+ Kind = "shift"
+ ;
+ Action = reduce(Val),
+ Kind = "reduce"
+ ;
+ Action = accept,
+ Kind = "accept",
+ Val = 0
+ ),
+ varset.init(Varset),
+ term_io.write_term_nl(Varset, Term, !IO)
+ ), StateActions, !IO),
+ io.nl(!IO).
:- pred terminal_to_term(terminal, term, term).
:- mode terminal_to_term(in, in, out) is det.
terminal_to_term(epsilon, _, _) :-
- error("terminal_to_term: unexpected epsilon").
+ error("terminal_to_term: unexpected epsilon").
terminal_to_term(Name/Arity, _, Term) :-
- varset__init(V0),
- varset__new_vars(V0, Arity, Vars, _),
- term__context_init(Ctxt),
- list__map((pred(Var::in, T::out) is det :-
- T = variable(Var, Ctxt)
- ), Vars, Args),
- Term = functor(atom(Name), Args, Ctxt).
+ varset.init(V0),
+ varset.new_vars(V0, Arity, Vars, _),
+ term.context_init(Ctxt),
+ list.map((pred(Var::in, T::out) is det :-
+ T = variable(Var, Ctxt)
+ ), Vars, Args),
+ Term = functor(atom(Name), Args, Ctxt).
terminal_to_term(($), End, End).
terminal_to_term((*), _, _) :-
- error("terminal_to_term: unexpected hash").
+ error("terminal_to_term: unexpected hash").
%------------------------------------------------------------------------------%
-:- pred write_goto_table(gototable, rule_decls, io__state, io__state).
+:- pred write_goto_table(gototable, rule_decls, io, io).
:- mode write_goto_table(in, in, di, uo) is det.
write_goto_table(Table, DeclTable, !IO) :-
- map__values(DeclTable, Decls),
- write_nonterminal_type(Decls, !IO),
- io__write_string("\
+ map.values(DeclTable, Decls),
+ write_nonterminal_type(Decls, !IO),
+ io.write_string("\
:- pred gotos(int, nonterminal, int).
:- mode gotos(in(state_no), in, out(state_no)) is semidet.
", !IO),
- WriteGotos = (pred(State::in, Actions::in, !.IO::di, !:IO::uo) is det :-
- string__format("0x%x", [i(State)], SS),
- io__format("\
+ WriteGotos = (pred(State::in, Actions::in, !.IO::di, !:IO::uo) is det :-
+ string.format("0x%x", [i(State)], SS),
+ io.format("\
gotos(%s, NT, NS) :-
- gotos%s(NT, NS).
+ gotos%s(NT, NS).
:- pred gotos%s(nonterminal, int).
:- mode gotos%s(in, out) is semidet.
",
- [s(SS), s(SS), s(SS), s(SS)], !IO),
- write_state_gotos(SS, Actions, !IO)
- ),
- map__foldl(WriteGotos, Table, !IO).
+ [s(SS), s(SS), s(SS), s(SS)], !IO),
+ write_state_gotos(SS, Actions, !IO)
+ ),
+ map.foldl(WriteGotos, Table, !IO).
-:- pred write_nonterminal_type(list(rule_decl), io__state, io__state).
+:- pred write_nonterminal_type(list(rule_decl), io, io).
:- mode write_nonterminal_type(in, di, uo) is det.
write_nonterminal_type(Ds, !IO) :-
- list__map((pred(Decl::in, NTType::out) is det :-
- Decl = rule(NT, Args, _VS, TC),
- (
- NT = start,
- error("write_nonterminal_type: start!")
- ;
- NT = Name/_Arity
- ),
- NTType = functor(atom(Name), Args, TC)
- ), Ds, NTTypes),
- term__context_init(Ctxt),
- varset__init(Varset),
- Type = disj(functor(atom("nonterminal"), [], Ctxt), NTTypes),
- Element = type(Type, Varset),
- write_element(nolines, Element, !IO),
- io__nl(!IO).
+ list.map((pred(Decl::in, NTType::out) is det :-
+ Decl = rule(NT, Args, _VS, TC),
+ (
+ NT = start,
+ error("write_nonterminal_type: start!")
+ ;
+ NT = Name/_Arity
+ ),
+ NTType = functor(atom(Name), Args, TC)
+ ), Ds, NTTypes),
+ term.context_init(Ctxt),
+ varset.init(Varset),
+ Type = disj(functor(atom("nonterminal"), [], Ctxt), NTTypes),
+ Element = type(Type, Varset),
+ write_element(nolines, Element, !IO),
+ io.nl(!IO).
-:- pred write_state_gotos(string, (nonterminal -> grammar__state),
- io__state, io__state).
+:- pred write_state_gotos(string, (nonterminal -> grammar.state), io, io).
:- mode write_state_gotos(in, in, di, uo) is det.
write_state_gotos(SS, StateActions, !IO) :-
- string__format("gotos%s", [s(SS)], Name),
- map__foldl((pred(NT::in, NS::in, !.IO::di, !:IO::uo) is det :-
- nonterminal_to_term(NT, Token),
- term__context_init(Ctxt),
- Term = functor(atom(Name),
- [Token, functor(integer(NS), [], Ctxt)], Ctxt),
- varset__init(Varset),
- term_io__write_term_nl(Varset, Term, !IO)
- ), StateActions, !IO),
- io__nl(!IO).
+ string.format("gotos%s", [s(SS)], Name),
+ map.foldl((pred(NT::in, NS::in, !.IO::di, !:IO::uo) is det :-
+ nonterminal_to_term(NT, Token),
+ term.context_init(Ctxt),
+ Term = functor(atom(Name),
+ [Token, functor(integer(NS), [], Ctxt)], Ctxt),
+ varset.init(Varset),
+ term_io.write_term_nl(Varset, Term, !IO)
+ ), StateActions, !IO),
+ io.nl(!IO).
:- pred nonterminal_to_term(nonterminal, term).
:- mode nonterminal_to_term(in, out) is det.
nonterminal_to_term(start, _) :-
- error("nonterminal_to_term: unexpected start").
+ error("nonterminal_to_term: unexpected start").
nonterminal_to_term(Name/Arity, Term) :-
- varset__init(V0),
- varset__new_vars(V0, Arity, Vars, _),
- term__context_init(Ctxt),
- list__map((pred(Var::in, T::out) is det :-
- T = variable(Var, Ctxt)
- ), Vars, Args),
- Term = functor(atom(Name), Args, Ctxt).
+ varset.init(V0),
+ varset.new_vars(V0, Arity, Vars, _),
+ term.context_init(Ctxt),
+ list.map((pred(Var::in, T::out) is det :-
+ T = variable(Var, Ctxt)
+ ), Vars, Args),
+ Term = functor(atom(Name), Args, Ctxt).
%------------------------------------------------------------------------------%
:- pred write_parser(whereami, nonterminal, rule_decl, string, string, string,
- io__state, io__state).
+ io, io).
:- mode write_parser(in, in, in, in, in, in, di, uo) is det.
write_parser(Where, NT, Decl, _TT, InAtom, OutAtom, !IO) :-
- (
- NT = StartName/StartArity
- ;
- NT = start,
- error("write_parser: start!")
- ),
- Decl = rule(_, DeclArgs, DeclVarset, DeclCtxt),
- varset__init(Varset0),
- mkstartargs(StartArity, [], StartArgs, Varset0, Varset),
- StartTerm = functor(atom(StartName), StartArgs, Ctxt),
- term__context_init(Ctxt),
- ParseResultType = type(disj(functor(atom("parse_result"), [], Ctxt),
- [OkayType, ErrorType]), DeclVarset),
- OkayType = functor(atom(StartName), DeclArgs, DeclCtxt),
- ErrorType = functor(atom("error"), [
- functor(atom("string"), [], Ctxt)], Ctxt),
- ( Where = (interface) ->
- io__write_string(":- interface.\n\n", !IO)
- ;
- true
- ),
- write_element(nolines, ParseResultType, !IO),
- io__nl(!IO),
- io__format("\
+ (
+ NT = StartName/StartArity
+ ;
+ NT = start,
+ error("write_parser: start!")
+ ),
+ Decl = rule(_, DeclArgs, DeclVarset, DeclCtxt),
+ varset.init(Varset0),
+ mkstartargs(StartArity, [], StartArgs, Varset0, Varset),
+ StartTerm = functor(atom(StartName), StartArgs, Ctxt),
+ term.context_init(Ctxt),
+ ParseResultType = type(disj(functor(atom("parse_result"), [], Ctxt),
+ [OkayType, ErrorType]), DeclVarset),
+ OkayType = functor(atom(StartName), DeclArgs, DeclCtxt),
+ ErrorType = functor(atom("error"), [
+ functor(atom("string"), [], Ctxt)], Ctxt),
+ ( Where = (interface) ->
+ io.write_string(":- interface.\n\n", !IO)
+ ;
+ true
+ ),
+ write_element(nolines, ParseResultType, !IO),
+ io.nl(!IO),
+ io.format("\
:- pred parse(parse_result, P, P) <= parser_state(P).
:- mode parse(out, %s, %s) is det.
",
- [s(InAtom), s(OutAtom)],
- !IO),
- ( Where = (interface) ->
- io__write_string(":- implementation.\n\n", !IO)
- ;
- true
- ),
- io__format("\
+ [s(InAtom), s(OutAtom)],
+ !IO),
+ ( Where = (interface) ->
+ io.write_string(":- implementation.\n\n", !IO)
+ ;
+ true
+ ),
+ io.format("\
:- import_module list.
parse(Result, Toks0, Toks) :-
- parse(Toks0, Toks, [0], [], Result).
+ parse(Toks0, Toks, [0], [], Result).
:- pred parse(P, P, statestack, symbolstack, parse_result) <= parser_state(P).
:- mode parse(%s, %s, in(state_nos), in, out) is det.
@@ -679,20 +679,20 @@
parse(Toks1, Toks, St1, Sy1, Res)
;
What = reduce,
- Toks2 = unget_token(Tok, Toks1),
+ Toks2 = unget_token(Tok, Toks1),
reduce(Val, St0, St1, Sy0, Sy1, Toks2, Toks3),
parse(Toks3, Toks, St1, Sy1, Res)
;
What = accept,
( Sy0 = [n(",
- [s(InAtom), s(OutAtom)],
+ [s(InAtom), s(OutAtom)],
!IO),
- term_io__write_term(Varset, StartTerm, !IO),
- io__write_string(")] ->
+ term_io.write_term(Varset, StartTerm, !IO),
+ io.write_string(")] ->
Res = (",
- !IO),
- term_io__write_term(Varset, StartTerm, !IO),
- io__write_string("),
+ !IO),
+ term_io.write_term(Varset, StartTerm, !IO),
+ io.write_string("),
Toks = Toks1
;
error(""parse: internal accept error"")
@@ -700,198 +700,198 @@
)
;
Res = error(""parse error""),
- Toks = unget_token(Tok, Toks1)
+ Toks = unget_token(Tok, Toks1)
)
;
St0 = [],
error(""parse: state stack underflow"")
).
",
- !IO).
+ !IO).
:- pred mkstartargs(int, list(term), list(term), varset, varset).
:- mode mkstartargs(in, in, out, in, out) is det.
mkstartargs(N, !Terms, !Varset) :-
- ( N =< 0 ->
- true
- ;
- string__format("V%d", [i(N)], VarName),
- varset__new_named_var(!.Varset, VarName, Var, !:Varset),
- Term = term__variable(Var, context_init),
- list__append([Term], !Terms),
- mkstartargs(N - 1, !Terms, !Varset)
- ).
+ ( N =< 0 ->
+ true
+ ;
+ string.format("V%d", [i(N)], VarName),
+ varset.new_named_var(!.Varset, VarName, Var, !:Varset),
+ Term = term.variable(Var, context_init),
+ list.append([Term], !Terms),
+ mkstartargs(N - 1, !Terms, !Varset)
+ ).
%------------------------------------------------------------------------------%
:- pred write_reductions(rules, actiontable, string, string, string, xforms,
- io__state, io__state).
+ io, io).
:- mode write_reductions(in, in, in, in, in, in, di, uo) is det.
write_reductions(Rules, Table, TT, InAtom, OutAtom, Xfns, !IO) :-
- io__format("\
+ io.format("\
:- import_module require, std_util.
:- type statestack == list(int).
:- type symbolstack == list(stacksymbol).
:- type stacksymbol
- ---> n(nonterminal)
- ; t(%s).
+ ---> n(nonterminal)
+ ; t(%s).
",
- [s(TT)],
- !IO),
- io__format("
+ [s(TT)],
+ !IO),
+ io.format("
:- pred reduce(int, statestack, statestack,
- symbolstack, symbolstack, P, P) <= parser_state(P).
+ symbolstack, symbolstack, P, P) <= parser_state(P).
:- mode reduce(in(state_no), in(state_nos), out(state_nos),
- in, out, %s, %s) is det.
+ in, out, %s, %s) is det.
reduce(RuleNum, States0, States, Symbols0, Symbols, Tokens0, Tokens) :-
- reduce0(RuleNum, States0, States1, Symbols0, Symbols1,
- Tokens0, Tokens1),
- (
- States1 = [State0|_States2],
- Symbols1 = [n(Non)|_],
- gotos(State0, Non, State1),
- States3 = [State1|States1]
- ->
- States = States3,
- Symbols = Symbols1,
- Tokens = Tokens1
- ;
- error(""reduce: reduction failed"")
- ).
-
-",
- [s(InAtom), s(OutAtom)],
- !IO),
- io__format("\
+ reduce0(RuleNum, States0, States1, Symbols0, Symbols1,
+ Tokens0, Tokens1),
+ (
+ States1 = [State0|_States2],
+ Symbols1 = [n(Non)|_],
+ gotos(State0, Non, State1),
+ States3 = [State1|States1]
+ ->
+ States = States3,
+ Symbols = Symbols1,
+ Tokens = Tokens1
+ ;
+ error(""reduce: reduction failed"")
+ ).
+
+",
+ [s(InAtom), s(OutAtom)],
+ !IO),
+ io.format("\
:- pred reduce0(int, statestack, statestack,
- symbolstack, symbolstack, P, P) <= parser_state(P).
+ symbolstack, symbolstack, P, P) <= parser_state(P).
:- mode reduce0(in(state_no), in(state_nos), out(state_nos),
- in, out, %s, %s) is det.
+ in, out, %s, %s) is det.
",
- [s(InAtom), s(OutAtom)],
- !IO),
- map__foldl((pred(Rn::in, Rule::in, !.IO::di, !:IO::uo) is det :-
- ( Rn = 0 ->
+ [s(InAtom), s(OutAtom)],
+ !IO),
+ map.foldl((pred(Rn::in, Rule::in, !.IO::di, !:IO::uo) is det :-
+ ( Rn = 0 ->
- io__write_string("\
+ io.write_string("\
reduce0(0x0, _, _, _, _, _, _) :-
- reduce0_error(0x0).
+ reduce0_error(0x0).
",
- !IO)
+ !IO)
- ;
+ ;
- RedName = string__format("reduce0x%x", [i(Rn)]),
- RnS = string__format("0x%x", [i(Rn)]),
- io__format("\
+ RedName = string.format("reduce0x%x", [i(Rn)]),
+ RnS = string.format("0x%x", [i(Rn)]),
+ io.format("\
reduce0(%s, S0, S, T0, T, U0, U) :-
- %s(S0, S, T0, T, U0, U).
+ %s(S0, S, T0, T, U0, U).
:- pred %s(statestack, statestack, symbolstack, symbolstack,
- P, P) <= parser_state(P).
+ P, P) <= parser_state(P).
:- mode %s(in(state_nos), out(state_nos), in, out, %s, %s) is det.
",
- [s(RnS), s(RedName), s(RedName), s(RedName),
- s(InAtom), s(OutAtom)],
- !IO),
- Rule = rule(RNt, Head, _, Body, Actions, Varset0, _C),
- term__context_init(Ctxt),
- varset__new_named_var(Varset0, "M_St0", St0v, Varset1),
- St0 = variable(St0v, Ctxt),
- varset__new_named_var(Varset1, "M_St1", St1v, Varset2),
- St1 = variable(St1v, Ctxt),
- varset__new_named_var(Varset2, "M_Sy0", Sy0v, Varset3),
- Sy0 = variable(Sy0v, Ctxt),
- varset__new_named_var(Varset3, "M_Sy1", Sy1v, Varset4),
- Sy1 = variable(Sy1v, Ctxt),
- varset__new_named_var(Varset4, "M_RedRes", Resv, Varset5),
- Res = variable(Resv, Ctxt),
- ResS = functor(atom("n"), [variable(Resv, Ctxt)], Ctxt),
- varset__new_named_var(Varset5, "M_D", Dv, Varset6),
- _D = variable(Dv, Ctxt),
- varset__new_named_var(Varset6, "M_S", Sv, Varset7),
- _S = variable(Sv, Ctxt),
- varset__new_named_var(Varset7, "M_St", Stv, Varset8),
- St = variable(Stv, Ctxt),
- varset__new_named_var(Varset8, "M_Sy", Syv, Varset9),
- Sy = variable(Syv, Ctxt),
- varset__new_named_var(Varset9, "M_Ts0", Ts0v, Varset10),
- Ts0 = variable(Ts0v, Ctxt),
- varset__new_named_var(Varset10, "M_Ts", Tsv, Varset11),
- Ts = variable(Tsv, Ctxt),
- string__format("reduction 0x%x failed!", [i(Rn)], Err),
- mkstacks(Body, St1, Sts, Sy1, Sys, Varset11, Varset12),
- Cond = functor(atom(","), [
- functor(atom("="), [St0, Sts], Ctxt),
- functor(atom("="), [Sy0, Sys], Ctxt)
- ], Ctxt),
- Red = functor(atom("="), [Res, Head], Ctxt),
- list__append(Actions, [Red], AllActions0),
- list__reverse(AllActions0, AllActions),
- ConsStack = functor(atom(","), [
- functor(atom("="), [Sy, functor(atom("[|]"),
- [ResS, Sy1], Ctxt)], Ctxt),
- functor(atom("="), [St, St1], Ctxt)], Ctxt),
- mkactions(AllActions, ConsStack, Then0),
- (
- map__search(Xfns, RNt, xform(_, XFormName)),
- Head = functor(_, HeadArgs, _)
- ->
- list__append(HeadArgs, [Ts0], Then1Args),
- XFTerm = functor(atom(XFormName), Then1Args, Ctxt)
- ;
- XFTerm = Ts0
- ),
- Then1 = functor(atom("="), [Ts, XFTerm], Ctxt),
- Then = functor(atom(","), [Then0, Then1], Ctxt),
- BodyTerm = functor(atom(";"),[
- functor(atom("->"), [
- Cond,
- Then
- ], Ctxt),
- functor(atom("error"),
- [functor(string(Err), [], Ctxt)],
- Ctxt
- )], Ctxt),
- ( term_to_goal(BodyTerm, Goal0) ->
- Goal = Goal0
- ;
- error("write_reductions: failed to convert goal")
- ),
- Clause = clause(
- functor(atom(RedName), [St0, St, Sy0, Sy, Ts0, Ts],
- Ctxt),
- Goal, Varset12),
- write_element(lines, Clause, !IO),
- io__nl(!IO)
- )
- ), Rules, !IO),
- WriteReduceError = (pred(State::in, _::in, !.IO::di, !:IO::uo) is det :-
- ( if not map__contains(Rules, State)
- then
- io__format("\
+ [s(RnS), s(RedName), s(RedName), s(RedName),
+ s(InAtom), s(OutAtom)],
+ !IO),
+ Rule = rule(RNt, Head, _, Body, Actions, Varset0, _C),
+ term.context_init(Ctxt),
+ varset.new_named_var(Varset0, "M_St0", St0v, Varset1),
+ St0 = variable(St0v, Ctxt),
+ varset.new_named_var(Varset1, "M_St1", St1v, Varset2),
+ St1 = variable(St1v, Ctxt),
+ varset.new_named_var(Varset2, "M_Sy0", Sy0v, Varset3),
+ Sy0 = variable(Sy0v, Ctxt),
+ varset.new_named_var(Varset3, "M_Sy1", Sy1v, Varset4),
+ Sy1 = variable(Sy1v, Ctxt),
+ varset.new_named_var(Varset4, "M_RedRes", Resv, Varset5),
+ Res = variable(Resv, Ctxt),
+ ResS = functor(atom("n"), [variable(Resv, Ctxt)], Ctxt),
+ varset.new_named_var(Varset5, "M_D", Dv, Varset6),
+ _D = variable(Dv, Ctxt),
+ varset.new_named_var(Varset6, "M_S", Sv, Varset7),
+ _S = variable(Sv, Ctxt),
+ varset.new_named_var(Varset7, "M_St", Stv, Varset8),
+ St = variable(Stv, Ctxt),
+ varset.new_named_var(Varset8, "M_Sy", Syv, Varset9),
+ Sy = variable(Syv, Ctxt),
+ varset.new_named_var(Varset9, "M_Ts0", Ts0v, Varset10),
+ Ts0 = variable(Ts0v, Ctxt),
+ varset.new_named_var(Varset10, "M_Ts", Tsv, Varset11),
+ Ts = variable(Tsv, Ctxt),
+ string.format("reduction 0x%x failed!", [i(Rn)], Err),
+ mkstacks(Body, St1, Sts, Sy1, Sys, Varset11, Varset12),
+ Cond = functor(atom(","), [
+ functor(atom("="), [St0, Sts], Ctxt),
+ functor(atom("="), [Sy0, Sys], Ctxt)
+ ], Ctxt),
+ Red = functor(atom("="), [Res, Head], Ctxt),
+ list.append(Actions, [Red], AllActions0),
+ list.reverse(AllActions0, AllActions),
+ ConsStack = functor(atom(","), [
+ functor(atom("="), [Sy, functor(atom("[|]"),
+ [ResS, Sy1], Ctxt)], Ctxt),
+ functor(atom("="), [St, St1], Ctxt)], Ctxt),
+ mkactions(AllActions, ConsStack, Then0),
+ (
+ map.search(Xfns, RNt, xform(_, XFormName)),
+ Head = functor(_, HeadArgs, _)
+ ->
+ list.append(HeadArgs, [Ts0], Then1Args),
+ XFTerm = functor(atom(XFormName), Then1Args, Ctxt)
+ ;
+ XFTerm = Ts0
+ ),
+ Then1 = functor(atom("="), [Ts, XFTerm], Ctxt),
+ Then = functor(atom(","), [Then0, Then1], Ctxt),
+ BodyTerm = functor(atom(";"),[
+ functor(atom("->"), [
+ Cond,
+ Then
+ ], Ctxt),
+ functor(atom("error"),
+ [functor(string(Err), [], Ctxt)],
+ Ctxt
+ )], Ctxt),
+ ( term_to_goal(BodyTerm, Goal0) ->
+ Goal = Goal0
+ ;
+ error("write_reductions: failed to convert goal")
+ ),
+ Clause = clause(
+ functor(atom(RedName), [St0, St, Sy0, Sy, Ts0, Ts],
+ Ctxt),
+ Goal, Varset12),
+ write_element(lines, Clause, !IO),
+ io.nl(!IO)
+ )
+ ), Rules, !IO),
+ WriteReduceError = (pred(State::in, _::in, !.IO::di, !:IO::uo) is det :-
+ ( if not map.contains(Rules, State)
+ then
+ io.format("\
reduce0(0x%x, _, _, _, _, _, _) :-
- reduce0_error(0x%x).
+ reduce0_error(0x%x).
",
- [i(State), i(State)], !IO)
- else true
- )
- ),
- map__foldl(WriteReduceError, Table, !IO),
- io__format("\
+ [i(State), i(State)], !IO)
+ else true
+ )
+ ),
+ map.foldl(WriteReduceError, Table, !IO),
+ io.format("\
:- pred reduce0_error(int).
:- mode reduce0_error(in) is erroneous.
reduce0_error(State) :-
- error(string__format(""reduce in state 0x%%x"", [i(State)])).
+ error(string.format(""reduce in state 0x%%x"", [i(State)])).
", [], !IO).
@@ -900,27 +900,27 @@
mkstacks([], !St, !Sy, !VS).
mkstacks([E0 | Es], !St, !Sy, !VS) :-
- varset__new_var(!.VS, U, !:VS),
- term__context_init(Ctxt),
- (
- E0 = terminal(ET),
- E = functor(atom("t"), [ET], Ctxt)
- ;
- E0 = nonterminal(EN),
- E = functor(atom("n"), [EN], Ctxt)
- ),
- !:Sy = functor(atom("[|]"), [E, !.Sy], Ctxt),
- !:St = functor(atom("[|]"), [variable(U, Ctxt), !.St], Ctxt),
- mkstacks(Es, !St, !Sy, !VS).
+ varset.new_var(!.VS, U, !:VS),
+ term.context_init(Ctxt),
+ (
+ E0 = terminal(ET),
+ E = functor(atom("t"), [ET], Ctxt)
+ ;
+ E0 = nonterminal(EN),
+ E = functor(atom("n"), [EN], Ctxt)
+ ),
+ !:Sy = functor(atom("[|]"), [E, !.Sy], Ctxt),
+ !:St = functor(atom("[|]"), [variable(U, Ctxt), !.St], Ctxt),
+ mkstacks(Es, !St, !Sy, !VS).
:- pred mkactions(list(term), term, term).
:- mode mkactions(in, in, out) is det.
mkactions([], !Term).
mkactions([E | Es], !Term) :-
- term__context_init(Ctxt),
- !:Term = functor(atom(","), [E, !.Term], Ctxt),
- mkactions(Es, !Term).
+ term.context_init(Ctxt),
+ !:Term = functor(atom(","), [E, !.Term], Ctxt),
+ mkactions(Es, !Term).
%------------------------------------------------------------------------------%
@@ -928,8 +928,8 @@
:- mode sub(in, in, out) is det.
sub(Orig, Subs, Final) :-
- list__foldl((pred(Sub::in, S0::in, S1::out) is det :-
- Sub = From - To,
- string__replace_all(S0, From, To, S1)
- ), Subs, Orig, Final).
+ list.foldl((pred(Sub::in, S0::in, S1::out) is det :-
+ Sub = From - To,
+ string.replace_all(S0, From, To, S1)
+ ), Subs, Orig, Final).
Index: extras/moose/options.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/extras/moose/options.m,v
retrieving revision 1.2
diff -u -r1.2 options.m
--- extras/moose/options.m 16 Jul 2003 07:16:03 -0000 1.2
+++ extras/moose/options.m 21 Feb 2009 11:27:38 -0000
@@ -28,7 +28,7 @@
:- type options == option_table(option).
:- type maybe_options == maybe_option_table(option).
-:- pred parse_options(maybe_options, list(string), io__state, io__state).
+:- pred parse_options(maybe_options, list(string), io.state, io.state).
:- mode parse_options(out, out, di, uo) is det.
:- implementation.
@@ -36,9 +36,9 @@
:- import_module bool, char, std_util.
parse_options(MOpts, Args, !IO) :-
- io__command_line_arguments(Args0, !IO),
+ io.command_line_arguments(Args0, !IO),
OptionOpts = option_ops(short, long, defaults),
- getopt__process_options(OptionOpts, Args0, Args, MOpts).
+ getopt.process_options(OptionOpts, Args0, Args, MOpts).
:- pred short(char, option).
:- mode short(in, out) is semidet.
Index: extras/moose/tables.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/extras/moose/tables.m,v
retrieving revision 1.3
diff -u -r1.3 tables.m
--- extras/moose/tables.m 24 Feb 2004 08:53:51 -0000 1.3
+++ extras/moose/tables.m 21 Feb 2009 11:27:38 -0000
@@ -49,26 +49,26 @@
%------------------------------------------------------------------------------%
shifts(_C, _Rules, First, Reaching, !:Shifts) :-
- map__init(!:Shifts),
- map__foldl((pred(N::in, Ts0::in, !.Shifts::in, !:Shifts::out) is det :-
- ( map__search(Reaching, N, Ns0) ->
- set__to_sorted_list(Ns0, Ns1)
+ map.init(!:Shifts),
+ map.foldl((pred(N::in, Ts0::in, !.Shifts::in, !:Shifts::out) is det :-
+ ( map.search(Reaching, N, Ns0) ->
+ set.to_sorted_list(Ns0, Ns1)
;
Ns1 = []
),
- list__map(map__lookup(First), Ns1, Ts1),
- list__foldl(set__union, Ts1, Ts0, Ts2),
+ list.map(map.lookup(First), Ns1, Ts1),
+ list.foldl(set.union, Ts1, Ts0, Ts2),
Ts = Ts2 - { epsilon },
- map__set(!.Shifts, N, Ts, !:Shifts)
+ map.set(!.Shifts, N, Ts, !:Shifts)
), First, !Shifts).
%------------------------------------------------------------------------------%
actions(C, Rules, Lookaheads, Gotos, Shifts, !:States, !:Actions, Errs) :-
- set__to_sorted_list(C, CList),
- map__init(!:States),
+ set.to_sorted_list(C, CList),
+ map.init(!:States),
number_states(CList, 0, !States),
- map__init(!:Actions),
+ map.init(!:Actions),
actions1(CList, Rules, Lookaheads, !.States, Gotos, Shifts, !Actions,
[], Errs).
@@ -77,7 +77,7 @@
number_states([], _N, !States).
number_states([I | Is], N, !States) :-
- map__det_insert(!.States, I, N, !:States),
+ map.det_insert(!.States, I, N, !:States),
number_states(Is, N + 1, !States).
:- pred actions1(list(items), rules, lookaheads, states, gotos, shifts,
@@ -86,8 +86,8 @@
actions1([], _Rules, _Lookaheads, _States, _Gotos, _Shifts, !Actions, !Errs).
actions1([I | Is], Rules, Lookaheads, States, Gotos, Shifts, !Actions, !Errs) :-
- map__lookup(States, I, Sn),
- set__to_sorted_list(I, IList),
+ map.lookup(States, I, Sn),
+ set.to_sorted_list(I, IList),
actions2(IList, I, Sn, Rules, Lookaheads, States, Gotos, Shifts,
!Actions, !Errs),
actions1(Is, Rules, Lookaheads, States, Gotos, Shifts, !Actions, !Errs).
@@ -99,37 +99,37 @@
actions2([], _I, _Sn, _Rules, _LA, _States, _Gotos, _Shifts, !Actions, !Errs).
actions2([A | As], I, Sn, Rules, LA, States, Gotos, Shifts, !Actions, !Errs) :-
A = item(Ip, Id),
- map__lookup(Rules, Ip, rule(_, _, Syms, _, _, _, _)),
- array__max(Syms, Max),
+ map.lookup(Rules, Ip, rule(_, _, Syms, _, _, _, _)),
+ array.max(Syms, Max),
( Id =< Max ->
- array__lookup(Syms, Id, X),
- map__lookup(Gotos, I, IGs),
+ array.lookup(Syms, Id, X),
+ map.lookup(Gotos, I, IGs),
(
X = terminal(T0),
Ts = { T0 }
;
X = nonterminal(N),
- ( map__search(Shifts, N, Ts0) ->
+ ( map.search(Shifts, N, Ts0) ->
Ts = Ts0
;
Ts = empty
)
),
- set__to_sorted_list(Ts, TList),
- list__foldl2((pred(T::in, !.Actions::in, !:Actions::out,
+ set.to_sorted_list(Ts, TList),
+ list.foldl2((pred(T::in, !.Actions::in, !:Actions::out,
!.Errs::in, !:Errs::out) is det :-
- map__lookup(IGs, terminal(T), J),
- map__lookup(States, J, Jn),
+ map.lookup(IGs, terminal(T), J),
+ map.lookup(States, J, Jn),
addaction(Sn, T, shift(Jn), !Actions, !Errs)
), TList, !Actions, !Errs)
;
% A -> alpha .
(
- map__search(LA, I, ILAs),
- map__search(ILAs, A, Alphas)
+ map.search(LA, I, ILAs),
+ map.search(ILAs, A, Alphas)
->
- set__to_sorted_list(Alphas, AlphaList),
- list__foldl2((pred(T::in,
+ set.to_sorted_list(Alphas, AlphaList),
+ list.foldl2((pred(T::in,
!.Actions::in, !:Actions::out,
!.Errs::in, !:Errs::out) is det :-
( Ip = 0, T = ($) ->
@@ -151,12 +151,12 @@
:- mode addaction(in, in, in, in, out, in, out) is det.
addaction(Sn, T, A0, !Actions, !Errs) :-
- ( map__search(!.Actions, Sn, State0) ->
+ ( map.search(!.Actions, Sn, State0) ->
State1 = State0
;
- map__init(State1)
+ map.init(State1)
),
- ( map__search(State1, T, A1) ->
+ ( map.search(State1, T, A1) ->
( A0 = A1 ->
A = A1
;
@@ -173,7 +173,7 @@
)
->
A = A2,
- list__append([Err], !Errs)
+ list.append([Err], !Errs)
;
A = A0,
(
@@ -189,32 +189,32 @@
;
Err = error(misc(A0, A1))
),
- list__append([Err], !Errs)
+ list.append([Err], !Errs)
)
;
A = A0
),
- map__set(State1, T, A, State),
- map__set(!.Actions, Sn, State, !:Actions).
+ map.set(State1, T, A, State),
+ map.set(!.Actions, Sn, State, !:Actions).
%------------------------------------------------------------------------------%
gotos(_C, States, Gotos, !:GotoTable) :-
- map__init(!:GotoTable),
- map__foldl((pred(I0::in, IGs::in, !.GotoTable::in,
+ map.init(!:GotoTable),
+ map.foldl((pred(I0::in, IGs::in, !.GotoTable::in,
!:GotoTable::out) is det :-
- map__lookup(States, I0, Sf),
- map__foldl((pred(Sym::in, J0::in, !.GotoTable::in,
+ map.lookup(States, I0, Sf),
+ map.foldl((pred(Sym::in, J0::in, !.GotoTable::in,
!:GotoTable::out) is det :-
( Sym = nonterminal(N) ->
- map__lookup(States, J0, St),
- ( map__search(!.GotoTable, Sf, X0) ->
+ map.lookup(States, J0, St),
+ ( map.search(!.GotoTable, Sf, X0) ->
X1 = X0
;
- map__init(X1)
+ map.init(X1)
),
- map__set(X1, N, St, X),
- map__set(!.GotoTable, Sf, X, !:GotoTable)
+ map.set(X1, N, St, X),
+ map.set(!.GotoTable, Sf, X, !:GotoTable)
;
true
)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mercurylang.org/archives/reviews/attachments/20090221/cab0ee7e/attachment.sig>
More information about the reviews
mailing list