Skip to main content

fluidattacks_blends_domain/
lib.rs

1//! Blends functional core: the pure AST graph to syntax graph transformation.
2//!
3//! Everything here is `no_std` + (later) `alloc` — no filesystem, network,
4//! clock, randomness, or tree-sitter. The imperative shell (`crates/shell`)
5//! parses source into an AST graph and feeds it in; this crate only decides how
6//! that graph becomes a syntax graph.
7#![cfg_attr(not(test), no_std)]
8
9extern crate alloc;
10
11use alloc::vec::Vec;
12
13pub mod ast;
14pub mod content;
15pub mod graph_set;
16pub mod language;
17pub mod query;
18pub mod stack;
19pub mod syntax;
20pub(crate) mod utilities;
21
22pub use language::Language;
23
24/// A node's identity within a graph, stable across the AST and syntax graphs.
25#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
26#[allow(
27    clippy::exhaustive_structs,
28    reason = "a newtype id consumers build by literal; it never grows a field"
29)]
30pub struct NodeId(
31    /// The id's raw value; the shell assigns it during parsing.
32    pub u64,
33);
34
35/// Marks an edge as part of the AST adjacency (as opposed to the CFG one).
36#[derive(Clone, Copy, PartialEq, Eq, Debug)]
37#[allow(
38    clippy::exhaustive_structs,
39    reason = "a unit marker used by value; it has no fields to add"
40)]
41pub struct Ast;
42
43/// Marks an edge as part of the CFG adjacency (as opposed to the AST one).
44#[derive(Clone, Copy, PartialEq, Eq, Debug)]
45#[allow(
46    clippy::exhaustive_structs,
47    reason = "a unit marker used by value; it has no fields to add"
48)]
49pub struct Cfg;
50
51/// A graph with both AST and control-flow adjacency over the same nodes.
52pub trait CodeGraph {
53    /// `n_id`'s children, following both AST and CFG edges.
54    fn children(&self, n_id: NodeId) -> Vec<NodeId>;
55    /// `n_id`'s parents, following both AST and CFG edges.
56    fn parents(&self, n_id: NodeId) -> Vec<NodeId>;
57    /// `n_id`'s children, following AST edges only.
58    fn ast_children(&self, n_id: NodeId) -> Vec<NodeId>;
59    /// `n_id`'s parents, following AST edges only.
60    fn ast_parents(&self, n_id: NodeId) -> Vec<NodeId>;
61    /// `n_id`'s children, following CFG edges only.
62    fn cfg_children(&self, n_id: NodeId) -> Vec<NodeId>;
63    /// `n_id`'s parents, following CFG edges only.
64    fn cfg_parents(&self, n_id: NodeId) -> Vec<NodeId>;
65    /// `n_id`'s syntax-kind label, when the graph has one for it.
66    fn label_type(&self, n_id: NodeId) -> Option<&str>;
67}