fluidattacks-blends-domain 0.35.0

Blends functional core: pure AST graph to syntax graph (no_std)
Documentation
use crate::{
    query::{adj_ast, match_ast},
    syntax::{SyntaxGraphArgs, SyntaxGraphError},
    NodeId,
};

pub fn reader(
    args: &mut SyntaxGraphArgs<'_>,
    n_id: NodeId,
) -> Result<Option<NodeId>, SyntaxGraphError> {
    let graph = args.ast_graph;
    let matches = match_ast(
        graph,
        n_id,
        &["integer_literal", "simple_identifier"],
        Some(1),
    );

    let expr_id = matches
        .get("integer_literal")
        .copied()
        .flatten()
        .or_else(|| matches.get("simple_identifier").copied().flatten())
        .or_else(|| adj_ast(graph, n_id, Some(1), &[]).first().copied())
        .ok_or(SyntaxGraphError::UnexpectedAstShape)?;

    args.generic(expr_id).map(Some)
}