1
1
use owned_slice:: OwnedSlice ;
2
+ use operator:: OperatorKind ;
2
3
3
4
#[ derive( Debug , PartialEq , Clone , Copy ) ]
4
5
pub enum Value {
@@ -18,214 +19,6 @@ pub struct Parameter {
18
19
pub default : Option < Box < Expression > >
19
20
}
20
21
21
- #[ derive( Debug , PartialEq , Clone , Copy ) ]
22
- pub enum OperatorType {
23
- FatArrow , // … => …
24
- Accessor , // … . …
25
- New , // new …
26
- Increment , // ++ … | … ++
27
- Decrement , // -- … | … --
28
- LogicalNot , // ! …
29
- BitwiseNot , // ~ …
30
- Typeof , // typeof …
31
- Void , // void …
32
- Delete , // delete …
33
- Multiplication , // … * …
34
- Division , // … / …
35
- Remainder , // … % …
36
- Exponent , // … ** …
37
- Addition , // … + … | + …
38
- Substraction , // … - … | - …
39
- BitShiftLeft , // … << …
40
- BitShiftRight , // … >> …
41
- UBitShiftRight , // … >>> …
42
- Lesser , // … < …
43
- LesserEquals , // … <= …
44
- Greater , // … > …
45
- GreaterEquals , // … >= …
46
- Instanceof , // … instanceof …
47
- In , // … in …
48
- StrictEquality , // … === …
49
- StrictInequality , // … !== …
50
- Equality , // … == …
51
- Inequality , // … != …
52
- BitwiseAnd , // … & …
53
- BitwiseXor , // … ^ …
54
- BitwiseOr , // … | …
55
- LogicalAnd , // … && …
56
- LogicalOr , // … || …
57
- Conditional , // … ? … : …
58
- Assign , // … = …
59
- AddAssign , // … += …
60
- SubstractAssign , // … -= …
61
- ExponentAssign , // … **= …
62
- MultiplyAssign , // … *= …
63
- DivideAssign , // … /= …
64
- RemainderAssign , // … %= …
65
- BSLAssign , // … <<= …
66
- BSRAssign , // … >>= …
67
- UBSRAssign , // … >>>= …
68
- BitAndAssign , // … &= …
69
- BitXorAssign , // … ^= …
70
- BitOrAssign , // … |= …
71
- Spread , // ... …
72
- }
73
- use self :: OperatorType :: * ;
74
-
75
- impl OperatorType {
76
- /// According to the Operator Precedence Table
77
- /// Note: Unary opearotrs default to 15!
78
- pub fn binding_power ( & self ) -> u8 {
79
- match * self {
80
- FatArrow |
81
- Accessor => 18 ,
82
-
83
- New => 17 ,
84
-
85
- Increment |
86
- Decrement => 16 ,
87
-
88
- LogicalNot |
89
- BitwiseNot |
90
- Typeof |
91
- Void |
92
- Delete => 15 ,
93
-
94
- Multiplication |
95
- Division |
96
- Remainder |
97
- Exponent => 14 ,
98
-
99
- Addition |
100
- Substraction => 13 ,
101
-
102
- BitShiftLeft |
103
- BitShiftRight |
104
- UBitShiftRight => 12 ,
105
-
106
- Lesser |
107
- LesserEquals |
108
- Greater |
109
- GreaterEquals |
110
- Instanceof |
111
- In => 11 ,
112
-
113
- StrictEquality |
114
- StrictInequality |
115
- Equality |
116
- Inequality => 10 ,
117
-
118
- BitwiseAnd => 9 ,
119
- BitwiseXor => 8 ,
120
- BitwiseOr => 7 ,
121
- LogicalAnd => 6 ,
122
- LogicalOr => 5 ,
123
- Conditional => 4 ,
124
-
125
- Assign |
126
- AddAssign |
127
- SubstractAssign |
128
- ExponentAssign |
129
- MultiplyAssign |
130
- DivideAssign |
131
- RemainderAssign |
132
- BSLAssign |
133
- BSRAssign |
134
- UBSRAssign |
135
- BitAndAssign |
136
- BitXorAssign |
137
- BitOrAssign => 3 ,
138
-
139
- Spread => 1 ,
140
- }
141
- }
142
-
143
- pub fn prefix ( & self ) -> bool {
144
- match * self {
145
- LogicalNot |
146
- BitwiseNot |
147
- Typeof |
148
- Void |
149
- Delete |
150
- New |
151
- Spread |
152
- Increment |
153
- Decrement |
154
- Addition |
155
- Substraction => true ,
156
-
157
- _ => false
158
- }
159
- }
160
-
161
- pub fn infix ( & self ) -> bool {
162
- match * self {
163
- FatArrow |
164
- Accessor |
165
- Multiplication |
166
- Division |
167
- Remainder |
168
- Exponent |
169
- StrictEquality |
170
- StrictInequality |
171
- Equality |
172
- Inequality |
173
- Lesser |
174
- LesserEquals |
175
- Greater |
176
- GreaterEquals |
177
- Instanceof |
178
- In |
179
- BitShiftLeft |
180
- BitShiftRight |
181
- UBitShiftRight |
182
- BitwiseAnd |
183
- BitwiseXor |
184
- BitwiseOr |
185
- LogicalAnd |
186
- LogicalOr |
187
- Conditional |
188
- Addition |
189
- Substraction |
190
- Assign |
191
- AddAssign |
192
- SubstractAssign |
193
- ExponentAssign |
194
- MultiplyAssign |
195
- DivideAssign |
196
- RemainderAssign |
197
- BSLAssign |
198
- BSRAssign |
199
- UBSRAssign |
200
- BitAndAssign |
201
- BitXorAssign |
202
- BitOrAssign => true ,
203
-
204
- _ => false
205
- }
206
- }
207
-
208
- pub fn assignment ( & self ) -> bool {
209
- match * self {
210
- Assign |
211
- AddAssign |
212
- SubstractAssign |
213
- ExponentAssign |
214
- MultiplyAssign |
215
- DivideAssign |
216
- RemainderAssign |
217
- BSLAssign |
218
- BSRAssign |
219
- UBSRAssign |
220
- BitAndAssign |
221
- BitXorAssign |
222
- BitOrAssign => true ,
223
-
224
- _ => false
225
- }
226
- }
227
- }
228
-
229
22
#[ derive( Debug , PartialEq , Clone ) ]
230
23
pub enum Expression {
231
24
This ,
@@ -257,16 +50,16 @@ pub enum Expression {
257
50
} ,
258
51
Binary {
259
52
parenthesized : bool ,
260
- operator : OperatorType ,
53
+ operator : OperatorKind ,
261
54
left : Box < Expression > ,
262
55
right : Box < Expression > ,
263
56
} ,
264
57
Prefix {
265
- operator : OperatorType ,
58
+ operator : OperatorKind ,
266
59
operand : Box < Expression > ,
267
60
} ,
268
61
Postfix {
269
- operator : OperatorType ,
62
+ operator : OperatorKind ,
270
63
operand : Box < Expression > ,
271
64
} ,
272
65
Conditional {
@@ -323,7 +116,7 @@ impl Expression {
323
116
}
324
117
325
118
#[ inline]
326
- pub fn binary < E : Into < Expression > > ( left : E , operator : OperatorType , right : E ) -> Self {
119
+ pub fn binary < E : Into < Expression > > ( left : E , operator : OperatorKind , right : E ) -> Self {
327
120
Expression :: Binary {
328
121
parenthesized : false ,
329
122
operator : operator,
@@ -511,6 +304,11 @@ pub enum Statement {
511
304
params : Vec < Parameter > ,
512
305
body : Vec < Statement > ,
513
306
} ,
307
+ Class {
308
+ name : OwnedSlice ,
309
+ extends : Option < OwnedSlice > ,
310
+ body : Vec < ClassMember > ,
311
+ } ,
514
312
If {
515
313
test : Expression ,
516
314
consequent : Box < Statement > ,
@@ -536,11 +334,6 @@ pub enum Statement {
536
334
right : Expression ,
537
335
body : Box < Statement > ,
538
336
} ,
539
- Class {
540
- name : OwnedSlice ,
541
- extends : Option < OwnedSlice > ,
542
- body : Vec < ClassMember > ,
543
- } ,
544
337
Throw {
545
338
value : Expression
546
339
} ,
0 commit comments