f8-engine 0.3.1__tar.gz → 0.3.3__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.
- {f8_engine-0.3.1 → f8_engine-0.3.3}/Cargo.lock +2 -2
- {f8_engine-0.3.1 → f8_engine-0.3.3}/Cargo.toml +6 -1
- {f8_engine-0.3.1 → f8_engine-0.3.3}/PKG-INFO +11 -2
- {f8_engine-0.3.1 → f8_engine-0.3.3}/README.md +10 -1
- {f8_engine-0.3.1 → f8_engine-0.3.3}/crates/f8-core/src/compiler/compiled/mod.rs +1 -1
- {f8_engine-0.3.1 → f8_engine-0.3.3}/crates/f8-core/src/compiler/emission/format.rs +17 -2
- {f8_engine-0.3.1 → f8_engine-0.3.3}/crates/f8-core/src/compiler/emission/workbook.rs +4 -3
- {f8_engine-0.3.1 → f8_engine-0.3.3}/crates/f8-core/src/compiler/eval/context.rs +11 -2
- {f8_engine-0.3.1 → f8_engine-0.3.3}/crates/f8-core/src/compiler/eval/expr.rs +13 -3
- {f8_engine-0.3.1 → f8_engine-0.3.3}/crates/f8-core/src/compiler/eval/model.rs +5 -2
- {f8_engine-0.3.1 → f8_engine-0.3.3}/crates/f8-core/src/compiler/graph/resolve.rs +1 -1
- {f8_engine-0.3.1 → f8_engine-0.3.3}/crates/f8-core/src/compiler/ir/cell.rs +1 -1
- {f8_engine-0.3.1 → f8_engine-0.3.3}/crates/f8-core/src/compiler/ir/expand.rs +1 -1
- {f8_engine-0.3.1 → f8_engine-0.3.3}/crates/f8-core/src/compiler/ir/symbol.rs +1 -1
- {f8_engine-0.3.1 → f8_engine-0.3.3}/crates/f8-core/src/compiler/layout/a1.rs +1 -1
- {f8_engine-0.3.1 → f8_engine-0.3.3}/crates/f8-core/src/compiler/layout/mod.rs +103 -54
- {f8_engine-0.3.1 → f8_engine-0.3.3}/crates/f8-core/src/compiler/lowering/mod.rs +1 -1
- {f8_engine-0.3.1 → f8_engine-0.3.3}/crates/f8-core/src/expr/ast.rs +3 -1
- {f8_engine-0.3.1 → f8_engine-0.3.3}/crates/f8-core/src/expr/parser.rs +131 -72
- {f8_engine-0.3.1 → f8_engine-0.3.3}/crates/f8-core/src/functions/common.rs +3 -1
- {f8_engine-0.3.1 → f8_engine-0.3.3}/crates/f8-core/src/functions/date/serial.rs +1 -1
- {f8_engine-0.3.1 → f8_engine-0.3.3}/crates/f8-core/src/functions/logical/branching.rs +3 -1
- {f8_engine-0.3.1 → f8_engine-0.3.3}/crates/f8-core/src/functions/lookup/index.rs +3 -1
- {f8_engine-0.3.1 → f8_engine-0.3.3}/crates/f8-core/src/functions/lookup/search.rs +18 -6
- {f8_engine-0.3.1 → f8_engine-0.3.3}/crates/f8-core/src/functions/math/conditional.rs +22 -10
- {f8_engine-0.3.1 → f8_engine-0.3.3}/crates/f8-core/src/functions/math/criteria.rs +34 -12
- {f8_engine-0.3.1 → f8_engine-0.3.3}/crates/f8-core/src/model/error.rs +8 -0
- {f8_engine-0.3.1 → f8_engine-0.3.3}/crates/f8-core/src/model/table.rs +4 -4
- {f8_engine-0.3.1 → f8_engine-0.3.3}/crates/f8-core/src/model/theme.rs +14 -0
- {f8_engine-0.3.1 → f8_engine-0.3.3}/crates/f8-core/src/value/format.rs +1 -1
- {f8_engine-0.3.1 → f8_engine-0.3.3}/crates/f8-core/src/value/mod.rs +4 -4
- {f8_engine-0.3.1 → f8_engine-0.3.3}/crates/f8-python/src/error.rs +11 -2
- {f8_engine-0.3.1 → f8_engine-0.3.3}/crates/f8-python/src/model.rs +4 -1
- {f8_engine-0.3.1 → f8_engine-0.3.3}/python/f8/skills/f8-modeling/references/syntax-and-grid.md +1 -1
- {f8_engine-0.3.1 → f8_engine-0.3.3}/LICENSE +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.3}/crates/f8-core/Cargo.toml +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.3}/crates/f8-core/src/compiler/compiled/error.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.3}/crates/f8-core/src/compiler/compiled/model.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.3}/crates/f8-core/src/compiler/emission/error.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.3}/crates/f8-core/src/compiler/emission/mod.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.3}/crates/f8-core/src/compiler/error.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.3}/crates/f8-core/src/compiler/eval/error.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.3}/crates/f8-core/src/compiler/eval/mod.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.3}/crates/f8-core/src/compiler/graph/cycle.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.3}/crates/f8-core/src/compiler/graph/dependency.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.3}/crates/f8-core/src/compiler/graph/error.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.3}/crates/f8-core/src/compiler/graph/mod.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.3}/crates/f8-core/src/compiler/ir/error.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.3}/crates/f8-core/src/compiler/ir/id.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.3}/crates/f8-core/src/compiler/ir/mod.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.3}/crates/f8-core/src/compiler/layout/error.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.3}/crates/f8-core/src/compiler/lowering/address.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.3}/crates/f8-core/src/compiler/lowering/error.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.3}/crates/f8-core/src/compiler/mod.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.3}/crates/f8-core/src/expr/error.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.3}/crates/f8-core/src/expr/mod.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.3}/crates/f8-core/src/functions/date/constructors.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.3}/crates/f8-core/src/functions/date/mod.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.3}/crates/f8-core/src/functions/date/parts.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.3}/crates/f8-core/src/functions/date/yearfrac.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.3}/crates/f8-core/src/functions/error.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.3}/crates/f8-core/src/functions/financial/annuity.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.3}/crates/f8-core/src/functions/financial/discounting.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.3}/crates/f8-core/src/functions/financial/irr.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.3}/crates/f8-core/src/functions/financial/mod.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.3}/crates/f8-core/src/functions/logical/boolean.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.3}/crates/f8-core/src/functions/logical/error_handling.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.3}/crates/f8-core/src/functions/logical/mod.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.3}/crates/f8-core/src/functions/lookup/mod.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.3}/crates/f8-core/src/functions/lookup/xlookup.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.3}/crates/f8-core/src/functions/lookup/xmatch.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.3}/crates/f8-core/src/functions/math/aggregation.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.3}/crates/f8-core/src/functions/math/basic.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.3}/crates/f8-core/src/functions/math/mod.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.3}/crates/f8-core/src/functions/math/product.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.3}/crates/f8-core/src/functions/math/rounding.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.3}/crates/f8-core/src/functions/mod.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.3}/crates/f8-core/src/functions/registry.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.3}/crates/f8-core/src/functions/traits.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.3}/crates/f8-core/src/lib.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.3}/crates/f8-core/src/model/format.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.3}/crates/f8-core/src/model/id.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.3}/crates/f8-core/src/model/manifest.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.3}/crates/f8-core/src/model/mod.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.3}/crates/f8-core/src/value/error.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.3}/crates/f8-python/Cargo.toml +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.3}/crates/f8-python/src/lib.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.3}/pyproject.toml +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.3}/python/f8/__init__.py +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.3}/python/f8/__main__.py +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.3}/python/f8/_core.pyi +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.3}/python/f8/audit.py +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.3}/python/f8/builder.py +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.3}/python/f8/cli.py +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.3}/python/f8/py.typed +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.3}/python/f8/skills/f8-modeling/SKILL.md +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.3}/python/f8/skills/f8-modeling/references/auditing-and-repair.md +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.3}/python/f8/skills/f8-modeling/references/functions.md +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.3}/python/f8/types.py +0 -0
|
@@ -37,7 +37,7 @@ checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f"
|
|
|
37
37
|
|
|
38
38
|
[[package]]
|
|
39
39
|
name = "f8-core"
|
|
40
|
-
version = "0.3.
|
|
40
|
+
version = "0.3.3"
|
|
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.
|
|
53
|
+
version = "0.3.3"
|
|
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.
|
|
6
|
+
version = "0.3.3"
|
|
7
7
|
edition = "2024"
|
|
8
8
|
description = "Financial modeling engine with compiler verification and live Excel formulas"
|
|
9
9
|
authors = ["Michael (Chencheng) Hu, CFA"]
|
|
@@ -26,4 +26,9 @@ pythonize = "0.24"
|
|
|
26
26
|
unwrap_used = "deny"
|
|
27
27
|
expect_used = "deny"
|
|
28
28
|
wildcard_imports = "deny"
|
|
29
|
+
wildcard_enum_match_arm = "deny"
|
|
30
|
+
allow_attributes_without_reason = "deny"
|
|
31
|
+
todo = "deny"
|
|
32
|
+
unimplemented = "deny"
|
|
33
|
+
dbg_macro = "deny"
|
|
29
34
|
fn_params_excessive_bools = "warn"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: f8-engine
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.3
|
|
4
4
|
Classifier: Development Status :: 4 - Beta
|
|
5
5
|
Classifier: Intended Audience :: Developers
|
|
6
6
|
Classifier: Intended Audience :: Financial and Insurance Industry
|
|
@@ -119,10 +119,19 @@ Output:
|
|
|
119
119
|
|
|
120
120
|
## Sample deliverables
|
|
121
121
|
|
|
122
|
-
Inspect compiled deliverables generated from
|
|
122
|
+
Inspect compiled deliverables generated from real-world models:
|
|
123
123
|
|
|
124
124
|
- [costco_financial_model.xlsx](https://github.com/mhcfa/f8/releases/latest/download/costco_financial_model.xlsx): Compiled financial model with live Excel formulas.
|
|
125
125
|
- [costco_valuation_report.pdf](https://github.com/mhcfa/f8/releases/latest/download/costco_valuation_report.pdf): Valuation report rendered directly from the compiled `f8` model using Quarto, Typst, and Matplotlib.
|
|
126
|
+
- [lbo_model.xlsx](https://github.com/mhcfa/f8/releases/latest/download/lbo_model.xlsx): Multi-sheet leveraged buyout (LBO) model with transaction structuring, debt waterfall, and returns analysis.
|
|
127
|
+
|
|
128
|
+
### LBO model demo
|
|
129
|
+
|
|
130
|
+
Complete model repo: https://github.com/mhcfa/f8-demo
|
|
131
|
+
|
|
132
|
+

|
|
133
|
+
|
|
134
|
+

|
|
126
135
|
|
|
127
136
|
> Disclaimer: Sample deliverables are AI-generated technical demonstrations and do not constitute financial analysis or investment advice.
|
|
128
137
|
|
|
@@ -93,10 +93,19 @@ Output:
|
|
|
93
93
|
|
|
94
94
|
## Sample deliverables
|
|
95
95
|
|
|
96
|
-
Inspect compiled deliverables generated from
|
|
96
|
+
Inspect compiled deliverables generated from real-world models:
|
|
97
97
|
|
|
98
98
|
- [costco_financial_model.xlsx](https://github.com/mhcfa/f8/releases/latest/download/costco_financial_model.xlsx): Compiled financial model with live Excel formulas.
|
|
99
99
|
- [costco_valuation_report.pdf](https://github.com/mhcfa/f8/releases/latest/download/costco_valuation_report.pdf): Valuation report rendered directly from the compiled `f8` model using Quarto, Typst, and Matplotlib.
|
|
100
|
+
- [lbo_model.xlsx](https://github.com/mhcfa/f8/releases/latest/download/lbo_model.xlsx): Multi-sheet leveraged buyout (LBO) model with transaction structuring, debt waterfall, and returns analysis.
|
|
101
|
+
|
|
102
|
+
### LBO model demo
|
|
103
|
+
|
|
104
|
+
Complete model repo: https://github.com/mhcfa/f8-demo
|
|
105
|
+
|
|
106
|
+

|
|
107
|
+
|
|
108
|
+

|
|
100
109
|
|
|
101
110
|
> Disclaimer: Sample deliverables are AI-generated technical demonstrations and do not constitute financial analysis or investment advice.
|
|
102
111
|
|
|
@@ -153,6 +153,8 @@ pub struct CellFormatKey {
|
|
|
153
153
|
pub is_descriptor: bool,
|
|
154
154
|
/// Descriptor indentation level.
|
|
155
155
|
pub indent: u8,
|
|
156
|
+
/// Whether the cell requires multi-line text wrapping.
|
|
157
|
+
pub wrap_text: bool,
|
|
156
158
|
}
|
|
157
159
|
|
|
158
160
|
impl CellFormatKey {
|
|
@@ -175,8 +177,16 @@ impl CellFormatKey {
|
|
|
175
177
|
is_input,
|
|
176
178
|
is_descriptor,
|
|
177
179
|
indent,
|
|
180
|
+
wrap_text: false,
|
|
178
181
|
}
|
|
179
182
|
}
|
|
183
|
+
|
|
184
|
+
/// Builder method enabling or disabling text wrapping on the cell format.
|
|
185
|
+
#[must_use]
|
|
186
|
+
pub const fn with_wrap_text(mut self, wrap_text: bool) -> Self {
|
|
187
|
+
self.wrap_text = wrap_text;
|
|
188
|
+
self
|
|
189
|
+
}
|
|
180
190
|
}
|
|
181
191
|
|
|
182
192
|
/// Format synthesizer and deduplication cache mapping semantic cell keys and structural headers
|
|
@@ -328,7 +338,7 @@ impl FormatCache {
|
|
|
328
338
|
format = format.set_bold();
|
|
329
339
|
}
|
|
330
340
|
|
|
331
|
-
// 2. Alignment
|
|
341
|
+
// 2. Alignment, Indentation, and Wrapping (Descriptor Left with optional indent, Measure Right, VerticalCenter)
|
|
332
342
|
format = if key.is_descriptor {
|
|
333
343
|
let mut fmt = format.set_align(FormatAlign::Left);
|
|
334
344
|
if key.indent > 0 {
|
|
@@ -337,7 +347,12 @@ impl FormatCache {
|
|
|
337
347
|
fmt
|
|
338
348
|
} else {
|
|
339
349
|
format.set_align(FormatAlign::Right)
|
|
340
|
-
}
|
|
350
|
+
}
|
|
351
|
+
.set_align(FormatAlign::VerticalCenter);
|
|
352
|
+
|
|
353
|
+
if key.wrap_text {
|
|
354
|
+
format = format.set_text_wrap();
|
|
355
|
+
}
|
|
341
356
|
|
|
342
357
|
// 3. Background Fill Precedence:
|
|
343
358
|
// is_highlight > total (or shade) > subtotal (or shade) > shade > data
|
|
@@ -81,7 +81,7 @@ impl WorkbookEmitter {
|
|
|
81
81
|
/// # Errors
|
|
82
82
|
/// Returns [`EmissionError`] if any worksheet, table, or cell coordinate is missing
|
|
83
83
|
/// from the spatial layout, or if an OpenXML format or packaging error occurs.
|
|
84
|
-
#[allow(clippy::too_many_arguments)]
|
|
84
|
+
#[allow(clippy::too_many_arguments, reason = "explicit pass outputs")]
|
|
85
85
|
pub fn emit_to_buffer(
|
|
86
86
|
manifest: &ProjectManifest,
|
|
87
87
|
tables: &[TableSpec],
|
|
@@ -107,7 +107,7 @@ impl WorkbookEmitter {
|
|
|
107
107
|
}
|
|
108
108
|
|
|
109
109
|
/// Assembles an OpenXML workbook with worksheets, formatting, outlines, and cells.
|
|
110
|
-
#[allow(clippy::too_many_arguments)]
|
|
110
|
+
#[allow(clippy::too_many_arguments, reason = "explicit pass outputs")]
|
|
111
111
|
fn assemble_workbook(
|
|
112
112
|
manifest: &ProjectManifest,
|
|
113
113
|
tables: &[TableSpec],
|
|
@@ -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 {
|
|
@@ -51,7 +51,12 @@ impl<'a> EvalContext for CellEvalContext<'a> {
|
|
|
51
51
|
)
|
|
52
52
|
.map_err(|err| match err {
|
|
53
53
|
EvalError::Function { source, .. } => *source,
|
|
54
|
-
other
|
|
54
|
+
other @ (EvalError::CellNotFound(_)
|
|
55
|
+
| EvalError::UnevaluatedDependency(_)
|
|
56
|
+
| EvalError::Resolve(_)
|
|
57
|
+
| EvalError::UnexpectedOmitted(_)
|
|
58
|
+
| EvalError::TableNotFound(_)
|
|
59
|
+
| EvalError::RowNotFound { .. }) => FunctionError::EvaluationFailure {
|
|
55
60
|
function: "eval_expr",
|
|
56
61
|
message: other.to_string(),
|
|
57
62
|
},
|
|
@@ -84,7 +89,11 @@ impl<'a> EvalContext for CellEvalContext<'a> {
|
|
|
84
89
|
|
|
85
90
|
Ok((slice.rows, slice.cols, values))
|
|
86
91
|
}
|
|
87
|
-
_
|
|
92
|
+
Expr::Literal(_)
|
|
93
|
+
| Expr::Unary { .. }
|
|
94
|
+
| Expr::Binary { .. }
|
|
95
|
+
| Expr::FunctionCall { .. }
|
|
96
|
+
| Expr::Omitted => {
|
|
88
97
|
let val = self.eval_expr(expr)?;
|
|
89
98
|
Ok((1, 1, vec![val]))
|
|
90
99
|
}
|
|
@@ -85,7 +85,10 @@ pub fn eval_expr(
|
|
|
85
85
|
|
|
86
86
|
let normalized = match result {
|
|
87
87
|
CellValue::Number(n) => CellValue::Number(normalize_zero(n)),
|
|
88
|
-
other
|
|
88
|
+
other @ (CellValue::Text(_)
|
|
89
|
+
| CellValue::Boolean(_)
|
|
90
|
+
| CellValue::Empty
|
|
91
|
+
| CellValue::Error(_)) => other,
|
|
89
92
|
};
|
|
90
93
|
Ok(normalized)
|
|
91
94
|
}
|
|
@@ -162,7 +165,12 @@ fn eval_arithmetic_op(
|
|
|
162
165
|
}
|
|
163
166
|
lhs.powf(rhs)
|
|
164
167
|
}
|
|
165
|
-
|
|
168
|
+
BinaryOp::Eq
|
|
169
|
+
| BinaryOp::NotEq
|
|
170
|
+
| BinaryOp::Lt
|
|
171
|
+
| BinaryOp::Lte
|
|
172
|
+
| BinaryOp::Gt
|
|
173
|
+
| BinaryOp::Gte => unreachable!("non-arithmetic operator passed to eval_arithmetic_op"),
|
|
166
174
|
};
|
|
167
175
|
|
|
168
176
|
if result.is_nan() || result.is_infinite() {
|
|
@@ -194,7 +202,9 @@ fn eval_comparison_op(
|
|
|
194
202
|
BinaryOp::Lte => ord != Ordering::Greater,
|
|
195
203
|
BinaryOp::Gt => ord == Ordering::Greater,
|
|
196
204
|
BinaryOp::Gte => ord != Ordering::Less,
|
|
197
|
-
|
|
205
|
+
BinaryOp::Pow | BinaryOp::Mul | BinaryOp::Div | BinaryOp::Add | BinaryOp::Sub => {
|
|
206
|
+
unreachable!("non-comparison operator passed to eval_comparison_op")
|
|
207
|
+
}
|
|
198
208
|
};
|
|
199
209
|
|
|
200
210
|
Ok(CellValue::Boolean(outcome))
|
|
@@ -79,7 +79,10 @@ impl EvaluatedModel {
|
|
|
79
79
|
.iter()
|
|
80
80
|
.filter_map(|(id, val)| match val {
|
|
81
81
|
CellValue::Error(err) => Some((id, err)),
|
|
82
|
-
_
|
|
82
|
+
CellValue::Number(_)
|
|
83
|
+
| CellValue::Text(_)
|
|
84
|
+
| CellValue::Boolean(_)
|
|
85
|
+
| CellValue::Empty => None,
|
|
83
86
|
})
|
|
84
87
|
.collect()
|
|
85
88
|
}
|
|
@@ -130,7 +133,7 @@ impl<'a> IntoIterator for &'a EvaluatedModel {
|
|
|
130
133
|
}
|
|
131
134
|
|
|
132
135
|
#[cfg(test)]
|
|
133
|
-
#[allow(clippy::unwrap_used, clippy::expect_used)]
|
|
136
|
+
#[allow(clippy::unwrap_used, clippy::expect_used, reason = "test code")]
|
|
134
137
|
mod tests {
|
|
135
138
|
use super::*;
|
|
136
139
|
use crate::model::id::SheetId;
|
|
@@ -416,7 +416,7 @@ pub fn resolve_cell_dependencies(
|
|
|
416
416
|
}
|
|
417
417
|
|
|
418
418
|
#[cfg(test)]
|
|
419
|
-
#[allow(clippy::unwrap_used, clippy::expect_used)]
|
|
419
|
+
#[allow(clippy::unwrap_used, clippy::expect_used, reason = "test code")]
|
|
420
420
|
mod tests {
|
|
421
421
|
use super::*;
|
|
422
422
|
use crate::model::id::{SheetId, TableId};
|
|
@@ -438,7 +438,7 @@ pub fn expand_workbook(
|
|
|
438
438
|
}
|
|
439
439
|
|
|
440
440
|
#[cfg(test)]
|
|
441
|
-
#[allow(clippy::unwrap_used, clippy::expect_used)]
|
|
441
|
+
#[allow(clippy::unwrap_used, clippy::expect_used, reason = "test code")]
|
|
442
442
|
mod tests {
|
|
443
443
|
use super::*;
|
|
444
444
|
use crate::model::format::FormatPreset;
|
|
@@ -58,7 +58,7 @@ pub fn coordinate_to_a1(col: u32, row: u32) -> Result<String, LayoutError> {
|
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
#[cfg(test)]
|
|
61
|
-
#[allow(clippy::unwrap_used, clippy::expect_used)]
|
|
61
|
+
#[allow(clippy::unwrap_used, clippy::expect_used, reason = "test code")]
|
|
62
62
|
mod tests {
|
|
63
63
|
use super::*;
|
|
64
64
|
|
|
@@ -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
|
|
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(
|
|
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
|
|
674
|
+
let (char_len, lines) =
|
|
665
675
|
match (self.evaluated.and_then(|e| e.get_cell(&cell_id)), cell_node) {
|
|
666
|
-
(Some(val), _) =>
|
|
667
|
-
|
|
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
|
-
|
|
672
|
-
|
|
673
|
-
|
|
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) =>
|
|
695
|
+
(None, None) => (usize::from(indent) * 2, 1),
|
|
676
696
|
};
|
|
677
697
|
|
|
678
|
-
if
|
|
679
|
-
&& coord
|
|
698
|
+
if lines > 1
|
|
699
|
+
&& let Some(coord) = self.layout_cells.get_mut(&cell_id)
|
|
680
700
|
{
|
|
681
|
-
|
|
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,
|
|
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
|
-
.
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
ValueLiteral::Boolean(b) => {
|
|
716
|
-
|
|
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
|
|
727
|
-
fn
|
|
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
|
-
|
|
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
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
CellValue::Boolean(b) => {
|
|
740
|
-
|
|
741
|
-
|
|
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
|
|
|
@@ -288,7 +288,7 @@ fn format_binary_operand(
|
|
|
288
288
|
Expr::Unary { op: child_op, .. } => {
|
|
289
289
|
is_right || child_op.precedence() < parent_op.precedence()
|
|
290
290
|
}
|
|
291
|
-
_ => false,
|
|
291
|
+
Expr::Literal(_) | Expr::Reference(_) | Expr::FunctionCall { .. } | Expr::Omitted => false,
|
|
292
292
|
};
|
|
293
293
|
|
|
294
294
|
if wrap {
|
|
@@ -40,7 +40,9 @@ impl Expr {
|
|
|
40
40
|
match self {
|
|
41
41
|
Self::Binary { op, .. } => Some(op.precedence()),
|
|
42
42
|
Self::Unary { op, .. } => Some(op.precedence()),
|
|
43
|
-
_ =>
|
|
43
|
+
Self::Literal(_) | Self::Reference(_) | Self::FunctionCall { .. } | Self::Omitted => {
|
|
44
|
+
None
|
|
45
|
+
}
|
|
44
46
|
}
|
|
45
47
|
}
|
|
46
48
|
}
|