formualizer-eval 0.10.0

High-performance Arrow-backed Excel formula engine with dependency graph and incremental recalculation
Documentation
use formualizer_parse::ASTNode;
#[cfg(any(test, feature = "legacy_oracle"))]
use rustc_hash::FxHashSet;

use formualizer_common::LiteralValue;

use crate::{CellRef, RangeRef, SheetId, engine::VertexId, reference::SharedRangeRef};

/// Scope of a named range
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum NameScope {
    /// Available throughout workbook
    Workbook,
    /// Only available in specific sheet
    Sheet(SheetId),
}

/// Definition of what a name refers to
#[derive(Debug, Clone, PartialEq)]
#[allow(clippy::large_enum_variant)]
pub enum NamedDefinition {
    /// Direct reference to a single cell
    Cell(CellRef),
    /// Reference to a range of cells
    Range(RangeRef),
    /// Constant literal value
    Literal(LiteralValue),
    /// Named formula (evaluates to value/range)
    Formula {
        ast: ASTNode,
        /// Cached dependencies from last parse
        dependencies: Vec<VertexId>,
        /// Cached range dependencies
        range_deps: Vec<SharedRangeRef<'static>>,
    },
}

/// Complete named range entry
#[derive(Debug, Clone)]
pub struct NamedRange {
    pub definition: NamedDefinition,
    pub scope: NameScope,
    /// Formulas that reference this name: legacy's name link map, kept
    /// only by the test oracle (Program 1 M5). Normal builds have no public
    /// equivalent: inspection (`Engine::dependents`) excludes name-mediated
    /// readers, as legacy's inspection did.
    #[cfg(any(test, feature = "legacy_oracle"))]
    pub dependents: FxHashSet<VertexId>,
    /// Vertex representing this named range within the dependency graph
    pub vertex: VertexId,
}

/// Cloned, binding-friendly snapshot of a named range entry.
#[derive(Debug, Clone, PartialEq)]
pub struct NamedRangeSnapshot {
    pub name: String,
    pub scope: NameScope,
    pub definition: NamedDefinition,
}