fluidattacks-blends-domain 0.37.0

Blends functional core: pure AST graph to syntax graph (no_std)
Documentation
//! AST node: source position, tree-sitter kind, optional text, named fields,
//! ordered children.

use alloc::collections::BTreeMap;
use alloc::string::String;
use alloc::vec::Vec;

use crate::NodeId;

/// A raw tree-sitter node, before it is read into a [`crate::syntax::SyntaxNode`].
#[derive(Clone, PartialEq, Eq, Debug)]
#[non_exhaustive]
pub struct AstNode {
    /// The node's starting line, 1-based.
    pub line: u32,
    /// The node's starting column, 1-based.
    pub col: u32,
    /// The tree-sitter grammar's node-type name.
    pub kind: String,
    /// The node's source text, for leaf nodes that carry one.
    pub text: Option<String>,
    /// Ids of this node's named grammar fields (e.g. `name`, `body`).
    pub fields: BTreeMap<String, NodeId>,
    /// Ids for the children of this node
    pub children: Vec<NodeId>,
}

impl AstNode {
    /// A node at `line`/`col` of grammar type `kind`, with no text or fields yet.
    #[must_use]
    pub const fn new(line: u32, col: u32, kind: String) -> Self {
        Self {
            line,
            col,
            kind,
            text: None,
            fields: BTreeMap::new(),
            children: Vec::new(),
        }
    }
}