fluidattacks-blends-domain 0.40.0

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

pub fn reader(
    args: &mut SyntaxGraphArgs<'_>,
    n_id: NodeId,
) -> Result<Option<NodeId>, SyntaxGraphError> {
    let value_id = *adj_ast(args.ast_graph, n_id, Some(1), &[])
        .first()
        .ok_or(SyntaxGraphError::UnexpectedAstShape)?;

    // An element that omits its type, as the inner brace of `[][]int{{1, 2}}`
    // does, takes the one the list holding it handed down.
    let omitted_type = args.metadata.element_type_stack.last().copied().flatten();
    if args.ast_graph.label_type(value_id) == Some("literal_value") {
        if let Some(type_id) = omitted_type {
            return build_composite(args, n_id, type_id, value_id).map(Some);
        }
    }

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