/
OperatorProperties.pm6
129 lines (121 loc) · 3.76 KB
/
OperatorProperties.pm6
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
class OperatorProperties {
has str $.precedence = "";
has str $.associative = "";
has str $.thunky = "";
has int $.iffy;
# shorten signatures and invocations
my constant OP = OperatorProperties;
multi method WHICH(OP:D: --> ValueObjAt) {
my $parts := nqp::list_s('OperatorProperties');
nqp::push_s($parts,nqp::concat('precedence=',$!precedence))
if $!precedence;
nqp::push_s($parts,nqp::concat('associative=',$!associative))
if $!associative;
nqp::push_s($parts,nqp::concat('thunky=',$!thunky))
if $!thunky;
nqp::push_s($parts,nqp::concat('iffy=',$!iffy))
if $!iffy;
nqp::box_s(nqp::join('|',$parts),ValueObjAt)
}
method equiv(OP:D:) {
self.new: :$!precedence,
:associative(''), :$!thunky, :$!iffy
}
method looser(OP:D:) {
self.new: precedence => $!precedence.subst('=','@='),
:associative(''), :$!thunky, :$!iffy
}
method tighter(OP:D:) {
self.new: precedence => $!precedence.subst('=',':=')
:associative(''), :$!thunky, :$!iffy
}
method prec() {
Map.new:
(prec => $!precedence if $!precedence),
(assoc => $!associative if $!associative),
(thunky => $!thunky if $!thunky),
(iffy => $!iffy)
}
method methodcall(OP:U:) { OP.new:
:precedence<y=>
}
method autoincrement(OP:U:) { OP.new:
:precedence<x=>
}
method exponentiation(OP:U:) { OP.new:
:precedence<w=>, :associative<left>
}
method symbolic-unary(OP:U:) { OP.new:
:precedence<v=>
}
method multiplicative(OP:U:) { OP.new:
:precedence<u=>, :associative<left>
}
method iffytive(OP:U:) { OP.new:
:precedence<u=>, :associative<left>, :iffy
}
method additive(OP:U:) { OP.new:
:precedence<t=>, :associative<left>
}
method replication(OP:U:) { OP.new:
:precedence<s=>, :associative<left>
}
method replication-xx(OP:U:) { OP.new:
:precedence<s=>, :associative<left>, :thunky<t.>
}
method concatenation(OP:U:) { OP.new:
:precedence<r=>, :associative<list>
}
method junctive-and(OP:U:) { OP.new:
:precedence<q=>, :associative<list>
}
method junctive-or(OP:U:) { OP.new:
:precedence<p=>, :associative<list>
}
method structural(OP:U:) { OP.new:
:precedence<n=>, :associative<non>
}
method chaining(OP:U:) { OP.new:
:precedence<m=>, :associative<chain>, :iffy
}
method tight-and(OP:U:) { OP.new:
:precedence<l=>, :associative<list>, :thunky<.t>
}
method tight-or(OP:U:) { OP.new:
:precedence<k=>, :associative<list>, :thunky<.t>
}
method tight-or-xor(OP:U:) { OP.new:
:precedence<k=>, :associative<list>, :thunky<..t>
}
method tight-or-minmax(OP:U:) { OP.new:
:precedence<k=>, :associative<list>
}
method item-assignment(OP:U:) { OP.new:
:precedence<i=>, :associative<right>
}
method loose-unary(OP:U:) { OP.new:
:precedence<h=>
}
method comma(OP:U:) { OP.new:
:precedence<g=>, :associative<list>
}
method list-infix(OP:U:) { OP.new:
:precedence<f=>, :associative<list>
}
method list-prefix(OP:U:) { OP.new:
:precedence<e=>
}
method loose-and(OP:U:) { OP.new:
:precedence<d=>, :associative<list>, :thunky<.t>
}
method loose-andthen(OP:U:) { OP.new:
:precedence<d=>, :associative<list>, :thunky<.b>
}
method loose-or(OP:U:) { OP.new:
:precedence<c=>, :associative<list>, :thunky<.t>
}
method loose-orelse(OP:U:) { OP.new:
:precedence<c=>, :associative<list>, :thunky<.b>
}
}
# vim: expandtab shiftwidth=4