fluidattacks-blends-domain 0.3.0

Blends functional core: pure AST graph to syntax graph (no_std)
Documentation
use alloc::format;
use alloc::string::String;

use crate::query::match_ast_d;
use crate::syntax::builders::reserved_word::build_reserved_word_node;
use crate::syntax::SyntaxNode;
use crate::syntax::{SyntaxGraphArgs, SyntaxGraphError};
use crate::utilities::text_nodes::node_to_str;
use crate::NodeId;

#[expect(
    clippy::unnecessary_wraps,
    reason = "the signature must match the reader dispatch table"
)]
pub fn reader(
    args: &mut SyntaxGraphArgs<'_>,
    n_id: NodeId,
) -> Result<Option<NodeId>, SyntaxGraphError> {
    let name_id = match_ast_d(args.ast_graph, n_id, "scoped_identifier", None)
        .or_else(|| match_ast_d(args.ast_graph, n_id, "identifier", None));
    let expression = name_id.map_or_else(
        || String::from("PackageName Unnamed"),
        |c_id| format!("PackageName {}", node_to_str(args.ast_graph, c_id)),
    );
    if let Some(c_id) = name_id {
        let package_name = node_to_str(args.ast_graph, c_id);
        if let Some(SyntaxNode::Metadata { package, .. }) =
            args.syntax_graph.nodes.get_mut(&NodeId(0))
        {
            *package = Some(package_name);
        }
    }
    Ok(Some(build_reserved_word_node(args, n_id, expression)))
}