fluidattacks-blends-domain 0.2.0

Blends functional core: pure AST graph to syntax graph (no_std)
Documentation
//! Walk-scoped state: the scope stack and the next synthetic id.

pub mod java;

use alloc::string::String;
use alloc::vec;
use alloc::vec::Vec;

use crate::NodeId;

#[derive(Clone, PartialEq, Eq, Debug)]
pub struct SyntaxMetadata {
    pub class_path: Vec<String>,
    pub scope_stack: Vec<NodeId>,
    pub next_synthetic_id: NodeId,
    pub sanitization_stack: Vec<(String, NodeId)>,
    pub control_flow_stack: Vec<NodeId>,
}

impl SyntaxMetadata {
    #[must_use]
    pub fn seeded(max_ast_id: NodeId) -> Self {
        Self {
            class_path: Vec::new(),
            scope_stack: vec![NodeId(1)],
            next_synthetic_id: NodeId(max_ast_id.0.saturating_add(1)),
            sanitization_stack: Vec::new(),
            control_flow_stack: Vec::new(),
        }
    }
}

#[cfg(test)]
mod tests {
    use super::SyntaxMetadata;
    use crate::NodeId;

    #[test]
    fn seeded_scope_stack_starts_at_root_and_synthetic_ids_after_max_ast_id() {
        let meta = SyntaxMetadata::seeded(NodeId(254));
        assert_eq!(meta.scope_stack, [NodeId(1)]);
        assert_eq!(meta.next_synthetic_id, NodeId(255));
        assert!(meta.class_path.is_empty());
    }
}