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 path_search;
18pub mod query;
19pub mod stack;
20pub mod syntax;
21pub(crate) mod utilities;
22
23pub use language::Language;
24
25/// A node's identity within a graph, stable across the AST and syntax graphs.
26#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
27#[allow(
28    clippy::exhaustive_structs,
29    reason = "a newtype id consumers build by literal; it never grows a field"
30)]
31pub struct NodeId(
32    /// The id's raw value; the shell assigns it during parsing.
33    pub u64,
34);
35
36/// Marks an edge as part of the AST adjacency (as opposed to the CFG one).
37#[derive(Clone, Copy, PartialEq, Eq, Debug)]
38#[allow(
39    clippy::exhaustive_structs,
40    reason = "a unit marker used by value; it has no fields to add"
41)]
42pub struct Ast;
43
44/// Marks an edge as part of the CFG adjacency (as opposed to the AST one).
45#[derive(Clone, Copy, PartialEq, Eq, Debug)]
46#[allow(
47    clippy::exhaustive_structs,
48    reason = "a unit marker used by value; it has no fields to add"
49)]
50pub struct Cfg;
51
52/// A graph with both AST and control-flow adjacency over the same nodes.
53pub trait CodeGraph {
54    /// `n_id`'s children, following both AST and CFG edges.
55    fn children(&self, n_id: NodeId) -> Vec<NodeId>;
56    /// `n_id`'s parents, following both AST and CFG edges.
57    fn parents(&self, n_id: NodeId) -> Vec<NodeId>;
58    /// `n_id`'s children, following AST edges only.
59    fn ast_children(&self, n_id: NodeId) -> Vec<NodeId>;
60    /// `n_id`'s parents, following AST edges only.
61    fn ast_parents(&self, n_id: NodeId) -> Vec<NodeId>;
62    /// `n_id`'s children, following CFG edges only.
63    fn cfg_children(&self, n_id: NodeId) -> Vec<NodeId>;
64    /// `n_id`'s parents, following CFG edges only.
65    fn cfg_parents(&self, n_id: NodeId) -> Vec<NodeId>;
66    /// `n_id`'s syntax-kind label, when the graph has one for it.
67    fn label_type(&self, n_id: NodeId) -> Option<&str>;
68}