Skip to main content

cp_ast_core/structure/
structure_node.rs

1use super::node_id::NodeId;
2use super::node_kind::NodeKind;
3
4/// A node in the structure AST.
5///
6/// Rev.1: Simplified to just id + kind. Name and structural data
7/// are embedded in `NodeKind` variants. Parent-child relationships
8/// are managed by the `StructureAst` arena.
9#[derive(Debug, Clone, PartialEq)]
10pub struct StructureNode {
11    id: NodeId,
12    kind: NodeKind,
13}
14
15impl StructureNode {
16    /// Create a new structure node.
17    #[must_use]
18    pub fn new(id: NodeId, kind: NodeKind) -> Self {
19        Self { id, kind }
20    }
21
22    /// Returns the unique ID of this node.
23    #[must_use]
24    pub fn id(&self) -> NodeId {
25        self.id
26    }
27
28    /// Returns a reference to the kind of this node.
29    #[must_use]
30    pub fn kind(&self) -> &NodeKind {
31        &self.kind
32    }
33
34    /// Replace the kind of this node (used by `FillHole`).
35    pub fn set_kind(&mut self, kind: NodeKind) {
36        self.kind = kind;
37    }
38}