oak-csharp 0.0.11

C# frontend for Oak
Documentation
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
#![doc = include_str!("readme.md")]

use core::range::Range;

/// Root node of the C# AST.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct CSharpRoot {
    /// Items in the compilation unit.
    pub items: Vec<Item>,
}

/// Top-level items in a C# program.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum Item {
    /// Namespace declaration.
    Namespace(NamespaceDeclaration),
    /// Using directive.
    Using(UsingDirective),
    /// Class declaration.
    Class(ClassDeclaration),
    /// Interface declaration.
    Interface(InterfaceDeclaration),
    /// Struct declaration.
    Struct(StructDeclaration),
    /// Enum declaration.
    Enum(EnumDeclaration),
    /// Record declaration.
    Record(RecordDeclaration),
    /// Delegate declaration.
    Delegate(DelegateDeclaration),
}

/// Namespace declaration.
///
/// Represents a `namespace` block in C#, which groups related classes and other types.
/// Supports both block-scoped and file-scoped namespaces (C# 10+).
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct NamespaceDeclaration {
    /// The fully qualified name of the namespace (e.g., "System.Collections.Generic").
    pub name: String,
    /// Attributes applied to the namespace declaration.
    pub attributes: Vec<Attribute>,
    /// Types and nested namespaces defined within this namespace.
    pub items: Vec<Item>,
    /// Source location of the entire namespace declaration.
    #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
    pub span: Range<usize>,
}

/// Using directive.
///
/// Represents a `using` statement used to import types from a namespace or to create aliases.
/// Supports `using`, `using static`, and `global using`.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct UsingDirective {
    /// The namespace or type path being imported.
    pub path: String,
    /// Indicates if this is a `using static` directive.
    pub is_static: bool,
    /// An optional alias for the namespace or type (e.g., `using Project = MyCompany.Project;`).
    pub alias: Option<String>,
    /// Indicates if this is a `global using` directive (C# 10+).
    pub is_global: bool,
    /// Source location of the using directive.
    #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
    pub span: Range<usize>,
}

/// Class declaration.
///
/// Represents a `class` definition in C#. Classes are the primary reference types
/// in C# and support inheritance, interfaces, and generics.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ClassDeclaration {
    /// The name of the class.
    pub name: String,
    /// Attributes applied to the class.
    pub attributes: Vec<Attribute>,
    /// Modifiers like `public`, `private`, `static`, `abstract`, `sealed`, `partial`.
    pub modifiers: Vec<String>,
    /// The base class and any implemented interfaces.
    pub base_types: Vec<String>,
    /// Generic type parameters (e.g., `T` in `List<T>`).
    pub type_parameters: Vec<TypeParameter>,
    /// Constraints on generic type parameters (e.g., `where T : class`).
    pub constraints: Vec<TypeParameterConstraint>,
    /// Members of the class, including fields, properties, methods, and nested types.
    pub members: Vec<Member>,
    /// Source location of the class declaration.
    #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
    pub span: Range<usize>,
}

/// Struct declaration.
///
/// Represents a `struct` definition in C#. Structs are value types
/// and are typically used for small, data-centric structures.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct StructDeclaration {
    /// The name of the struct.
    pub name: String,
    /// Attributes applied to the struct.
    pub attributes: Vec<Attribute>,
    /// Modifiers like `public`, `private`, `readonly`, `ref`, `partial`.
    pub modifiers: Vec<String>,
    /// Members of the struct.
    pub members: Vec<Member>,
    /// Generic type parameters.
    pub type_parameters: Vec<TypeParameter>,
    /// Source location of the struct declaration.
    #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
    pub span: Range<usize>,
}

/// Interface declaration.
///
/// Represents an `interface` definition in C#. Interfaces define a contract
/// that classes or structs must implement.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct InterfaceDeclaration {
    /// The name of the interface.
    pub name: String,
    /// Attributes applied to the interface.
    pub attributes: Vec<Attribute>,
    /// Modifiers like `public`, `internal`, `partial`.
    pub modifiers: Vec<String>,
    /// Members defined in the interface (methods, properties, etc.).
    pub members: Vec<Member>,
    /// Generic type parameters.
    pub type_parameters: Vec<TypeParameter>,
    /// Source location of the interface declaration.
    #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
    pub span: Range<usize>,
}

