oak-rust 0.0.11

High-performance incremental Rust parser for the oak ecosystem with flexible configuration, emphasizing memory safety and zero-cost abstractions.
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
736
737
#![doc = include_str!("readme.md")]
use crate::lexer::RustTokenType;
use core::range::Range;

use std::sync::Arc;

/// Strongly-typed AST root node representing the entire Rust source file.
///
/// This is the top-level structure that contains all items (functions, statements, etc.)
/// parsed from a Rust source file.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct RustRoot {
    /// Collection of top-level items in the Rust file
    pub items: Vec<Item>,
}

/// Represents a generic parameter list and where clauses in Rust.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Generics {
    /// List of generic parameters (lifetimes, types, constants)
    pub params: Vec<GenericParam>,
    /// Optional where clause
    pub where_clause: Option<WhereClause>,
    /// Source code span
    #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
    pub span: Range<usize>,
}

/// Represents a single generic parameter.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum GenericParam {
    /// A lifetime parameter (e.g., `'a`)
    Lifetime(Lifetime),
    /// A type parameter (e.g., `T: Display`)
    Type {
        /// The type parameter name
        name: Identifier,
        /// Optional bounds (e.g., `: Display + Clone`)
        bounds: Vec<TypeParamBound>,
        /// Optional default type (e.g., `= i32`)
        default: Option<Type>,
    },
    /// A const parameter (e.g., `const N: usize`)
    Const {
        /// The const parameter name
        name: Identifier,
        /// The type of the constant
        ty: Type,
        /// Optional default value
        default: Option<Expr>,
    },
}

/// Represents a lifetime in Rust (e.g., `'a`, `'static`).
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Lifetime {
    /// The name of the lifetime (including the leading quote)
    pub name: String,
    /// Source code span
    #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
    pub span: Range<usize>,
}

/// Represents a bound on a type parameter.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum TypeParamBound {
    /// A trait bound (e.g., `Display`)
    Trait(Type),
    /// A lifetime bound (e.g., `'a`)
    Lifetime(Lifetime),
}

/// Represents a where clause in Rust.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct WhereClause {
    /// List of where predicates
    pub predicates: Vec<WherePredicate>,
    /// Source code span
    #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
    pub span: Range<usize>,
}

/// Represents a single predicate in a where clause.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum WherePredicate {
    /// A type predicate (e.g., `T: Display`)
    Type {
        /// The type being bounded
        bounded_ty: Type,
        /// The bounds applied to the type
        bounds: Vec<TypeParamBound>,
    },
    /// A lifetime predicate (e.g., `'a: 'b`)
    Lifetime {
        /// The lifetime being bounded
        lifetime: Lifetime,
        /// The bounds applied to the lifetime
        bounds: Vec<Lifetime>,
    },
}

/// Represents an identifier in Rust source code.
///
/// Identifiers are names used for variables, functions, types, and other named entities.
/// Each identifier carries its textual representation and source location information.
///
/// # Examples
///
/// ```rust,ignore
/// /// use oak_rust::ast::Identifier;
/// let ident = Identifier { name: "main".to_string(), span: 0..4 }
/// assert_eq!(ident.name, "main");
/// ```
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Identifier {
    /// The textual name of the identifier
    pub name: String,
    /// Source code span where this identifier appears
    #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
    pub span: Range<usize>,
}

/// Top-level items that can appear in a Rust source file.
///
/// These represent the main constructs that can exist at the module level,
/// such as function definitions, structs, enums, modules, and other declarations.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum Item {
    /// A function definition
    Function(Arc<Function>),
    /// A struct definition
    Struct(Arc<Struct>),
    /// An enum definition
    Enum(Arc<Enum>),
    /// A module definition
    Module(Arc<Module>),
    /// A use statement
    Use(Arc<UseItem>),
    /// A trait definition
    Trait(Arc<Trait>),
    /// An impl block
    Impl(Arc<Impl>),
    /// A type alias
    TypeAlias(Arc<TypeAlias>),
    /// A constant definition
    Const(Arc<Const>),
    /// A static definition
    Static(Arc<Static>),
    /// An extern block
    ExternBlock(Arc<ExternBlock>),
}

