@@ -2,6 +2,8 @@ use fuse_common::{ReferenceType, Span};
2
2
use fuse_common_proc:: serializable;
3
3
use std:: { cell:: Cell , rc:: Rc } ;
4
4
5
+ use crate :: GetSpan ;
6
+
5
7
#[ serializable]
6
8
#[ derive( Debug ) ]
7
9
pub struct Chunk {
@@ -117,11 +119,35 @@ pub enum Expression {
117
119
ArrayExpression ( Box < ArrayExpression > ) ,
118
120
TupleExpression ( Box < TupleExpression > ) ,
119
121
ParenthesizedExpression ( Box < ParenthesizedExpression > ) ,
122
+ MemberExpression ( Box < MemberExpression > ) ,
120
123
CallExpression ( Box < CallExpression > ) ,
121
124
TableConstructionExpression ( Box < ConstructionExpression > ) ,
122
125
StructConstructionExpression ( Box < StructConstructionExpression > ) ,
123
126
}
124
127
128
+ impl Expression {
129
+ pub fn span ( & self ) -> Span {
130
+ use Expression :: * ;
131
+ match self {
132
+ NumberLiteral ( expr) => expr. span ,
133
+ StringLiteral ( expr) => expr. span ,
134
+ BooleanLiteral ( expr) => expr. span ,
135
+ Identifier ( expr) => expr. span ,
136
+ Function ( expr) => expr. span ,
137
+ If ( expr) => expr. span ,
138
+ UnaryOperator ( expr) => expr. span ( ) ,
139
+ BinaryOperator ( expr) => expr. span ( ) ,
140
+ ArrayExpression ( expr) => expr. span ,
141
+ TupleExpression ( expr) => expr. span ,
142
+ ParenthesizedExpression ( expr) => expr. span ,
143
+ MemberExpression ( expr) => expr. span ,
144
+ CallExpression ( expr) => expr. span ,
145
+ TableConstructionExpression ( expr) => expr. span ,
146
+ StructConstructionExpression ( expr) => expr. span ( ) ,
147
+ }
148
+ }
149
+ }
150
+
125
151
#[ serializable]
126
152
#[ derive( Debug , PartialEq ) ]
127
153
pub struct BooleanLiteral {
@@ -264,12 +290,29 @@ pub struct UnaryOperator {
264
290
pub expression : Expression ,
265
291
}
266
292
293
+ impl GetSpan for UnaryOperator {
294
+ #[ inline]
295
+ fn span ( & self ) -> Span {
296
+ Span :: with_spans ( vec ! [ self . kind. span( ) , self . expression. span( ) ] )
297
+ }
298
+ }
299
+
267
300
#[ serializable]
268
301
#[ derive( Debug , PartialEq ) ]
269
302
pub enum UnaryOperatorKind {
270
303
Not ( Span ) ,
271
- Minus ( Span ) ,
272
304
Plus ( Span ) ,
305
+ Minus ( Span ) ,
306
+ }
307
+
308
+ impl GetSpan for UnaryOperatorKind {
309
+ fn span ( & self ) -> Span {
310
+ match self {
311
+ Self :: Not ( span) => * span,
312
+ Self :: Plus ( span) => * span,
313
+ Self :: Minus ( span) => * span,
314
+ }
315
+ }
273
316
}
274
317
275
318
#[ serializable]
@@ -280,6 +323,12 @@ pub struct BinaryOperator {
280
323
pub rhs : Expression ,
281
324
}
282
325
326
+ impl GetSpan for BinaryOperator {
327
+ fn span ( & self ) -> Span {
328
+ Span :: with_spans ( vec ! [ self . kind. span( ) , self . lhs. span( ) , self . rhs. span( ) ] )
329
+ }
330
+ }
331
+
283
332
#[ serializable]
284
333
#[ derive( Debug , PartialEq ) ]
285
334
pub enum BinaryOperatorKind {
@@ -307,6 +356,36 @@ pub enum BinaryOperatorKind {
307
356
Member ( Span ) ,
308
357
}
309
358
359
+ impl GetSpan for BinaryOperatorKind {
360
+ fn span ( & self ) -> Span {
361
+ let span = match self {
362
+ Self :: Assignment ( span) => span,
363
+ Self :: LogicalOr ( span) => span,
364
+ Self :: LogicalAnd ( span) => span,
365
+ Self :: BitwiseOr ( span) => span,
366
+ Self :: BitwiseXor ( span) => span,
367
+ Self :: BitwiseAnd ( span) => span,
368
+ Self :: Equality ( span) => span,
369
+ Self :: NonEquality ( span) => span,
370
+ Self :: LessThanEqual ( span) => span,
371
+ Self :: LessThan ( span) => span,
372
+ Self :: GreaterThanEqual ( span) => span,
373
+ Self :: GreaterThan ( span) => span,
374
+ Self :: Plus ( span) => span,
375
+ Self :: Minus ( span) => span,
376
+ Self :: Multiply ( span) => span,
377
+ Self :: Exponential ( span) => span,
378
+ Self :: Division ( span) => span,
379
+ Self :: FloorDivision ( span) => span,
380
+ Self :: Modulo ( span) => span,
381
+ Self :: ShiftLeft ( span) => span,
382
+ Self :: ShiftRight ( span) => span,
383
+ Self :: Member ( span) => span,
384
+ } ;
385
+ * span
386
+ }
387
+ }
388
+
310
389
#[ serializable]
311
390
#[ derive( Debug , PartialEq ) ]
312
391
pub struct ArrayExpression {
@@ -403,13 +482,58 @@ pub struct CallExpression {
403
482
pub arguments : Vec < Expression > ,
404
483
}
405
484
485
+ #[ serializable]
486
+ #[ derive( Debug , PartialEq ) ]
487
+ pub struct MemberExpression {
488
+ pub span : Span ,
489
+ pub lhs : Box < MemberExpressionLHS > ,
490
+ pub rhs : Box < MemberExpressionRHS > ,
491
+ }
492
+
493
+ #[ serializable]
494
+ #[ derive( Debug , PartialEq ) ]
495
+ pub enum MemberExpressionLHS {
496
+ Identifier ( Identifier ) ,
497
+ Expression ( Expression ) ,
498
+ Member ( MemberExpression ) ,
499
+ Call ( CallExpression ) ,
500
+ }
501
+
502
+ impl From < MemberExpressionRHS > for MemberExpressionLHS {
503
+ fn from ( value : MemberExpressionRHS ) -> Self {
504
+ match value {
505
+ MemberExpressionRHS :: Number ( num) => {
506
+ Self :: Expression ( Expression :: NumberLiteral ( Box :: from ( num) ) )
507
+ }
508
+ MemberExpressionRHS :: Identifier ( ident) => Self :: Identifier ( ident) ,
509
+ MemberExpressionRHS :: Member ( member) => Self :: Member ( member) ,
510
+ MemberExpressionRHS :: Call ( call) => Self :: Call ( call) ,
511
+ }
512
+ }
513
+ }
514
+
515
+ #[ serializable]
516
+ #[ derive( Debug , PartialEq ) ]
517
+ pub enum MemberExpressionRHS {
518
+ Identifier ( Identifier ) ,
519
+ Number ( NumberLiteral ) ,
520
+ Member ( MemberExpression ) ,
521
+ Call ( CallExpression ) ,
522
+ }
523
+
406
524
#[ serializable]
407
525
#[ derive( Debug , PartialEq ) ]
408
526
pub struct StructConstructionExpression {
409
527
pub target : Expression ,
410
528
pub construction : ConstructionExpression ,
411
529
}
412
530
531
+ impl GetSpan for StructConstructionExpression {
532
+ fn span ( & self ) -> Span {
533
+ Span :: with_spans ( vec ! [ self . target. span( ) , self . construction. span] )
534
+ }
535
+ }
536
+
413
537
#[ serializable]
414
538
#[ derive( Debug , PartialEq ) ]
415
539
pub struct ConstructionExpression {
0 commit comments