/// Enum declaration.
///
/// Represents an `enum` definition in C#. Enums are value types that
/// consist of a set of named constants.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct EnumDeclaration {
    /// The name of the enum.
    pub name: String,
    /// Attributes applied to the enum.
    pub attributes: Vec<Attribute>,
    /// Modifiers like `public`, `internal`.
    pub modifiers: Vec<String>,
    /// The individual members (constants) of the enum.
    pub members: Vec<EnumMember>,
    /// Source location of the enum declaration.
    #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
    pub span: Range<usize>,
}

/// Enum member.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct EnumMember {
    /// Member name.
    pub name: String,
    /// Attributes.
    pub attributes: Vec<Attribute>,
    /// Member value.
    pub value: Option<Expression>,
}

/// Record declaration.
///
/// Represents a `record` definition in C# (C# 9+). Records provide built-in
/// functionality for encapsulating data and supporting value-based equality.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct RecordDeclaration {
    /// The name of the record.
    pub name: String,
    /// Attributes applied to the record.
    pub attributes: Vec<Attribute>,
    /// Modifiers like `public`, `private`, `sealed`, `partial`.
    pub modifiers: Vec<String>,
    /// Members of the record.
    pub members: Vec<Member>,
    /// Generic type parameters.
    pub type_parameters: Vec<TypeParameter>,
    /// Source location of the record declaration.
    #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
    pub span: Range<usize>,
}

/// Delegate declaration.
///
/// Represents a `delegate` definition in C#. Delegates are reference types
/// that represent a method with a particular parameter list and return type.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct DelegateDeclaration {
    /// The name of the delegate.
    pub name: String,
    /// Attributes applied to the delegate.
    pub attributes: Vec<Attribute>,
    /// Modifiers like `public`, `internal`.
    pub modifiers: Vec<String>,
    /// The return type of the method signature.
    pub return_type: String,
    /// Generic type parameters.
    pub type_parameters: Vec<TypeParameter>,
    /// The parameters of the delegate method signature.
    pub parameters: Vec<Parameter>,
    /// Source location of the delegate declaration.
    #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
    pub span: Range<usize>,
}

/// Member declaration.
///
/// Represents various members that can be declared within a class, struct,
/// or interface.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum Member {
    /// Method declaration.
    Method(MethodDeclaration),
    /// Field declaration.
    Field(FieldDeclaration),
    /// Property declaration.
    Property(PropertyDeclaration),
    /// Indexer declaration.
    Indexer(IndexerDeclaration),
    /// Constructor declaration.
    Constructor(MethodDeclaration),
    /// Event declaration.
    Event(EventDeclaration),
}

/// Method declaration.
///
/// Represents a method or constructor declaration, including its signature,
/// modifiers, and optional body.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct MethodDeclaration {
    /// Method name.
    pub name: String,
    /// Attributes.
    pub attributes: Vec<Attribute>,
    /// Modifiers.
    pub modifiers: Vec<String>,
    /// Return type.
    pub return_type: String,
    /// Type parameters.
    pub type_parameters: Vec<TypeParameter>,
    /// Parameters.
    pub parameters: Vec<Parameter>,
    /// Method body.
    pub body: Option<Vec<Statement>>,
    /// Whether it's an async method.
    pub is_async: bool,
    /// Source location.
    #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
    pub span: Range<usize>,
}

/// Property declaration.
///
/// Represents a C# property with optional get and set accessors.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct PropertyDeclaration {
    /// Property name.
    pub name: String,
    /// Attributes.
    pub attributes: Vec<Attribute>,
    /// Property type.
    pub r#type: String,
    /// Modifiers.
    pub modifiers: Vec<String>,
    /// Get accessor.
    pub get_accessor: Option<Accessor>,
    /// Set accessor.
    pub set_accessor: Option<Accessor>,
    /// Source location.
    #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
    pub span: Range<usize>,
}

/// Accessor (get/set).
///
/// Represents a property or indexer accessor, which can contain a body
/// of statements or be auto-implemented.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Accessor {
    /// Attributes.
    pub attributes: Vec<Attribute>,
    /// Accessor body.
    pub body: Option<Vec<Statement>>,
    /// Modifiers.
    pub modifiers: Vec<String>,
}