/// Represents a function definition in Rust source code.
///
/// Functions are fundamental building blocks in Rust that encapsulate reusable logic.
/// They can have parameters, return types, and contain executable code blocks.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Function {
    /// The name identifier of the function
    pub name: Identifier,
    /// List of function parameters
    pub params: Vec<Param>,
    /// Optional return type
    pub return_type: Option<Type>,
    /// The function body containing executable statements
    pub body: Block,
    /// Generic parameters and where clauses
    pub generics: Option<Generics>,
    /// Whether the function is async
    pub is_async: bool,
    /// Whether the function is unsafe
    pub is_unsafe: bool,
    /// Whether the function is extern
    pub is_extern: bool,
    /// Source code span where this function appears
    #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
    pub span: Range<usize>,
}

/// Represents a struct definition in Rust source code.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Struct {
    /// The name identifier of the struct
    pub name: Identifier,
    /// Generic parameters and where clauses
    pub generics: Option<Generics>,
    /// List of struct fields
    pub fields: Vec<Field>,
    /// Source code span where this struct appears
    #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
    pub span: Range<usize>,
}

/// Represents a field in a struct definition.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Field {
    /// The field name identifier
    pub name: Identifier,
    /// The field type
    pub ty: Type,
    /// Source code span where this field appears
    #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
    pub span: Range<usize>,
}

/// Represents an enum definition in Rust source code.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Enum {
    /// The name identifier of the enum
    pub name: Identifier,
    /// Generic parameters and where clauses
    pub generics: Option<Generics>,
    /// List of enum variants
    pub variants: Vec<Variant>,
    /// Source code span where this enum appears
    #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
    pub span: Range<usize>,
}

/// Represents a variant in an enum definition.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Variant {
    /// The variant name identifier
    pub name: Identifier,
    /// Optional fields for tuple or struct variants
    pub fields: Option<Vec<Field>>,
    /// Source code span where this variant appears
    #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
    pub span: Range<usize>,
}

/// Represents a module definition in Rust source code.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Module {
    /// The name identifier of the module
    pub name: Identifier,
    /// List of items within the module
    pub items: Vec<Item>,
    /// Source code span where this module appears
    #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
    pub span: Range<usize>,
}

/// Represents a use statement in Rust source code.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct UseItem {
    /// The path being imported
    pub path: String,
    /// Source code span where this use statement appears
    #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
    pub span: Range<usize>,
}

/// Represents a trait definition in Rust source code.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Trait {
    /// The name identifier of the trait
    pub name: Identifier,
    /// Generic parameters and where clauses
    pub generics: Option<Generics>,
    /// List of trait items (methods, associated types, etc.)
    pub items: Vec<TraitItem>,
    /// Source code span where this trait appears
    #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
    pub span: Range<usize>,
}

/// Represents items within a trait definition.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum TraitItem {
    /// A method signature
    Method(Function),
    /// An associated type
    Type(TypeAlias),
}

/// Represents an impl block in Rust source code.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Impl {
    /// Generic parameters and where clauses
    pub generics: Option<Generics>,
    /// The type being implemented for
    pub ty: Type,
    /// Optional trait being implemented
    pub trait_: Option<Type>,
    /// List of implementation items
    pub items: Vec<ImplItem>,
    /// Source code span where this impl block appears
    #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
    pub span: Range<usize>,
}

/// Represents items within an impl block.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum ImplItem {
    /// A method implementation
    Method(Function),
    /// An associated type implementation
    Type(TypeAlias),
    /// An associated constant
    Const(Const),
}

/// Represents a type alias in Rust source code.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct TypeAlias {
    /// The alias name identifier
    pub name: Identifier,
    /// Generic parameters and where clauses
    pub generics: Option<Generics>,
    /// The target type
    pub ty: Type,
    /// Source code span where this type alias appears
    #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
    pub span: Range<usize>,
}

/// Represents a constant definition in Rust source code.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Const {
    /// The constant name identifier
    pub name: Identifier,
    /// The constant type
    pub ty: Type,
    /// The constant value expression
    pub expr: Expr,
    /// Source code span where this constant appears
    #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
    pub span: Range<usize>,
}

/// Represents a static definition in Rust source code.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Static {
    /// The static name identifier
    pub name: Identifier,
    /// The static type
    pub ty: Type,
    /// The static value expression
    pub expr: Expr,
    /// Whether the static is mutable
    pub mutable: bool,
    /// Source code span where this static appears
    #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
    pub span: Range<usize>,
}

