-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutils.pl
83 lines (75 loc) · 1.45 KB
/
utils.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
:- module(utils,
[pretty/1,
writeRules/1]).
writeRules([]).
writeRules([R|Rs]) :-
writeln(R),
writeRules(Rs).
%% pos(term,pos)
%% returns the set of positions of a term
pos(_,[]).
pos(cons(_,X), [P|Ps]) :-
nth1(P,X,T),
pos(T,Ps).
pos(funs(_,X), [P|Ps]) :-
nth1(P,X,T),
pos(T,Ps).
%% pretty(trs_object)
%% pretty printing of a trs_object
%% a trs_object can be a trs or a component of a trs
%% (rules, defined symbols, variables...)
pretty(ctrs(_,R)) :-
pretty(R),
nl.
pretty(rules(Rs)) :-
pretty(Rs).
pretty([]).
pretty([R|Rs]) :-
pretty(R),
pretty(Rs).
pretty(rule(B,L,R,C)) :-
pretty(B),
format(" : "),
pretty(L),
format(" -> "),
pretty(R),
pretty_conds(C),
nl.
pretty(beta(N)) :-
format("B_~d",[N]).
pretty(cond(L,R)) :-
pretty(L),
format(" ->> "),
pretty(R).
pretty(fun(N,[])) :-
format("~s()",[N]).
pretty(fun(N,[T|Ts])) :-
format("~s(",[N]),
pretty_args([T|Ts]),
format(")").
pretty(cons(N,[])) :-
format("~s",[N]).
pretty(cons(N,[T|Ts])) :-
format("~s(",[N]),
pretty_args([T|Ts]),
format(")").
pretty(var(N,_)) :-
format("~s",[N]).
pretty(TupleArgs) :-
TupleArgs =.. [tuple|Args],
format("<"),
pretty_args(Args),
format(">").
pretty_args([]).
pretty_args([A|As]) :-
pretty(A),
pretty_commas(As).
pretty_commas([]).
pretty_commas([A|As]) :-
format(", "),
pretty(A),
pretty_commas(As).
pretty_conds([]).
pretty_conds([C|Cs]) :-
format(" <= "),
pretty_args([C|Cs]).