fluidattacks-blends-domain 0.6.1

Blends functional core: pure AST graph to syntax graph (no_std)
Documentation
use crate::query::match_ast;
use crate::syntax::builders::for_each_statement::build_for_each_statement_node;
use crate::syntax::fields::c_sharp::foreach_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 var_node = args.required_field_alt(n_id, foreach_statement::LEFT)?;
    let iterable_item = args.required_field_alt(n_id, foreach_statement::RIGHT)?;

    let mut block_id = Some(args.required_field_alt(n_id, foreach_statement::BODY)?);
    if let Some(body) = block_id {
        if graph.label_type(body) == Some("expression_statement") {
            block_id = match_ast(graph, body, &[], None)
                .get("__0__")
                .copied()
                .flatten();
        }
    }
    if let Some(body) = block_id {
        if graph.label_type(body) == Some("parenthesized_expression") {
            block_id = match_ast(graph, body, &[], None)
                .get("__1__")
                .copied()
                .flatten();
        }
    }

    build_for_each_statement_node(args, n_id, var_node, iterable_item, block_id).map(Some)
}