/// Indexer declaration.
///
/// Represents a C# indexer (`this[...]`), which allows objects to be indexed
/// like arrays.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct IndexerDeclaration {
    /// Attributes.
    pub attributes: Vec<Attribute>,
    /// Indexer type.
    pub r#type: String,
    /// Parameters.
    pub parameters: Vec<Parameter>,
    /// Get accessor.
    pub get_accessor: Option<Accessor>,
    /// Set accessor.
    pub set_accessor: Option<Accessor>,
    /// Source location.
    #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
    pub span: Range<usize>,
}

/// Event declaration.
///
/// Represents a C# `event` member, which provides a way for a class to notify
/// other classes when something of interest occurs.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct EventDeclaration {
    /// Event name.
    pub name: String,
    /// Attributes.
    pub attributes: Vec<Attribute>,
    /// Event type.
    pub r#type: String,
    /// Modifiers.
    pub modifiers: Vec<String>,
    /// Source location.
    #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
    pub span: Range<usize>,
}

/// Parameter.
///
/// Represents a parameter in a method, constructor, or delegate signature.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Parameter {
    /// Attributes.
    pub attributes: Vec<Attribute>,
    /// Parameter name.
    pub name: String,
    /// Parameter type.
    pub r#type: String,
    /// Modifiers (ref, out, params).
    pub modifiers: Vec<String>,
    /// Default value.
    pub default_value: Option<Expression>,
}

/// Field declaration.
///
/// Represents a field within a class or struct.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct FieldDeclaration {
    /// Field name.
    pub name: String,
    /// Attributes.
    pub attributes: Vec<Attribute>,
    /// Field type.
    pub r#type: String,
    /// Modifiers.
    pub modifiers: Vec<String>,
    /// Initializer.
    pub initializer: Option<Expression>,
    /// Source location.
    #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
    pub span: Range<usize>,
}

/// Attribute.
///
/// Represents a C# attribute applied to a program element (class, method, etc.).
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Attribute {
    /// Attribute name.
    pub name: String,
    /// Argument list.
    pub arguments: Vec<Expression>,
    /// Source location.
    #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
    pub span: Range<usize>,
}

/// Type parameter.
///
/// Represents a generic type parameter (e.g., `T` in `List<T>`).
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct TypeParameter {
    /// Parameter name.
    pub name: String,
    /// Attributes.
    pub attributes: Vec<Attribute>,
    /// Variance (in, out).
    pub variance: Option<String>,
}

/// Type parameter constraint.
///
/// Represents a constraint on a generic type parameter (e.g., `where T : class`).
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct TypeParameterConstraint {
    /// Type parameter name.
    pub parameter_name: String,
    /// Constraints.
    pub constraints: Vec<String>,
}

/// Statement.
///
/// Represents various C# statements that can appear within a method body or block.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum Statement {
    /// Expression statement.
    Expression(Expression),
    /// Return statement.
    Return(Option<Expression>),
    /// Block statement.
    Block(Vec<Statement>),
    /// If statement.
    If {
        /// The condition expression.
        condition: Expression,
        /// The then branch statement.
        then_branch: Box<Statement>,
        /// The optional else branch statement.
        else_branch: Option<Box<Statement>>,
    },
    /// While loop.
    While {
        /// The condition expression.
        condition: Expression,
        /// The loop body.
        body: Box<Statement>,
    },
    /// For loop.
    For {
        /// The initializer statement.
        init: Option<Box<Statement>>,
        /// The condition expression.
        condition: Option<Expression>,
        /// The update expression.
        update: Option<Expression>,
        /// The loop body.
        body: Box<Statement>,
    },
    /// Foreach loop.
    Foreach {
        /// The item type name.
        item_type: String,
        /// The item variable name.
        item_name: String,
        /// The iterable expression.
        iterable: Expression,
        /// The loop body.
        body: Box<Statement>,
    },
    /// Local variable declaration.
    LocalVariable {
        /// The variable type name.
        r#type: String,
        /// The variable name.
        name: String,
        /// The optional initializer expression.
        initializer: Option<Expression>,
    },
    /// Break.
    Break,
    /// Continue.
    Continue,
}

