fluidattacks-blends-domain 0.6.1

Blends functional core: pure AST graph to syntax graph (no_std)
Documentation
use crate::query::{adj_ast, match_ast_d};
use crate::syntax::builders::using_statement::build_using_statement_node;
use crate::syntax::fields::python::with_statement;
use crate::syntax::{SyntaxGraphArgs, SyntaxGraphError};
use crate::{CodeGraph, NodeId};

pub fn reader(
    args: &mut SyntaxGraphArgs<'_>,
    n_id: NodeId,
) -> Result<Option<NodeId>, SyntaxGraphError> {
    let graph = args.ast_graph;
    let mut block_id = args.required_field_alt(n_id, with_statement::BODY)?;
    if graph.label_type(block_id) == Some("expression_statement") {
        block_id = adj_ast(graph, block_id, None, &[])
            .first()
            .copied()
            .ok_or(SyntaxGraphError::UnexpectedAstShape)?;
    }

    let mut declaration_id = match_ast_d(graph, n_id, "with_clause", None);
    if let Some(with_clause) = declaration_id {
        if let Some(with_item) = match_ast_d(graph, with_clause, "with_item", None) {
            declaration_id = adj_ast(graph, with_item, None, &[]).first().copied();
        }
    }

    build_using_statement_node(args, n_id, block_id, declaration_id).map(Some)
}