/// Represents a type in Rust source code.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum Type {
    /// A path type (e.g., std::vec::Vec)
    Path(String),
    /// A reference type (e.g., &str, &mut T)
    Reference {
        /// Whether the reference is mutable
        mutable: bool,
        /// The referenced type
        ty: Box<Type>,
    },
    /// A tuple type (e.g., (i32, String))
    Tuple(Vec<Type>),
    /// An array type (e.g., [i32; 10])
    Array {
        /// The element type
        ty: Box<Type>,
        /// The array size expression
        size: Expr,
    },
    /// A slice type (e.g., [i32])
    Slice(Box<Type>),
    /// A function pointer type (e.g., fn(i32) -> String)
    Fn {
        /// Parameter types
        params: Vec<Type>,
        /// Return type
        ret: Option<Box<Type>>,
    },
    /// An inferred type (_)
    Infer,
}

/// Represents a function parameter with its type annotation.
///
/// Parameters define the inputs that a function can accept, with their respective types.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Param {
    /// The parameter name identifier
    pub name: Identifier,
    /// The parameter type
    pub ty: Type,
    /// Whether the parameter is mutable
    pub is_mut: bool,
    /// Source code span where this parameter appears
    #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
    pub span: Range<usize>,
}

/// Represents a block of statements enclosed in braces.
///
/// Blocks are used to group statements together and define scope boundaries.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Block {
    /// List of statements within the block
    pub statements: Vec<Statement>,
    /// Block start position
    pub block_start: usize,
    /// Block end position
    pub block_end: usize,
    /// Nested block level
    pub nested: usize,
    /// Source code span where this block appears
    #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
    pub span: Range<usize>,
}

/// Represents different types of statements in Rust source code.
///
/// Statements are executable units that raise actions or declare bindings.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum Statement {
    /// A let binding statement
    Let {
        /// The variable name being bound
        name: Identifier,
        /// Optional type annotation
        ty: Option<Type>,
        /// The expression being assigned to the variable
        expr: Option<Expr>,
        /// Whether the binding is mutable
        mutable: bool,
        /// Source code span where this let statement appears
        #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
        span: Range<usize>,
    },
    /// An expression statement (expression followed by optional semicolon)
    ExprStmt {
        /// The expression being evaluated
        expr: Expr,
        /// Whether the statement ends with a semicolon
        semi: bool,
        /// Source code span where this expression statement appears
        #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
        span: Range<usize>,
    },
    /// A return statement
    Return {
        /// Optional return expression
        expr: Option<Expr>,
        /// Source code span where this return statement appears
        #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
        span: Range<usize>,
    },
    /// A break statement
    Break {
        /// Optional break expression
        expr: Option<Expr>,
        /// Source code span where this break statement appears
        #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
        span: Range<usize>,
    },
    /// A continue statement
    Continue {
        /// Source code span where this continue statement appears
        #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
        span: Range<usize>,
    },
    /// An item statement (item declaration within a block)
    Item(Item),
}

