fluidattacks-blends-domain 0.3.0

Blends functional core: pure AST graph to syntax graph (no_std)
Documentation
use crate::query::adj_ast;
use crate::syntax::builders::argument::build_argument_node;
use crate::syntax::builders::named_argument::build_named_argument_node;
use crate::syntax::fields::python::keyword_argument;
use crate::syntax::{SyntaxGraphArgs, SyntaxGraphError};
use crate::utilities::text_nodes::node_to_str;
use crate::NodeId;

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

    if let Ok(identifier_id) = args.required_field_alt(n_id, keyword_argument::NAME) {
        let arg_name = node_to_str(graph, identifier_id);
        let value_id = args
            .required_field_alt(n_id, keyword_argument::VALUE)
            .ok()
            .or_else(|| childs.last().copied())
            .ok_or(SyntaxGraphError::UnexpectedAstShape)?;
        return build_named_argument_node(args, n_id, Some(arg_name), value_id).map(Some);
    }

    build_argument_node(args, n_id, &childs).map(Some)
}