fluidattacks-blends-domain 0.6.1

Blends functional core: pure AST graph to syntax graph (no_std)
Documentation
//! Counterpart of `blends/syntax/readers/yaml/stream.py`.

use alloc::vec::Vec;

use crate::query::{adj_ast, match_ast_d, match_ast_group_d};
use crate::syntax::builders::file::build_file_node;
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 child_ids: Vec<NodeId> = Vec::new();
    for document_id in match_ast_group_d(graph, n_id, "document", None) {
        let content_id = match_ast_d(graph, document_id, "block_node", None)
            .or_else(|| match_ast_d(graph, document_id, "flow_node", None));
        if let Some(content_id) = content_id {
            child_ids.extend(
                adj_ast(graph, content_id, None, &[])
                    .into_iter()
                    .filter(|c_id| graph.label_type(*c_id) != Some("---")),
            );
        }
    }
    build_file_node(args, n_id, &child_ids).map(Some)
}