Skip to main content

oak_csharp/ast/
mod.rs

1#![doc = include_str!("readme.md")]
2
3use core::range::Range;
4
5/// Root node of the C# AST.
6#[derive(Debug, Clone, PartialEq)]
7#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
8pub struct CSharpRoot {
9    /// Items in the compilation unit.
10    pub items: Vec<Item>,
11}
12
13/// Top-level items in a C# program.
14#[derive(Debug, Clone, PartialEq)]
15#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
16pub enum Item {
17    /// Namespace declaration.
18    Namespace(NamespaceDeclaration),
19    /// Using directive.
20    Using(UsingDirective),
21    /// Class declaration.
22    Class(ClassDeclaration),
23    /// Interface declaration.
24    Interface(InterfaceDeclaration),
25    /// Struct declaration.
26    Struct(StructDeclaration),
27    /// Enum declaration.
28    Enum(EnumDeclaration),
29    /// Record declaration.
30    Record(RecordDeclaration),
31    /// Delegate declaration.
32    Delegate(DelegateDeclaration),
33}
34
35/// Namespace declaration.
36///
37/// Represents a `namespace` block in C#, which groups related classes and other types.
38/// Supports both block-scoped and file-scoped namespaces (C# 10+).
39#[derive(Debug, Clone, PartialEq)]
40#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
41pub struct NamespaceDeclaration {
42    /// The fully qualified name of the namespace (e.g., "System.Collections.Generic").
43    pub name: String,
44    /// Attributes applied to the namespace declaration.
45    pub attributes: Vec<Attribute>,
46    /// Types and nested namespaces defined within this namespace.
47    pub items: Vec<Item>,
48    /// Source location of the entire namespace declaration.
49    #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
50    pub span: Range<usize>,
51}
52
53/// Using directive.
54///
55/// Represents a `using` statement used to import types from a namespace or to create aliases.
56/// Supports `using`, `using static`, and `global using`.
57#[derive(Debug, Clone, PartialEq)]
58#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
59pub struct UsingDirective {
60    /// The namespace or type path being imported.
61    pub path: String,
62    /// Indicates if this is a `using static` directive.
63    pub is_static: bool,
64    /// An optional alias for the namespace or type (e.g., `using Project = MyCompany.Project;`).
65    pub alias: Option<String>,
66    /// Indicates if this is a `global using` directive (C# 10+).
67    pub is_global: bool,
68    /// Source location of the using directive.
69    #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
70    pub span: Range<usize>,
71}
72
73/// Class declaration.
74///
75/// Represents a `class` definition in C#. Classes are the primary reference types
76/// in C# and support inheritance, interfaces, and generics.
77#[derive(Debug, Clone, PartialEq)]
78#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
79pub struct ClassDeclaration {
80    /// The name of the class.
81    pub name: String,
82    /// Attributes applied to the class.
83    pub attributes: Vec<Attribute>,
84    /// Modifiers like `public`, `private`, `static`, `abstract`, `sealed`, `partial`.
85    pub modifiers: Vec<String>,
86    /// The base class and any implemented interfaces.
87    pub base_types: Vec<String>,
88    /// Generic type parameters (e.g., `T` in `List<T>`).
89    pub type_parameters: Vec<TypeParameter>,
90    /// Constraints on generic type parameters (e.g., `where T : class`).
91    pub constraints: Vec<TypeParameterConstraint>,
92    /// Members of the class, including fields, properties, methods, and nested types.
93    pub members: Vec<Member>,
94    /// Source location of the class declaration.
95    #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
96    pub span: Range<usize>,
97}
98
99/// Struct declaration.
100///
101/// Represents a `struct` definition in C#. Structs are value types
102/// and are typically used for small, data-centric structures.
103#[derive(Debug, Clone, PartialEq)]
104#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
105pub struct StructDeclaration {
106    /// The name of the struct.
107    pub name: String,
108    /// Attributes applied to the struct.
109    pub attributes: Vec<Attribute>,
110    /// Modifiers like `public`, `private`, `readonly`, `ref`, `partial`.
111    pub modifiers: Vec<String>,
112    /// Members of the struct.
113    pub members: Vec<Member>,
114    /// Generic type parameters.
115    pub type_parameters: Vec<TypeParameter>,
116    /// Source location of the struct declaration.
117    #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
118    pub span: Range<usize>,
119}
120
121/// Interface declaration.
122///
123/// Represents an `interface` definition in C#. Interfaces define a contract
124/// that classes or structs must implement.
125#[derive(Debug, Clone, PartialEq)]
126#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
127pub struct InterfaceDeclaration {
128    /// The name of the interface.
129    pub name: String,
130    /// Attributes applied to the interface.
131    pub attributes: Vec<Attribute>,
132    /// Modifiers like `public`, `internal`, `partial`.
133    pub modifiers: Vec<String>,
134    /// Members defined in the interface (methods, properties, etc.).
135    pub members: Vec<Member>,
136    /// Generic type parameters.
137    pub type_parameters: Vec<TypeParameter>,
138    /// Source location of the interface declaration.
139    #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
140    pub span: Range<usize>,
141}
142
143/// Enum declaration.
144///
145/// Represents an `enum` definition in C#. Enums are value types that
146/// consist of a set of named constants.
147#[derive(Debug, Clone, PartialEq)]
148#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
149pub struct EnumDeclaration {
150    /// The name of the enum.
151    pub name: String,
152    /// Attributes applied to the enum.
153    pub attributes: Vec<Attribute>,
154    /// Modifiers like `public`, `internal`.
155    pub modifiers: Vec<String>,
156    /// The individual members (constants) of the enum.
157    pub members: Vec<EnumMember>,
158    /// Source location of the enum declaration.
159    #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
160    pub span: Range<usize>,
161}
162
163/// Enum member.
164#[derive(Debug, Clone, PartialEq)]
165#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
166pub struct EnumMember {
167    /// Member name.
168    pub name: String,
169    /// Attributes.
170    pub attributes: Vec<Attribute>,
171    /// Member value.
172    pub value: Option<Expression>,
173}
174
175/// Record declaration.
176///
177/// Represents a `record` definition in C# (C# 9+). Records provide built-in
178/// functionality for encapsulating data and supporting value-based equality.
179#[derive(Debug, Clone, PartialEq)]
180#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
181pub struct RecordDeclaration {
182    /// The name of the record.
183    pub name: String,
184    /// Attributes applied to the record.
185    pub attributes: Vec<Attribute>,
186    /// Modifiers like `public`, `private`, `sealed`, `partial`.
187    pub modifiers: Vec<String>,
188    /// Members of the record.
189    pub members: Vec<Member>,
190    /// Generic type parameters.
191    pub type_parameters: Vec<TypeParameter>,
192    /// Source location of the record declaration.
193    #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
194    pub span: Range<usize>,
195}
196
197/// Delegate declaration.
198///
199/// Represents a `delegate` definition in C#. Delegates are reference types
200/// that represent a method with a particular parameter list and return type.
201#[derive(Debug, Clone, PartialEq)]
202#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
203pub struct DelegateDeclaration {
204    /// The name of the delegate.
205    pub name: String,
206    /// Attributes applied to the delegate.
207    pub attributes: Vec<Attribute>,
208    /// Modifiers like `public`, `internal`.
209    pub modifiers: Vec<String>,
210    /// The return type of the method signature.
211    pub return_type: String,
212    /// Generic type parameters.
213    pub type_parameters: Vec<TypeParameter>,
214    /// The parameters of the delegate method signature.
215    pub parameters: Vec<Parameter>,
216    /// Source location of the delegate declaration.
217    #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
218    pub span: Range<usize>,
219}
220
221/// Member declaration.
222///
223/// Represents various members that can be declared within a class, struct,
224/// or interface.
225#[derive(Debug, Clone, PartialEq)]
226#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
227pub enum Member {
228    /// Method declaration.
229    Method(MethodDeclaration),
230    /// Field declaration.
231    Field(FieldDeclaration),
232    /// Property declaration.
233    Property(PropertyDeclaration),
234    /// Indexer declaration.
235    Indexer(IndexerDeclaration),
236    /// Constructor declaration.
237    Constructor(MethodDeclaration),
238    /// Event declaration.
239    Event(EventDeclaration),
240}
241
242/// Method declaration.
243///
244/// Represents a method or constructor declaration, including its signature,
245/// modifiers, and optional body.
246#[derive(Debug, Clone, PartialEq)]
247#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
248pub struct MethodDeclaration {
249    /// Method name.
250    pub name: String,
251    /// Attributes.
252    pub attributes: Vec<Attribute>,
253    /// Modifiers.
254    pub modifiers: Vec<String>,
255    /// Return type.
256    pub return_type: String,
257    /// Type parameters.
258    pub type_parameters: Vec<TypeParameter>,
259    /// Parameters.
260    pub parameters: Vec<Parameter>,
261    /// Method body.
262    pub body: Option<Vec<Statement>>,
263    /// Whether it's an async method.
264    pub is_async: bool,
265    /// Source location.
266    #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
267    pub span: Range<usize>,
268}
269
270/// Property declaration.
271///
272/// Represents a C# property with optional get and set accessors.
273#[derive(Debug, Clone, PartialEq)]
274#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
275pub struct PropertyDeclaration {
276    /// Property name.
277    pub name: String,
278    /// Attributes.
279    pub attributes: Vec<Attribute>,
280    /// Property type.
281    pub r#type: String,
282    /// Modifiers.
283    pub modifiers: Vec<String>,
284    /// Get accessor.
285    pub get_accessor: Option<Accessor>,
286    /// Set accessor.
287    pub set_accessor: Option<Accessor>,
288    /// Source location.
289    #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
290    pub span: Range<usize>,
291}
292
293/// Accessor (get/set).
294///
295/// Represents a property or indexer accessor, which can contain a body
296/// of statements or be auto-implemented.
297#[derive(Debug, Clone, PartialEq)]
298#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
299pub struct Accessor {
300    /// Attributes.
301    pub attributes: Vec<Attribute>,
302    /// Accessor body.
303    pub body: Option<Vec<Statement>>,
304    /// Modifiers.
305    pub modifiers: Vec<String>,
306}
307
308/// Indexer declaration.
309///
310/// Represents a C# indexer (`this[...]`), which allows objects to be indexed
311/// like arrays.
312#[derive(Debug, Clone, PartialEq)]
313#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
314pub struct IndexerDeclaration {
315    /// Attributes.
316    pub attributes: Vec<Attribute>,
317    /// Indexer type.
318    pub r#type: String,
319    /// Parameters.
320    pub parameters: Vec<Parameter>,
321    /// Get accessor.
322    pub get_accessor: Option<Accessor>,
323    /// Set accessor.
324    pub set_accessor: Option<Accessor>,
325    /// Source location.
326    #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
327    pub span: Range<usize>,
328}
329
330/// Event declaration.
331///
332/// Represents a C# `event` member, which provides a way for a class to notify
333/// other classes when something of interest occurs.
334#[derive(Debug, Clone, PartialEq)]
335#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
336pub struct EventDeclaration {
337    /// Event name.
338    pub name: String,
339    /// Attributes.
340    pub attributes: Vec<Attribute>,
341    /// Event type.
342    pub r#type: String,
343    /// Modifiers.
344    pub modifiers: Vec<String>,
345    /// Source location.
346    #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
347    pub span: Range<usize>,
348}
349
350/// Parameter.
351///
352/// Represents a parameter in a method, constructor, or delegate signature.
353#[derive(Debug, Clone, PartialEq)]
354#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
355pub struct Parameter {
356    /// Attributes.
357    pub attributes: Vec<Attribute>,
358    /// Parameter name.
359    pub name: String,
360    /// Parameter type.
361    pub r#type: String,
362    /// Modifiers (ref, out, params).
363    pub modifiers: Vec<String>,
364    /// Default value.
365    pub default_value: Option<Expression>,
366}
367
368/// Field declaration.
369///
370/// Represents a field within a class or struct.
371#[derive(Debug, Clone, PartialEq)]
372#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
373pub struct FieldDeclaration {
374    /// Field name.
375    pub name: String,
376    /// Attributes.
377    pub attributes: Vec<Attribute>,
378    /// Field type.
379    pub r#type: String,
380    /// Modifiers.
381    pub modifiers: Vec<String>,
382    /// Initializer.
383    pub initializer: Option<Expression>,
384    /// Source location.
385    #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
386    pub span: Range<usize>,
387}
388
389/// Attribute.
390///
391/// Represents a C# attribute applied to a program element (class, method, etc.).
392#[derive(Debug, Clone, PartialEq)]
393#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
394pub struct Attribute {
395    /// Attribute name.
396    pub name: String,
397    /// Argument list.
398    pub arguments: Vec<Expression>,
399    /// Source location.
400    #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
401    pub span: Range<usize>,
402}
403
404/// Type parameter.
405///
406/// Represents a generic type parameter (e.g., `T` in `List<T>`).
407#[derive(Debug, Clone, PartialEq)]
408#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
409pub struct TypeParameter {
410    /// Parameter name.
411    pub name: String,
412    /// Attributes.
413    pub attributes: Vec<Attribute>,
414    /// Variance (in, out).
415    pub variance: Option<String>,
416}
417
418/// Type parameter constraint.
419///
420/// Represents a constraint on a generic type parameter (e.g., `where T : class`).
421#[derive(Debug, Clone, PartialEq)]
422#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
423pub struct TypeParameterConstraint {
424    /// Type parameter name.
425    pub parameter_name: String,
426    /// Constraints.
427    pub constraints: Vec<String>,
428}
429
430/// Statement.
431///
432/// Represents various C# statements that can appear within a method body or block.
433#[derive(Debug, Clone, PartialEq)]
434#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
435pub enum Statement {
436    /// Expression statement.
437    Expression(Expression),
438    /// Return statement.
439    Return(Option<Expression>),
440    /// Block statement.
441    Block(Vec<Statement>),
442    /// If statement.
443    If {
444        /// The condition expression.
445        condition: Expression,
446        /// The then branch statement.
447        then_branch: Box<Statement>,
448        /// The optional else branch statement.
449        else_branch: Option<Box<Statement>>,
450    },
451    /// While loop.
452    While {
453        /// The condition expression.
454        condition: Expression,
455        /// The loop body.
456        body: Box<Statement>,
457    },
458    /// For loop.
459    For {
460        /// The initializer statement.
461        init: Option<Box<Statement>>,
462        /// The condition expression.
463        condition: Option<Expression>,
464        /// The update expression.
465        update: Option<Expression>,
466        /// The loop body.
467        body: Box<Statement>,
468    },
469    /// Foreach loop.
470    Foreach {
471        /// The item type name.
472        item_type: String,
473        /// The item variable name.
474        item_name: String,
475        /// The iterable expression.
476        iterable: Expression,
477        /// The loop body.
478        body: Box<Statement>,
479    },
480    /// Local variable declaration.
481    LocalVariable {
482        /// The variable type name.
483        r#type: String,
484        /// The variable name.
485        name: String,
486        /// The optional initializer expression.
487        initializer: Option<Expression>,
488    },
489    /// Break.
490    Break,
491    /// Continue.
492    Continue,
493}
494
495/// Expression.
496///
497/// Represents various C# expressions that can be evaluated to a value.
498#[derive(Debug, Clone, PartialEq)]
499#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
500pub enum Expression {
501    /// Literal.
502    Literal(Literal),
503    /// Identifier.
504    Identifier(String),
505    /// Method call.
506    MethodCall(MethodCall),
507    /// Member access.
508    MemberAccess(MemberAccess),
509    /// Element access.
510    ElementAccess(ElementAccess),
511    /// New expression.
512    New(NewExpression),
513    /// This expression.
514    This,
515    /// Base expression.
516    Base,
517    /// Binary expression.
518    Binary {
519        /// The left operand.
520        left: Box<Expression>,
521        /// The operator string.
522        op: String,
523        /// The right operand.
524        right: Box<Expression>,
525    },
526    /// Unary expression.
527    Unary {
528        /// The operator string.
529        op: String,
530        /// The operand expression.
531        expression: Box<Expression>,
532    },
533    /// Assignment expression.
534    Assignment {
535        /// The left-hand side expression.
536        left: Box<Expression>,
537        /// The operator string.
538        op: String,
539        /// The right-hand side expression.
540        right: Box<Expression>,
541    },
542    /// Await expression.
543    Await(Box<Expression>),
544    /// LINQ query expression.
545    Query(Box<QueryExpression>),
546}
547
548/// LINQ query expression.
549///
550/// Represents a LINQ query (e.g., `from x in items where x > 0 select x`).
551#[derive(Debug, Clone, PartialEq)]
552#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
553pub struct QueryExpression {
554    /// From clause.
555    pub from_clause: FromClause,
556    /// Query body.
557    pub body: QueryBody,
558}
559
560/// From clause.
561///
562/// Represents a `from` clause in a LINQ query.
563#[derive(Debug, Clone, PartialEq)]
564#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
565pub struct FromClause {
566    /// Identifier.
567    pub identifier: String,
568    /// Expression.
569    pub expression: Box<Expression>,
570}
571
572/// Query body.
573///
574/// Represents the body of a LINQ query, containing clauses and a select/group clause.
575#[derive(Debug, Clone, PartialEq)]
576#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
577pub struct QueryBody {
578    /// Query clauses.
579    pub clauses: Vec<QueryClause>,
580    /// Select or group clause.
581    pub select_or_group: SelectOrGroupClause,
582    /// Continuation (into).
583    pub continuation: Option<String>,
584}
585
586/// Query clause.
587///
588/// Represents a clause within a LINQ query body.
589#[derive(Debug, Clone, PartialEq)]
590#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
591pub enum QueryClause {
592    /// From clause.
593    From(FromClause),
594    /// Let clause.
595    Let(LetClause),
596    /// Where clause.
597    Where(Expression),
598    /// Join clause.
599    Join(JoinClause),
600    /// OrderBy clause.
601    OrderBy(Vec<Ordering>),
602}
603
604/// Query clause extension.
605#[derive(Debug, Clone, PartialEq)]
606#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
607pub enum QueryClauseExt {
608    /// GroupBy clause.
609    GroupBy(Expression),
610}
611
612/// Let clause.
613///
614/// Represents a `let` clause in a LINQ query, used to store sub-expression results.
615#[derive(Debug, Clone, PartialEq)]
616#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
617pub struct LetClause {
618    /// Identifier.
619    pub identifier: String,
620    /// Expression.
621    pub expression: Expression,
622}
623
624/// Join clause.
625///
626/// Represents a `join` clause in a LINQ query.
627#[derive(Debug, Clone, PartialEq)]
628#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
629pub struct JoinClause {
630    /// Identifier.
631    pub identifier: String,
632    /// In expression.
633    pub in_expression: Expression,
634    /// On expression.
635    pub on_expression: Expression,
636    /// Equals expression.
637    pub equals_expression: Expression,
638    /// Into identifier.
639    pub into_identifier: Option<String>,
640}
641
642/// Ordering.
643///
644/// Represents an `orderby` criterion in a LINQ query.
645#[derive(Debug, Clone, PartialEq)]
646#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
647pub struct Ordering {
648    /// Expression.
649    pub expression: Expression,
650    /// Whether it's ascending.
651    pub ascending: bool,
652}
653
654/// Select or group clause.
655///
656/// Represents the final `select` or `group` clause of a LINQ query.
657#[derive(Debug, Clone, PartialEq)]
658#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
659pub enum SelectOrGroupClause {
660    /// Select clause.
661    Select(Expression),
662    /// Group clause.
663    Group {
664        /// Expression.
665        expression: Expression,
666        /// By expression.
667        by_expression: Expression,
668    },
669}
670
671/// New expression.
672///
673/// Represents an object creation expression (e.g., `new MyClass(args)`).
674#[derive(Debug, Clone, PartialEq)]
675#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
676pub struct NewExpression {
677    /// Type name.
678    pub r#type: String,
679    /// Argument list.
680    pub arguments: Vec<Expression>,
681}
682
683/// Literal.
684///
685/// Represents a constant value of a primitive type.
686#[derive(Debug, Clone, PartialEq)]
687#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
688pub enum Literal {
689    /// Integer.
690    Integer(i64),
691    /// String.
692    String(String),
693    /// Boolean.
694    Boolean(bool),
695    /// Null.
696    Null,
697}
698
699/// Member access.
700///
701/// Represents accessing a member of an object (e.g., `obj.Member`).
702#[derive(Debug, Clone, PartialEq)]
703#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
704pub struct MemberAccess {
705    /// Target expression.
706    pub target: Box<Expression>,
707    /// Member name.
708    pub name: String,
709}
710
711/// Method call.
712///
713/// Represents a method invocation (e.g., `target.Method(args)` or `Method(args)`).
714#[derive(Debug, Clone, PartialEq)]
715#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
716pub struct MethodCall {
717    /// Target expression.
718    pub target: Option<Box<Expression>>,
719    /// Method name.
720    pub name: String,
721    /// Argument list.
722    pub arguments: Vec<Expression>,
723}
724
725/// Element access (indexer).
726///
727/// Represents an element access via indexers (e.g., `array[index]`).
728#[derive(Debug, Clone, PartialEq)]
729#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
730pub struct ElementAccess {
731    /// Target expression.
732    pub target: Box<Expression>,
733    /// Argument list.
734    pub arguments: Vec<Expression>,
735}