/// Expression.
///
/// Represents various C# expressions that can be evaluated to a value.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum Expression {
    /// Literal.
    Literal(Literal),
    /// Identifier.
    Identifier(String),
    /// Method call.
    MethodCall(MethodCall),
    /// Member access.
    MemberAccess(MemberAccess),
    /// Element access.
    ElementAccess(ElementAccess),
    /// New expression.
    New(NewExpression),
    /// This expression.
    This,
    /// Base expression.
    Base,
    /// Binary expression.
    Binary {
        /// The left operand.
        left: Box<Expression>,
        /// The operator string.
        op: String,
        /// The right operand.
        right: Box<Expression>,
    },
    /// Unary expression.
    Unary {
        /// The operator string.
        op: String,
        /// The operand expression.
        expression: Box<Expression>,
    },
    /// Assignment expression.
    Assignment {
        /// The left-hand side expression.
        left: Box<Expression>,
        /// The operator string.
        op: String,
        /// The right-hand side expression.
        right: Box<Expression>,
    },
    /// Await expression.
    Await(Box<Expression>),
    /// LINQ query expression.
    Query(Box<QueryExpression>),
}

/// LINQ query expression.
///
/// Represents a LINQ query (e.g., `from x in items where x > 0 select x`).
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct QueryExpression {
    /// From clause.
    pub from_clause: FromClause,
    /// Query body.
    pub body: QueryBody,
}

/// From clause.
///
/// Represents a `from` clause in a LINQ query.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct FromClause {
    /// Identifier.
    pub identifier: String,
    /// Expression.
    pub expression: Box<Expression>,
}

/// Query body.
///
/// Represents the body of a LINQ query, containing clauses and a select/group clause.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct QueryBody {
    /// Query clauses.
    pub clauses: Vec<QueryClause>,
    /// Select or group clause.
    pub select_or_group: SelectOrGroupClause,
    /// Continuation (into).
    pub continuation: Option<String>,
}

/// Query clause.
///
/// Represents a clause within a LINQ query body.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum QueryClause {
    /// From clause.
    From(FromClause),
    /// Let clause.
    Let(LetClause),
    /// Where clause.
    Where(Expression),
    /// Join clause.
    Join(JoinClause),
    /// OrderBy clause.
    OrderBy(Vec<Ordering>),
}

/// Query clause extension.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum QueryClauseExt {
    /// GroupBy clause.
    GroupBy(Expression),
}

/// Let clause.
///
/// Represents a `let` clause in a LINQ query, used to store sub-expression results.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct LetClause {
    /// Identifier.
    pub identifier: String,
    /// Expression.
    pub expression: Expression,
}

/// Join clause.
///
/// Represents a `join` clause in a LINQ query.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct JoinClause {
    /// Identifier.
    pub identifier: String,
    /// In expression.
    pub in_expression: Expression,
    /// On expression.
    pub on_expression: Expression,
    /// Equals expression.
    pub equals_expression: Expression,
    /// Into identifier.
    pub into_identifier: Option<String>,
}

/// Ordering.
///
/// Represents an `orderby` criterion in a LINQ query.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Ordering {
    /// Expression.
    pub expression: Expression,
    /// Whether it's ascending.
    pub ascending: bool,
}

/// Select or group clause.
///
/// Represents the final `select` or `group` clause of a LINQ query.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum SelectOrGroupClause {
    /// Select clause.
    Select(Expression),
    /// Group clause.
    Group {
        /// Expression.
        expression: Expression,
        /// By expression.
        by_expression: Expression,
    },
}

/// New expression.
///
/// Represents an object creation expression (e.g., `new MyClass(args)`).
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct NewExpression {
    /// Type name.
    pub r#type: String,
    /// Argument list.
    pub arguments: Vec<Expression>,
}

/// Literal.
///
/// Represents a constant value of a primitive type.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum Literal {
    /// Integer.
    Integer(i64),
    /// String.
    String(String),
    /// Boolean.
    Boolean(bool),
    /// Null.
    Null,
}

/// Member access.
///
/// Represents accessing a member of an object (e.g., `obj.Member`).
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct MemberAccess {
    /// Target expression.
    pub target: Box<Expression>,
    /// Member name.
    pub name: String,
}

/// Method call.
///
/// Represents a method invocation (e.g., `target.Method(args)` or `Method(args)`).
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct MethodCall {
    /// Target expression.
    pub target: Option<Box<Expression>>,
    /// Method name.
    pub name: String,
    /// Argument list.
    pub arguments: Vec<Expression>,
}

/// Element access (indexer).
///
/// Represents an element access via indexers (e.g., `array[index]`).
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ElementAccess {
    /// Target expression.
    pub target: Box<Expression>,
    /// Argument list.
    pub arguments: Vec<Expression>,
}