/// Represents different types of expressions in Rust source code.
///
/// Expressions are constructs that evaluate to values and can be used in various contexts.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum Expr {
    /// An identifier expression
    Ident(Identifier),
    /// A literal expression
    Literal {
        /// The literal value as a string
        value: String,
        /// Source code span where this literal appears
        #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
        span: Range<usize>,
    },
    /// A boolean literal expression
    Bool {
        /// The boolean value
        value: bool,
        /// Source code span where this boolean literal appears
        #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
        span: Range<usize>,
    },
    /// A unary expression (e.g., !x, -x, *x, &x)
    Unary {
        /// The unary operator
        op: RustTokenType,
        /// The operand expression
        expr: Box<Expr>,
        /// Source code span where this unary expression appears
        #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
        span: Range<usize>,
    },
    /// A binary expression (e.g., x + y, x == y)
    Binary {
        /// The left operand
        left: Box<Expr>,
        /// The binary operator
        op: RustTokenType,
        /// The right operand
        right: Box<Expr>,
        /// Source code span where this binary expression appears
        #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
        span: Range<usize>,
    },
    /// A function call expression
    Call {
        /// The function being called
        callee: Box<Expr>,
        /// The arguments passed to the function
        args: Vec<Expr>,
        /// Source code span where this call expression appears
        #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
        span: Range<usize>,
    },
    /// A field access expression (e.g., obj.field)
    Field {
        /// The object being accessed
        receiver: Box<Expr>,
        /// The field being accessed
        field: Identifier,
        /// Source code span where this field expression appears
        #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
        span: Range<usize>,
    },
    /// An index expression (e.g., arr[0])
    Index {
        /// The object being indexed
        receiver: Box<Expr>,
        /// The index expression
        index: Box<Expr>,
        /// Source code span where this index expression appears
        #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
        span: Range<usize>,
    },
    /// A parenthesized expression
    Paren {
        /// The inner expression
        expr: Box<Expr>,
        /// Source code span where this parenthesized expression appears
        #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
        span: Range<usize>,
    },
    /// A block expression
    Block(Block),
    /// An if expression
    If {
        /// The condition expression
        condition: Box<Expr>,
        /// The then block
        then_block: Block,
        /// Optional else block
        else_block: Option<Block>,
        /// Source code span where this if expression appears
        #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
        span: Range<usize>,
    },
    /// A while loop expression
    While {
        /// The condition expression
        condition: Box<Expr>,
        /// The loop body
        body: Block,
        /// Source code span where this while expression appears
        #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
        span: Range<usize>,
    },
    /// A for loop expression
    For {
        /// The loop variable
        var: Identifier,
        /// The iterable expression
        iter: Box<Expr>,
        /// The loop body
        body: Block,
        /// Source code span where this for expression appears
        #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
        span: Range<usize>,
    },
    /// A loop expression
    Loop {
        /// The loop body
        body: Block,
        /// Source code span where this loop expression appears
        #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
        span: Range<usize>,
    },
    /// A match expression
    Match {
        /// The expression being matched
        expr: Box<Expr>,
        /// The match arms
        arms: Vec<MatchArm>,
        /// Source code span where this match expression appears
        #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
        span: Range<usize>,
    },
    /// A tuple expression
    Tuple {
        /// The tuple elements
        elements: Vec<Expr>,
        /// Source code span where this tuple expression appears
        #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
        span: Range<usize>,
    },
    /// An array expression
    Array {
        /// The array elements
        elements: Vec<Expr>,
        /// Source code span where this array expression appears
        #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
        span: Range<usize>,
    },
    /// A struct expression
    Struct {
        /// The struct path
        path: String,
        /// The struct fields
        fields: Vec<FieldInit>,
        /// Source code span where this struct expression appears
        #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
        span: Range<usize>,
    },
}

/// Represents a match arm in a match expression.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct MatchArm {
    /// The pattern to match
    pub pattern: Pattern,
    /// Optional guard expression
    pub guard: Option<Expr>,
    /// The arm body expression
    pub body: Expr,
    /// Source code span where this match arm appears
    #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
    pub span: Range<usize>,
}

/// Represents a pattern in pattern matching.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum Pattern {
    /// A wildcard pattern (_)
    Wildcard,
    /// An identifier pattern
    Ident(Identifier),
    /// A literal pattern
    Literal(String),
    /// A tuple pattern
    Tuple(Vec<Pattern>),
    /// A struct pattern
    Struct {
        /// The struct path
        path: String,
        /// The field patterns
        fields: Vec<FieldPattern>,
    },
}

/// Represents a field pattern in a struct pattern.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct FieldPattern {
    /// The field name
    pub name: Identifier,
    /// The field pattern
    pub pattern: Pattern,
    /// Source code span where this field pattern appears
    #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
    pub span: Range<usize>,
}

/// Represents a field initialization in a struct expression.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct FieldInit {
    /// The field name
    pub name: Identifier,
    /// The field value expression
    pub expr: Expr,
    /// Source code span where this field initialization appears
    #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
    pub span: Range<usize>,
}

/// Represents an extern block in Rust source code.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ExternBlock {
    /// The ABI string (e.g., "C", "system")
    pub abi: Option<String>,
    /// List of items within the extern block
    pub items: Vec<Item>,
    /// Source code span where this extern block appears
    #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
    pub span: Range<usize>,
}