fluidattacks-blends-domain 0.6.1

Blends functional core: pure AST graph to syntax graph (no_std)
Documentation
use crate::query::adj_ast;
use crate::syntax::builders::for_each_statement::build_for_each_statement_node;
use crate::syntax::fields::java::enhanced_for_statement;
use crate::syntax::{SyntaxGraphArgs, SyntaxGraphError};
use crate::{CodeGraph, NodeId};

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