fluidattacks-blends-domain 0.34.0

Blends functional core: pure AST graph to syntax graph (no_std)
Documentation
//! Blends functional core: the pure AST graph to syntax graph transformation.
//!
//! Everything here is `no_std` + (later) `alloc` — no filesystem, network,
//! clock, randomness, or tree-sitter. The imperative shell (`crates/shell`)
//! parses source into an AST graph and feeds it in; this crate only decides how
//! that graph becomes a syntax graph.
#![cfg_attr(not(test), no_std)]

extern crate alloc;

use alloc::vec::Vec;

pub mod ast;
pub mod content;
pub mod graph_set;
pub mod language;
pub mod path_search;
pub mod query;
pub mod stack;
pub mod syntax;
pub(crate) mod utilities;

pub use language::Language;

/// A node's identity within a graph, stable across the AST and syntax graphs.
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
#[allow(
    clippy::exhaustive_structs,
    reason = "a newtype id consumers build by literal; it never grows a field"
)]
pub struct NodeId(
    /// The id's raw value; the shell assigns it during parsing.
    pub u64,
);

/// Marks an edge as part of the AST adjacency (as opposed to the CFG one).
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
#[allow(
    clippy::exhaustive_structs,
    reason = "a unit marker used by value; it has no fields to add"
)]
pub struct Ast;

/// Marks an edge as part of the CFG adjacency (as opposed to the AST one).
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
#[allow(
    clippy::exhaustive_structs,
    reason = "a unit marker used by value; it has no fields to add"
)]
pub struct Cfg;

/// A graph with both AST and control-flow adjacency over the same nodes.
pub trait CodeGraph {
    /// `n_id`'s children, following both AST and CFG edges.
    fn children(&self, n_id: NodeId) -> Vec<NodeId>;
    /// `n_id`'s parents, following both AST and CFG edges.
    fn parents(&self, n_id: NodeId) -> Vec<NodeId>;
    /// `n_id`'s children, following AST edges only.
    fn ast_children(&self, n_id: NodeId) -> Vec<NodeId>;
    /// `n_id`'s parents, following AST edges only.
    fn ast_parents(&self, n_id: NodeId) -> Vec<NodeId>;
    /// `n_id`'s children, following CFG edges only.
    fn cfg_children(&self, n_id: NodeId) -> Vec<NodeId>;
    /// `n_id`'s parents, following CFG edges only.
    fn cfg_parents(&self, n_id: NodeId) -> Vec<NodeId>;
    /// `n_id`'s syntax-kind label, when the graph has one for it.
    fn label_type(&self, n_id: NodeId) -> Option<&str>;
}