f8-engine 0.3.2__tar.gz → 0.4.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. {f8_engine-0.3.2 → f8_engine-0.4.0}/Cargo.lock +2 -2
  2. {f8_engine-0.3.2 → f8_engine-0.4.0}/Cargo.toml +1 -1
  3. {f8_engine-0.3.2 → f8_engine-0.4.0}/PKG-INFO +1 -1
  4. {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/compiler/emission/format.rs +17 -5
  5. {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/compiler/emission/workbook.rs +2 -1
  6. {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/compiler/graph/resolve.rs +8 -6
  7. {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/compiler/layout/mod.rs +103 -54
  8. {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/compiler/lowering/mod.rs +16 -9
  9. {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/expr/ast.rs +50 -3
  10. {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/expr/error.rs +2 -2
  11. {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/expr/mod.rs +1 -1
  12. {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/expr/parser.rs +47 -4
  13. {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/model/error.rs +8 -0
  14. {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/model/format.rs +0 -2
  15. {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/model/theme.rs +20 -8
  16. {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-python/src/error.rs +1 -0
  17. {f8_engine-0.3.2 → f8_engine-0.4.0}/python/f8/audit.py +11 -5
  18. {f8_engine-0.3.2 → f8_engine-0.4.0}/python/f8/skills/f8-modeling/SKILL.md +1 -1
  19. {f8_engine-0.3.2 → f8_engine-0.4.0}/python/f8/skills/f8-modeling/references/auditing-and-repair.md +1 -1
  20. {f8_engine-0.3.2 → f8_engine-0.4.0}/python/f8/skills/f8-modeling/references/syntax-and-grid.md +5 -5
  21. {f8_engine-0.3.2 → f8_engine-0.4.0}/python/f8/types.py +1 -1
  22. {f8_engine-0.3.2 → f8_engine-0.4.0}/LICENSE +0 -0
  23. {f8_engine-0.3.2 → f8_engine-0.4.0}/README.md +0 -0
  24. {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/Cargo.toml +0 -0
  25. {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/compiler/compiled/error.rs +0 -0
  26. {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/compiler/compiled/mod.rs +0 -0
  27. {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/compiler/compiled/model.rs +0 -0
  28. {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/compiler/emission/error.rs +0 -0
  29. {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/compiler/emission/mod.rs +0 -0
  30. {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/compiler/error.rs +0 -0
  31. {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/compiler/eval/context.rs +0 -0
  32. {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/compiler/eval/error.rs +0 -0
  33. {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/compiler/eval/expr.rs +0 -0
  34. {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/compiler/eval/mod.rs +0 -0
  35. {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/compiler/eval/model.rs +0 -0
  36. {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/compiler/graph/cycle.rs +0 -0
  37. {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/compiler/graph/dependency.rs +0 -0
  38. {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/compiler/graph/error.rs +0 -0
  39. {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/compiler/graph/mod.rs +0 -0
  40. {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/compiler/ir/cell.rs +0 -0
  41. {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/compiler/ir/error.rs +0 -0
  42. {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/compiler/ir/expand.rs +0 -0
  43. {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/compiler/ir/id.rs +0 -0
  44. {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/compiler/ir/mod.rs +0 -0
  45. {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/compiler/ir/symbol.rs +0 -0
  46. {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/compiler/layout/a1.rs +0 -0
  47. {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/compiler/layout/error.rs +0 -0
  48. {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/compiler/lowering/address.rs +0 -0
  49. {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/compiler/lowering/error.rs +0 -0
  50. {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/compiler/mod.rs +0 -0
  51. {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/functions/common.rs +0 -0
  52. {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/functions/date/constructors.rs +0 -0
  53. {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/functions/date/mod.rs +0 -0
  54. {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/functions/date/parts.rs +0 -0
  55. {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/functions/date/serial.rs +0 -0
  56. {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/functions/date/yearfrac.rs +0 -0
  57. {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/functions/error.rs +0 -0
  58. {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/functions/financial/annuity.rs +0 -0
  59. {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/functions/financial/discounting.rs +0 -0
  60. {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/functions/financial/irr.rs +0 -0
  61. {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/functions/financial/mod.rs +0 -0
  62. {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/functions/logical/boolean.rs +0 -0
  63. {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/functions/logical/branching.rs +0 -0
  64. {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/functions/logical/error_handling.rs +0 -0
  65. {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/functions/logical/mod.rs +0 -0
  66. {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/functions/lookup/index.rs +0 -0
  67. {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/functions/lookup/mod.rs +0 -0
  68. {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/functions/lookup/search.rs +0 -0
  69. {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/functions/lookup/xlookup.rs +0 -0
  70. {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/functions/lookup/xmatch.rs +0 -0
  71. {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/functions/math/aggregation.rs +0 -0
  72. {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/functions/math/basic.rs +0 -0
  73. {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/functions/math/conditional.rs +0 -0
  74. {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/functions/math/criteria.rs +0 -0
  75. {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/functions/math/mod.rs +0 -0
  76. {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/functions/math/product.rs +0 -0
  77. {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/functions/math/rounding.rs +0 -0
  78. {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/functions/mod.rs +0 -0
  79. {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/functions/registry.rs +0 -0
  80. {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/functions/traits.rs +0 -0
  81. {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/lib.rs +0 -0
  82. {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/model/id.rs +0 -0
  83. {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/model/manifest.rs +0 -0
  84. {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/model/mod.rs +0 -0
  85. {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/model/table.rs +0 -0
  86. {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/value/error.rs +0 -0
  87. {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/value/format.rs +0 -0
  88. {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/value/mod.rs +0 -0
  89. {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-python/Cargo.toml +0 -0
  90. {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-python/src/lib.rs +0 -0
  91. {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-python/src/model.rs +0 -0
  92. {f8_engine-0.3.2 → f8_engine-0.4.0}/pyproject.toml +0 -0
  93. {f8_engine-0.3.2 → f8_engine-0.4.0}/python/f8/__init__.py +0 -0
  94. {f8_engine-0.3.2 → f8_engine-0.4.0}/python/f8/__main__.py +0 -0
  95. {f8_engine-0.3.2 → f8_engine-0.4.0}/python/f8/_core.pyi +0 -0
  96. {f8_engine-0.3.2 → f8_engine-0.4.0}/python/f8/builder.py +0 -0
  97. {f8_engine-0.3.2 → f8_engine-0.4.0}/python/f8/cli.py +0 -0
  98. {f8_engine-0.3.2 → f8_engine-0.4.0}/python/f8/py.typed +0 -0
  99. {f8_engine-0.3.2 → f8_engine-0.4.0}/python/f8/skills/f8-modeling/references/functions.md +0 -0
@@ -37,7 +37,7 @@ checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f"
37
37
 
38
38
  [[package]]
39
39
  name = "f8-core"
40
- version = "0.3.2"
40
+ version = "0.4.0"
41
41
  dependencies = [
42
42
  "indexmap",
43
43
  "petgraph",
@@ -50,7 +50,7 @@ dependencies = [
50
50
 
51
51
  [[package]]
52
52
  name = "f8-python"
53
- version = "0.3.2"
53
+ version = "0.4.0"
54
54
  dependencies = [
55
55
  "f8-core",
56
56
  "pyo3",
@@ -3,7 +3,7 @@ resolver = "3"
3
3
  members = ["crates/f8-core", "crates/f8-python"]
4
4
 
5
5
  [workspace.package]
6
- version = "0.3.2"
6
+ version = "0.4.0"
7
7
  edition = "2024"
8
8
  description = "Financial modeling engine with compiler verification and live Excel formulas"
9
9
  authors = ["Michael (Chencheng) Hu, CFA"]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: f8-engine
3
- Version: 0.3.2
3
+ Version: 0.4.0
4
4
  Classifier: Development Status :: 4 - Beta
5
5
  Classifier: Intended Audience :: Developers
6
6
  Classifier: Intended Audience :: Financial and Insurance Industry
@@ -95,7 +95,6 @@ struct ParsedPalette {
95
95
  input_text: Color,
96
96
  formula_text: Color,
97
97
  shade_muted_fill: Option<Color>,
98
- shade_accent_fill: Option<Color>,
99
98
  shade_alt_fill: Option<Color>,
100
99
  highlight_fill: Option<Color>,
101
100
  highlight_text: Color,
@@ -125,7 +124,6 @@ impl ParsedPalette {
125
124
  input_text: parse_hex_color("input_text", &p.input_text)?,
126
125
  formula_text: parse_hex_color("formula_text", &p.formula_text)?,
127
126
  shade_muted_fill: parse_fill_color("shade_muted_fill", &p.shade_muted_fill)?,
128
- shade_accent_fill: parse_fill_color("shade_accent_fill", &p.shade_accent_fill)?,
129
127
  shade_alt_fill: parse_fill_color("shade_alt_fill", &p.shade_alt_fill)?,
130
128
  highlight_fill: parse_fill_color("highlight_fill", &p.highlight_fill)?,
131
129
  highlight_text: parse_hex_color("highlight_text", &p.highlight_text)?,
@@ -153,6 +151,8 @@ pub struct CellFormatKey {
153
151
  pub is_descriptor: bool,
154
152
  /// Descriptor indentation level.
155
153
  pub indent: u8,
154
+ /// Whether the cell requires multi-line text wrapping.
155
+ pub wrap_text: bool,
156
156
  }
157
157
 
158
158
  impl CellFormatKey {
@@ -175,8 +175,16 @@ impl CellFormatKey {
175
175
  is_input,
176
176
  is_descriptor,
177
177
  indent,
178
+ wrap_text: false,
178
179
  }
179
180
  }
181
+
182
+ /// Builder method enabling or disabling text wrapping on the cell format.
183
+ #[must_use]
184
+ pub const fn with_wrap_text(mut self, wrap_text: bool) -> Self {
185
+ self.wrap_text = wrap_text;
186
+ self
187
+ }
180
188
  }
181
189
 
182
190
  /// Format synthesizer and deduplication cache mapping semantic cell keys and structural headers
@@ -328,7 +336,7 @@ impl FormatCache {
328
336
  format = format.set_bold();
329
337
  }
330
338
 
331
- // 2. Alignment & Indentation (Descriptor Left with optional indent, Measure Right)
339
+ // 2. Alignment, Indentation, and Wrapping (Descriptor Left with optional indent, Measure Right, VerticalCenter)
332
340
  format = if key.is_descriptor {
333
341
  let mut fmt = format.set_align(FormatAlign::Left);
334
342
  if key.indent > 0 {
@@ -337,13 +345,17 @@ impl FormatCache {
337
345
  fmt
338
346
  } else {
339
347
  format.set_align(FormatAlign::Right)
340
- };
348
+ }
349
+ .set_align(FormatAlign::VerticalCenter);
350
+
351
+ if key.wrap_text {
352
+ format = format.set_text_wrap();
353
+ }
341
354
 
342
355
  // 3. Background Fill Precedence:
343
356
  // is_highlight > total (or shade) > subtotal (or shade) > shade > data
344
357
  let shade_fill = match key.role.shade {
345
358
  Some(Shade::Muted) => self.palette.shade_muted_fill,
346
- Some(Shade::Accent) => self.palette.shade_accent_fill,
347
359
  Some(Shade::Alt) => self.palette.shade_alt_fill,
348
360
  Some(Shade::None) | None => None,
349
361
  };
@@ -413,7 +413,8 @@ impl WorkbookEmitter {
413
413
  is_input,
414
414
  is_descriptor,
415
415
  coord.indent,
416
- );
416
+ )
417
+ .with_wrap_text(coord.wrap_text);
417
418
  let cell_format = format_cache.get_cell_format(&format_key)?;
418
419
 
419
420
  if options.values_only {
@@ -369,9 +369,10 @@ pub fn resolve_table_ref(
369
369
  .get_table(&origin.table)
370
370
  .ok_or_else(|| ResolveError::unregistered_table(origin, origin.table.clone()))?;
371
371
 
372
+ let resolved_table_id = table_ref.table.resolve(&origin.table);
372
373
  let target_table = symbol_table
373
- .get_table(&table_ref.table)
374
- .ok_or_else(|| ResolveError::unknown_table(origin, table_ref.table.clone()))?;
374
+ .get_table(resolved_table_id)
375
+ .ok_or_else(|| ResolveError::unknown_table(origin, resolved_table_id.clone()))?;
375
376
 
376
377
  let rows = resolve_row_selector(origin, target_table, origin_table, &table_ref.row)?;
377
378
  let cols = resolve_col_selector(origin, target_table, origin_table, &table_ref.col)?;
@@ -382,7 +383,7 @@ pub fn resolve_table_ref(
382
383
  for row in rows {
383
384
  for col in &cols {
384
385
  resolved.push(CellId::new(
385
- table_ref.table.clone(),
386
+ resolved_table_id.clone(),
386
387
  row.clone(),
387
388
  col.clone(),
388
389
  ));
@@ -419,6 +420,7 @@ pub fn resolve_cell_dependencies(
419
420
  #[allow(clippy::unwrap_used, clippy::expect_used, reason = "test code")]
420
421
  mod tests {
421
422
  use super::*;
423
+ use crate::expr::ast::TableSelector;
422
424
  use crate::model::id::{SheetId, TableId};
423
425
  use crate::model::table::{ColumnSpec, RowSpec, TableSpec};
424
426
 
@@ -428,9 +430,9 @@ mod tests {
428
430
  let expr = Expr::parse(formula).expect("valid formula");
429
431
  let refs = collect_references(&expr);
430
432
  assert_eq!(refs.len(), 3);
431
- assert_eq!(refs[0].table, TableId::from("TableA"));
432
- assert_eq!(refs[1].table, TableId::from("TableB"));
433
- assert_eq!(refs[2].table, TableId::from("TableC"));
433
+ assert_eq!(refs[0].table, TableSelector::from("TableA"));
434
+ assert_eq!(refs[1].table, TableSelector::from("TableB"));
435
+ assert_eq!(refs[2].table, TableSelector::from("TableC"));
434
436
  }
435
437
 
436
438
  #[test]
@@ -20,7 +20,7 @@ use crate::model::format::{CurrencyCode, FormatPreset, SemanticStyle, Shade};
20
20
  use crate::model::id::{SheetId, TableId};
21
21
  use crate::model::manifest::{FreezePanes, ProjectManifest};
22
22
  use crate::model::table::{ColumnSpec, PlacementSpec, RowSpec, TableSpec, ValueLiteral};
23
- use crate::model::theme::Theme;
23
+ use crate::model::theme::{MetricsConfig, Theme};
24
24
  use crate::value::{CellValue, format_accounting_number};
25
25
 
26
26
  /// Semantic styling role assigned to a physical coordinate.
@@ -72,6 +72,9 @@ pub struct PhysicalCoordinate {
72
72
  pub style_role: StyleRole,
73
73
  /// Descriptor text indentation level.
74
74
  pub indent: u8,
75
+ /// Whether this cell requires multi-line text wrapping.
76
+ #[serde(default, skip_serializing_if = "std::ops::Not::not")]
77
+ pub wrap_text: bool,
75
78
  }
76
79
 
77
80
  /// Physical bounding box and structural row offsets for a table on a worksheet.
@@ -464,6 +467,7 @@ impl LayoutPlanner {
464
467
  a1,
465
468
  style_role,
466
469
  indent,
470
+ wrap_text: false,
467
471
  },
468
472
  );
469
473
  }
@@ -524,11 +528,11 @@ impl LayoutPlanner {
524
528
  tables: &sheet_tables,
525
529
  placements: &sheet_placements,
526
530
  grid,
527
- layout_cells: &layout_cells,
531
+ layout_cells: &mut layout_cells,
528
532
  theme,
529
533
  evaluated,
530
534
  }
531
- .arbitrate(sheet_max_end_col, &mut col_widths);
535
+ .arbitrate(sheet_max_end_col, &mut col_widths, &mut row_heights);
532
536
 
533
537
  layout_sheets.insert(
534
538
  sheet_id.clone(),
@@ -597,19 +601,24 @@ fn resolve_placement_target<'a>(
597
601
  })
598
602
  }
599
603
 
600
- /// Context and read-only inputs for arbitrating sheet-wide column widths across placed tables.
604
+ /// Context and inputs for arbitrating sheet-wide column widths and cell text wrapping across placed tables.
601
605
  struct ColumnArbitrationContext<'a> {
602
606
  tables: &'a [&'a TableSpec],
603
607
  placements: &'a IndexMap<TableId, TablePlacement>,
604
608
  grid: &'a CellGrid,
605
- layout_cells: &'a IndexMap<CellId, PhysicalCoordinate>,
609
+ layout_cells: &'a mut IndexMap<CellId, PhysicalCoordinate>,
606
610
  theme: &'a Theme,
607
611
  evaluated: Option<&'a EvaluatedModel>,
608
612
  }
609
613
 
610
614
  impl ColumnArbitrationContext<'_> {
611
- /// Arbitrates sheet-wide column widths across all tables sharing worksheet columns.
612
- fn arbitrate(&self, sheet_max_end_col: u32, col_widths: &mut IndexMap<u32, f64>) {
615
+ /// Arbitrates sheet-wide column widths, cell text wrapping, and multi-line row heights across all tables sharing worksheet columns.
616
+ fn arbitrate(
617
+ &mut self,
618
+ sheet_max_end_col: u32,
619
+ col_widths: &mut IndexMap<u32, f64>,
620
+ row_heights: &mut IndexMap<u32, f64>,
621
+ ) {
613
622
  for physical_col in 1..=sheet_max_end_col {
614
623
  let has_data_col = self.tables.iter().any(|t| {
615
624
  let Some(placement) = self.placements.get(&t.id) else {
@@ -647,7 +656,7 @@ impl ColumnArbitrationContext<'_> {
647
656
  let header_len = data_col.max_header_chars();
648
657
  table_max_chars = table_max_chars.max(header_len);
649
658
 
650
- // 2. Row cells text length
659
+ // 2. Row cells text length and multi-line wrapping
651
660
  for row in &table.rows {
652
661
  let RowSpec::Data(data_row) = row else {
653
662
  continue;
@@ -660,25 +669,41 @@ impl ColumnArbitrationContext<'_> {
660
669
  format.and_then(|f| self.theme.number_formats.default_decimals(f))
661
670
  });
662
671
  let currency = cell_node.and_then(|n| n.currency);
672
+ let indent = self.layout_cells.get(&cell_id).map_or(0, |c| c.indent);
663
673
 
664
- let mut char_len =
674
+ let (char_len, lines) =
665
675
  match (self.evaluated.and_then(|e| e.get_cell(&cell_id)), cell_node) {
666
- (Some(val), _) => {
667
- cell_value_string_length(val, format, decimals, currency)
668
- }
676
+ (Some(val), _) => measure_cell_value(
677
+ val,
678
+ format,
679
+ decimals,
680
+ currency,
681
+ indent,
682
+ &self.theme.metrics,
683
+ ),
669
684
  (None, Some(node)) => match &node.payload {
670
- CellPayload::Literal(lit) => {
671
- literal_value_length(lit, format, decimals, currency)
672
- }
673
- CellPayload::Formula(_) => 0,
685
+ CellPayload::Literal(lit) => measure_literal_value(
686
+ lit,
687
+ format,
688
+ decimals,
689
+ currency,
690
+ indent,
691
+ &self.theme.metrics,
692
+ ),
693
+ CellPayload::Formula(_) => (usize::from(indent) * 2, 1),
674
694
  },
675
- (None, None) => 0,
695
+ (None, None) => (usize::from(indent) * 2, 1),
676
696
  };
677
697
 
678
- if let Some(coord) = self.layout_cells.get(&cell_id)
679
- && coord.indent > 0
698
+ if lines > 1
699
+ && let Some(coord) = self.layout_cells.get_mut(&cell_id)
680
700
  {
681
- char_len += (coord.indent as usize) * 2;
701
+ coord.wrap_text = true;
702
+ record_row_height(
703
+ row_heights,
704
+ coord.row,
705
+ (lines as f64) * self.theme.metrics.data_row_height,
706
+ );
682
707
  }
683
708
 
684
709
  table_max_chars = table_max_chars.max(char_len);
@@ -687,11 +712,14 @@ impl ColumnArbitrationContext<'_> {
687
712
  max_chars_across_tables = max_chars_across_tables.max(table_max_chars);
688
713
  }
689
714
 
690
- // Apply theme font multiplier and padding, enforcing min_col_width
715
+ // Apply theme font multiplier and padding, clamping to [min_col_width, max_col_width]
691
716
  let computed_width = (max_chars_across_tables as f64
692
717
  * self.theme.metrics.char_width_multiplier
693
718
  + self.theme.metrics.col_padding)
694
- .max(self.theme.metrics.min_col_width);
719
+ .clamp(
720
+ self.theme.metrics.min_col_width,
721
+ self.theme.metrics.max_col_width,
722
+ );
695
723
 
696
724
  let final_width = (computed_width * 100.0).round() / 100.0;
697
725
  let existing = col_widths.get(&physical_col).copied().unwrap_or(0.0);
@@ -700,51 +728,72 @@ impl ColumnArbitrationContext<'_> {
700
728
  }
701
729
  }
702
730
 
703
- fn literal_value_length(
731
+ fn measure_text_segments(
732
+ s: &str,
733
+ format: Option<FormatPreset>,
734
+ indent: u8,
735
+ metrics: &MetricsConfig,
736
+ ) -> (usize, usize) {
737
+ let trailing_pad = usize::from(format == Some(FormatPreset::Text));
738
+ let indent_chars = usize::from(indent) * 2;
739
+ let mut max_chars = 0;
740
+ let mut total_lines = 0;
741
+
742
+ for segment in s.split('\n') {
743
+ let seg_chars = segment.chars().count() + trailing_pad + indent_chars;
744
+ max_chars = max_chars.max(seg_chars);
745
+ let seg_lines = if seg_chars == 0 {
746
+ 1
747
+ } else {
748
+ let seg_width =
749
+ (seg_chars as f64) * metrics.char_width_multiplier + metrics.col_padding;
750
+ ((seg_width / metrics.max_col_width).ceil() as usize).max(1)
751
+ };
752
+ total_lines += seg_lines;
753
+ }
754
+
755
+ (max_chars, total_lines)
756
+ }
757
+
758
+ fn measure_literal_value(
704
759
  lit: &ValueLiteral,
705
760
  format: Option<FormatPreset>,
706
761
  decimals: Option<u32>,
707
762
  currency: Option<CurrencyCode>,
708
- ) -> usize {
763
+ indent: u8,
764
+ metrics: &MetricsConfig,
765
+ ) -> (usize, usize) {
766
+ let indent_chars = usize::from(indent) * 2;
709
767
  match lit {
710
- ValueLiteral::String(s) => {
711
- let trailing_pad = usize::from(format == Some(FormatPreset::Text));
712
- s.chars().count() + trailing_pad
713
- }
714
- ValueLiteral::Number(n) => formatted_number_estimate(*n, format, decimals, currency),
715
- ValueLiteral::Boolean(b) => {
716
- if *b {
717
- 4
718
- } else {
719
- 5
720
- }
721
- }
722
- ValueLiteral::Null => 0,
768
+ ValueLiteral::String(s) => measure_text_segments(s, format, indent, metrics),
769
+ ValueLiteral::Number(n) => (
770
+ formatted_number_estimate(*n, format, decimals, currency) + indent_chars,
771
+ 1,
772
+ ),
773
+ ValueLiteral::Boolean(b) => ((if *b { 4 } else { 5 }) + indent_chars, 1),
774
+ ValueLiteral::Null => (indent_chars, 1),
723
775
  }
724
776
  }
725
777
 
726
- /// Computes the approximate character length of an evaluated `CellValue`.
727
- fn cell_value_string_length(
778
+ /// Computes the horizontal character demand and wrapped line count of an evaluated `CellValue`.
779
+ fn measure_cell_value(
728
780
  val: &CellValue,
729
781
  format: Option<FormatPreset>,
730
782
  decimals: Option<u32>,
731
783
  currency: Option<CurrencyCode>,
732
- ) -> usize {
784
+ indent: u8,
785
+ metrics: &MetricsConfig,
786
+ ) -> (usize, usize) {
787
+ let indent_chars = usize::from(indent) * 2;
733
788
  match val {
734
- CellValue::Text(s) => {
735
- let trailing_pad = usize::from(format == Some(FormatPreset::Text));
736
- s.chars().count() + trailing_pad
737
- }
738
- CellValue::Number(n) => formatted_number_estimate(*n, format, decimals, currency),
739
- CellValue::Boolean(b) => {
740
- if *b {
741
- 4
742
- } else {
743
- 5
744
- }
745
- }
746
- CellValue::Error(e) => e.to_string().chars().count(),
747
- CellValue::Empty => 0,
789
+ CellValue::Text(s) => measure_text_segments(s, format, indent, metrics),
790
+ CellValue::Number(n) => (
791
+ formatted_number_estimate(*n, format, decimals, currency) + indent_chars,
792
+ 1,
793
+ ),
794
+ CellValue::Boolean(b) => ((if *b { 4 } else { 5 }) + indent_chars, 1),
795
+ CellValue::Error(e) => (e.to_string().chars().count() + indent_chars, 1),
796
+ CellValue::Empty => (indent_chars, 1),
748
797
  }
749
798
  }
750
799
 
@@ -120,8 +120,12 @@ pub fn lower_table_ref(
120
120
  crate::compiler::graph::error::ResolveError::unknown_table(origin, origin.table.clone())
121
121
  })?;
122
122
 
123
- let target_table = symbol_table.get_table(&target_ref.table).ok_or_else(|| {
124
- crate::compiler::graph::error::ResolveError::unknown_table(origin, target_ref.table.clone())
123
+ let resolved_table_id = target_ref.table.resolve(&origin.table);
124
+ let target_table = symbol_table.get_table(resolved_table_id).ok_or_else(|| {
125
+ crate::compiler::graph::error::ResolveError::unknown_table(
126
+ origin,
127
+ resolved_table_id.clone(),
128
+ )
125
129
  })?;
126
130
 
127
131
  let origin_coord =
@@ -138,19 +142,19 @@ pub fn lower_table_ref(
138
142
 
139
143
  let first_row = rows.first().ok_or_else(|| LoweringError::EmptyRange {
140
144
  origin: origin.clone(),
141
- target_table: target_ref.table.clone(),
145
+ target_table: resolved_table_id.clone(),
142
146
  })?;
143
147
  let last_row = rows.last().ok_or_else(|| LoweringError::EmptyRange {
144
148
  origin: origin.clone(),
145
- target_table: target_ref.table.clone(),
149
+ target_table: resolved_table_id.clone(),
146
150
  })?;
147
151
  let first_col = cols.first().ok_or_else(|| LoweringError::EmptyRange {
148
152
  origin: origin.clone(),
149
- target_table: target_ref.table.clone(),
153
+ target_table: resolved_table_id.clone(),
150
154
  })?;
151
155
  let last_col = cols.last().ok_or_else(|| LoweringError::EmptyRange {
152
156
  origin: origin.clone(),
153
- target_table: target_ref.table.clone(),
157
+ target_table: resolved_table_id.clone(),
154
158
  })?;
155
159
 
156
160
  let is_row_range = target_ref.row.is_range();
@@ -161,7 +165,7 @@ pub fn lower_table_ref(
161
165
  let (start_row_dyn, end_row_dyn) = target_ref.row.dynamic_bounds();
162
166
 
163
167
  let top_left_id = CellId::new(
164
- target_ref.table.clone(),
168
+ resolved_table_id.clone(),
165
169
  first_row.clone(),
166
170
  first_col.clone(),
167
171
  );
@@ -177,8 +181,11 @@ pub fn lower_table_ref(
177
181
  let end_pinned =
178
182
  range_endpoint_pinning(end_col_dyn, end_row_dyn, pin_static_col_on_dynamic_row);
179
183
 
180
- let bottom_right_id =
181
- CellId::new(target_ref.table.clone(), last_row.clone(), last_col.clone());
184
+ let bottom_right_id = CellId::new(
185
+ resolved_table_id.clone(),
186
+ last_row.clone(),
187
+ last_col.clone(),
188
+ );
182
189
  let bottom_right_coord =
183
190
  layout_map
184
191
  .cells
@@ -166,11 +166,58 @@ impl fmt::Display for UnaryOp {
166
166
  }
167
167
  }
168
168
 
169
+ /// Target table selector within a table reference.
170
+ #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
171
+ pub enum TableSelector {
172
+ /// Active evaluation table: `@table`.
173
+ Active,
174
+ /// Explicit table identifier: `IncomeStatement`.
175
+ Key(TableId),
176
+ }
177
+
178
+ impl TableSelector {
179
+ /// Resolves the selector against the origin table ID.
180
+ #[must_use]
181
+ pub const fn resolve<'a>(&'a self, origin_table: &'a TableId) -> &'a TableId {
182
+ match self {
183
+ Self::Active => origin_table,
184
+ Self::Key(id) => id,
185
+ }
186
+ }
187
+ }
188
+
189
+ impl From<TableId> for TableSelector {
190
+ fn from(id: TableId) -> Self {
191
+ Self::Key(id)
192
+ }
193
+ }
194
+
195
+ impl From<&str> for TableSelector {
196
+ fn from(s: &str) -> Self {
197
+ Self::Key(TableId::from(s))
198
+ }
199
+ }
200
+
201
+ impl From<String> for TableSelector {
202
+ fn from(s: String) -> Self {
203
+ Self::Key(TableId::from(s))
204
+ }
205
+ }
206
+
207
+ impl fmt::Display for TableSelector {
208
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
209
+ match self {
210
+ Self::Active => write!(f, "@table"),
211
+ Self::Key(k) => write!(f, "{k}"),
212
+ }
213
+ }
214
+ }
215
+
169
216
  /// Reference addressing target to a table.
170
217
  #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
171
218
  pub struct TableRef {
172
- /// Target table identifier.
173
- pub table: TableId,
219
+ /// Target table selector.
220
+ pub table: TableSelector,
174
221
  /// Row coordinate selector.
175
222
  pub row: RowSelector,
176
223
  /// Column coordinate selector.
@@ -179,7 +226,7 @@ pub struct TableRef {
179
226
 
180
227
  impl TableRef {
181
228
  /// Constructs a table reference: `Table[row, col]`.
182
- pub fn new(table: impl Into<TableId>, row: RowSelector, col: ColSelector) -> Self {
229
+ pub fn new(table: impl Into<TableSelector>, row: RowSelector, col: ColSelector) -> Self {
183
230
  Self {
184
231
  table: table.into(),
185
232
  row,
@@ -59,9 +59,9 @@ pub enum ParseError {
59
59
  offset: usize,
60
60
  },
61
61
 
62
- /// Bare '@' was encountered instead of '@col' or '@row'.
62
+ /// Bare '@' was encountered instead of '@col', '@row', or '@table'.
63
63
  #[error(
64
- "Bare '@' at offset {offset} is retired; specify active axis explicitly using '@col' or '@row'"
64
+ "Bare '@' at offset {offset} is retired; specify active coordinate explicitly using '@col', '@row', or '@table'"
65
65
  )]
66
66
  RetiredBareAt {
67
67
  /// Byte offset in the formula string.
@@ -8,7 +8,7 @@ pub mod parser;
8
8
 
9
9
  pub use ast::{
10
10
  BinaryOp, ColEndpoint, ColSelector, Expr, Literal, RelativeOffset, RowEndpoint, RowSelector,
11
- TableRef, UnaryOp,
11
+ TableRef, TableSelector, UnaryOp,
12
12
  };
13
13
  pub use error::ParseError;
14
14