fluidattacks-blends-domain 0.17.1

Blends functional core: pure AST graph to syntax graph (no_std)
Documentation
use crate::{
    syntax::{
        builders::class_declaration::build_class_node, fields::Field, SyntaxGraphArgs,
        SyntaxGraphError,
    },
    utilities::text_nodes::node_to_str,
    NodeId,
};
use alloc::format;
use alloc::string::String;

const NAME: Field<false> = Field::new("name_id");
const VALUE: Field<false> = Field::new("value_id");
const BODY: Field<false> = Field::new("body_id");
const SUPER: Field<false> = Field::new("superclass_id");

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

    let mut name_str = String::new();

    if let Some(name_id) = args.optional_field_alt(n_id, NAME) {
        name_str = node_to_str(graph, name_id);
    } else if let Some(val_id) = args.optional_field_alt(n_id, VALUE) {
        name_str = format!("<<{}", node_to_str(graph, val_id));
    }

    let block_id = args.optional_field_alt(n_id, BODY);

    let superclass_name_str = args.optional_field_alt(n_id, SUPER).map(|superclass_id| {
        node_to_str(graph, superclass_id)
            .chars()
            .skip(1)
            .collect::<String>()
    });

    build_class_node(
        args,
        n_id,
        name_str,
        block_id,
        &[],
        superclass_name_str,
        None,
        None,
    )
    .map(Some)
}