-
Notifications
You must be signed in to change notification settings - Fork 0
/
mkCollectArgRefs.sh
executable file
·146 lines (138 loc) · 3.71 KB
/
mkCollectArgRefs.sh
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/bin/bash
cat << EOF
:- module sentence_collectArgRefs.
:- interface.
:- import_module mrs.
:- import_module multi_map.
:- import_module sentence_predicates.
:- import_module sentence_types.
:- pred collectArgRefs(multi_map(mrs_rel_handle,{mrs_rel_handle,string,string,preds}),
mrs_rel_handle,
preds,
multi_map(mrs_types,mrs_rel_handle),
multi_map(mrs_types,mrs_rel_handle)).
:- mode collectArgRefs(in,in,in,in,out) is det.
:- implementation.
:- import_module require.
:- import_module solutions.
:- import_module list.
:- import_module calls.
:- import_module io.
:- import_module unsafe.
:- pragma promise_pure(collectArgRefs/5).
collectArgRefs(RelMap,RelHandleIn,Pred,ArgRefMapIn,ArgRefMapOut) :-
EOF
sed -n '/mrs/s/.*pred_\([a-z0-9_]*\)(pred(\(mrs_rel_handle,[^)]*\)))/\1\,\2/p' sentence_predicates.m | tr -d ' ' | tr -d . > _predicate_table
declare -a ArgAry
declare -a WrapExprs
for line in `cat _predicate_table`; do
set -- `echo $line | tr , ' '`
pred=$1
shift
IndivPos=0
InstPos=0
RelHandlePos=0
RstrHandlePos=0
BodyHandlePos=0
CargPos=0
UnknownPos=0
delim=""
Args=""
ArgPos=0
EventPos=0
echo " ${lineDelim}if pred_${pred}(_) = Pred then"
while test -n "$1"; do
case $1 in
mrs_indiv)
Var=Indiv${IndivPos}
IndivPos=$((${IndivPos} + 1))
WrapExpr="wrap_indiv(${Var})"
;;
mrs_inst)
Var=Inst${InstPos}
InstPos=$((${InstPos} + 1))
WrapExpr="wrap_inst(${Var})"
;;
mrs_event)
Var=Event${EventPos}
EventPos=$((${EventPos} + 1))
WrapExpr="wrap_event(${Var})"
;;
mrs_rel_handle)
Var=RelHandle${RelHandlePos}
RelHandlePos=$((${RelHandlePos} + 1))
WrapExpr="wrap_rel_handle(${Var})"
;;
mrs_rstr_handle)
Var="mrs_rstr_handle(RstrHandle${RstrHandlePos})"
RstrHandlePos=$((${RstrHandlePos} + 1))
WrapExpr="wrap_rstr_handle(${Var})"
;;
mrs_body_handle)
Var="mrs_body_handle(BodyHandle${BodyHandlePos})"
BodyHandlePos=$((${BodyHandlePos} + 1))
WrapExpr="wrap_body_handle(${Var})"
;;
mrs_carg)
Var=Carg${CargPos}
CargPos=$((${CargPos} + 1))
WrapExpr="wrap_carg(${Var})"
;;
mrs_unknown)
Var=Unk${UnknownPos}
UnknownPos=$((${UnknownPos} + 1))
WrapExpr="wrap_unknown(${Var})"
;;
*)
echo "unknown type $1" 1>&2
exit 1
;;
esac
Args="${Args}${delim}${Var}"
ArgAry[${ArgPos}]=${Var}
WrapExprs[${ArgPos}]=${WrapExpr}
delim=","
shift
ArgPos=$((${ArgPos} + 1))
done
echo " solutions(pred({${Args}}::out) is nondet :- (${pred}(${Args}), RelHandle0 = RelHandleIn), L),"
ArgCount=${ArgPos}
ArgPos=0
while test $ArgPos -lt $ArgCount; do
ArgSubPos=0
Pattern=''
delim=''
while test $ArgSubPos -lt $ArgCount; do
if test $ArgSubPos = $ArgPos; then
Pattern="${Pattern}${delim}${ArgAry[$ArgPos]}"
else
Pattern="${Pattern}${delim}_"
fi
ArgSubPos=$(($ArgSubPos + 1))
delim=","
done
if test $ArgPos = 0; then
ArgRefMapIn=ArgRefMapIn
else
ArgRefMapIn=ArgRefMap$(($ArgPos - 1))
fi
if test $(($ArgPos + 1)) = $ArgCount; then
ArgRefMapOut=ArgRefMapOut
else
ArgRefMapOut=ArgRefMap${ArgPos}
fi
echo -n " list.foldl(pred({${Pattern}}::in,AIn::in,AOut::out) is det :- AOut = multi_map.add(AIn,${WrapExprs[$ArgPos]},RelHandleIn),L,${ArgRefMapIn},${ArgRefMapOut})"
ArgPos=$(($ArgPos + 1))
if test $ArgPos -lt $ArgCount; then
echo ,
else
echo
fi
done
lineDelim="else "
done
cat << EOF
else
impure unsafe_perform_io(print(Pred)),
error("unknown predicate").
EOF