formualizer_eval/engine/
named_range.rs

1use formualizer_parse::{ASTNode, parser::ReferenceType};
2use rustc_hash::FxHashSet;
3
4use crate::{CellRef, RangeRef, SheetId, engine::VertexId};
5
6/// Scope of a named range
7#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
8pub enum NameScope {
9    /// Available throughout workbook
10    Workbook,
11    /// Only available in specific sheet
12    Sheet(SheetId),
13}
14
15/// Definition of what a name refers to
16#[derive(Debug, Clone, PartialEq)]
17pub enum NamedDefinition {
18    /// Direct reference to a single cell
19    Cell(CellRef),
20    /// Reference to a range of cells
21    Range(RangeRef),
22    /// Named formula (evaluates to value/range)
23    Formula {
24        ast: ASTNode,
25        /// Cached dependencies from last parse
26        dependencies: Vec<VertexId>,
27        /// Cached range dependencies
28        range_deps: Vec<ReferenceType>,
29    },
30}
31
32/// Complete named range entry
33#[derive(Debug, Clone)]
34pub struct NamedRange {
35    pub definition: NamedDefinition,
36    pub scope: NameScope,
37    /// Formulas that reference this name (for invalidation)
38    pub dependents: FxHashSet<VertexId>,
39}