fluidattacks-blends-domain 0.17.1

Blends functional core: pure AST graph to syntax graph (no_std)
Documentation
use crate::syntax::fields::ruby::assignment;
use crate::{
    syntax::{
        builders::{
            assignment::build_assignment_node,
            variable_declaration::build_variable_declaration_node,
        },
        SyntaxGraphArgs, SyntaxGraphError,
    },
    utilities::text_nodes::node_to_str,
    CodeGraph, NodeId,
};

pub fn reader(
    args: &mut SyntaxGraphArgs<'_>,
    n_id: NodeId,
) -> Result<Option<NodeId>, SyntaxGraphError> {
    let graph = args.ast_graph;

    let variable_id = args.required_field_alt(n_id, assignment::LEFT)?;
    let value_id = args.required_field_alt(n_id, assignment::RIGHT)?;

    let ruby_variable_nodes = &[
        "identifier",
        "constant",
        "global_variable",
        "class_variable",
        "instance_variable",
        "exception_variable",
    ];

    if ruby_variable_nodes.contains(&graph.label_type(variable_id).unwrap_or("")) {
        let var_name = node_to_str(graph, variable_id);
        return build_variable_declaration_node(
            args,
            n_id,
            var_name,
            None,
            Some(value_id),
            None,
            None,
        )
        .map(Some);
    }

    build_assignment_node(args, n_id, variable_id, Some(value_id), None).map(Some)
}