Skip to main content

oak_valkyrie/ast/
root_nodes.rs

1use super::Item;
2
3/// Source code span
4pub type Span = oak_core::Range<usize>;
5
6/// Loop keyword kind for deprecation warnings.
7#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
8#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
9pub enum LoopKind {
10    /// Using `loop` keyword (preferred).
11    #[default]
12    Loop,
13    /// Using `for` keyword (deprecated, use `loop` instead).
14    For,
15}
16
17/// Structure keyword kind for class-like definitions.
18#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
19#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
20pub enum StructureKind {
21    /// Using `class` keyword.
22    #[default]
23    Class,
24    /// Using `struct` keyword (deprecated, use `class` instead).
25    Struct,
26    /// Using `structure` keyword.
27    Structure,
28    /// Using `widget` keyword.
29    Widget,
30    /// Using `trait` keyword.
31    Trait,
32}
33
34/// Enums keyword kind for deprecation warnings.
35#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
36#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
37pub enum EnumsKind {
38    /// Using `enums` keyword (preferred).
39    #[default]
40    Enums,
41    /// Using `enum` keyword (deprecated, use `unity` instead).
42    Enum,
43    /// Using `unity` keyword (preferred alternative).
44    Unity,
45}
46
47/// An identifier
48#[derive(Debug, Clone, PartialEq, Eq, Hash)]
49#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
50pub struct Identifier {
51    /// The identifier name as a string.
52    pub name: String,
53    /// The source code span where this identifier appears.
54    #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
55    pub span: Span,
56}
57
58impl Default for Identifier {
59    fn default() -> Self {
60        Self { name: String::new(), span: Span::default() }
61    }
62}
63
64/// A name path (e.g., `std::collections::HashMap`)
65#[derive(Debug, Clone, PartialEq, Eq, Hash, Default)]
66#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
67pub struct NamePath {
68    /// The individual identifier parts of the path.
69    pub parts: Vec<Identifier>,
70    /// The source code span covering the entire name path.
71    #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
72    pub span: Span,
73}
74
75/// Valkyrie root node.
76#[derive(Debug, Clone, PartialEq, Eq, Hash)]
77#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
78pub struct ValkyrieRoot {
79    /// The collection of top-level items in the Valkyrie module.
80    pub items: Vec<Item>,
81}