f8-engine 0.3.1__tar.gz → 0.3.2__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.2}/Cargo.lock +2 -2
- {f8_engine-0.3.1 → f8_engine-0.3.2}/Cargo.toml +6 -1
- {f8_engine-0.3.1 → f8_engine-0.3.2}/PKG-INFO +11 -2
- {f8_engine-0.3.1 → f8_engine-0.3.2}/README.md +10 -1
- {f8_engine-0.3.1 → f8_engine-0.3.2}/crates/f8-core/src/compiler/compiled/mod.rs +1 -1
- {f8_engine-0.3.1 → f8_engine-0.3.2}/crates/f8-core/src/compiler/emission/workbook.rs +2 -2
- {f8_engine-0.3.1 → f8_engine-0.3.2}/crates/f8-core/src/compiler/eval/context.rs +11 -2
- {f8_engine-0.3.1 → f8_engine-0.3.2}/crates/f8-core/src/compiler/eval/expr.rs +13 -3
- {f8_engine-0.3.1 → f8_engine-0.3.2}/crates/f8-core/src/compiler/eval/model.rs +5 -2
- {f8_engine-0.3.1 → f8_engine-0.3.2}/crates/f8-core/src/compiler/graph/resolve.rs +1 -1
- {f8_engine-0.3.1 → f8_engine-0.3.2}/crates/f8-core/src/compiler/ir/cell.rs +1 -1
- {f8_engine-0.3.1 → f8_engine-0.3.2}/crates/f8-core/src/compiler/ir/expand.rs +1 -1
- {f8_engine-0.3.1 → f8_engine-0.3.2}/crates/f8-core/src/compiler/ir/symbol.rs +1 -1
- {f8_engine-0.3.1 → f8_engine-0.3.2}/crates/f8-core/src/compiler/layout/a1.rs +1 -1
- {f8_engine-0.3.1 → f8_engine-0.3.2}/crates/f8-core/src/compiler/lowering/mod.rs +1 -1
- {f8_engine-0.3.1 → f8_engine-0.3.2}/crates/f8-core/src/expr/ast.rs +3 -1
- {f8_engine-0.3.1 → f8_engine-0.3.2}/crates/f8-core/src/expr/parser.rs +131 -72
- {f8_engine-0.3.1 → f8_engine-0.3.2}/crates/f8-core/src/functions/common.rs +3 -1
- {f8_engine-0.3.1 → f8_engine-0.3.2}/crates/f8-core/src/functions/date/serial.rs +1 -1
- {f8_engine-0.3.1 → f8_engine-0.3.2}/crates/f8-core/src/functions/logical/branching.rs +3 -1
- {f8_engine-0.3.1 → f8_engine-0.3.2}/crates/f8-core/src/functions/lookup/index.rs +3 -1
- {f8_engine-0.3.1 → f8_engine-0.3.2}/crates/f8-core/src/functions/lookup/search.rs +18 -6
- {f8_engine-0.3.1 → f8_engine-0.3.2}/crates/f8-core/src/functions/math/conditional.rs +22 -10
- {f8_engine-0.3.1 → f8_engine-0.3.2}/crates/f8-core/src/functions/math/criteria.rs +34 -12
- {f8_engine-0.3.1 → f8_engine-0.3.2}/crates/f8-core/src/model/table.rs +4 -4
- {f8_engine-0.3.1 → f8_engine-0.3.2}/crates/f8-core/src/value/format.rs +1 -1
- {f8_engine-0.3.1 → f8_engine-0.3.2}/crates/f8-core/src/value/mod.rs +4 -4
- {f8_engine-0.3.1 → f8_engine-0.3.2}/crates/f8-python/src/error.rs +10 -2
- {f8_engine-0.3.1 → f8_engine-0.3.2}/crates/f8-python/src/model.rs +4 -1
- {f8_engine-0.3.1 → f8_engine-0.3.2}/LICENSE +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.2}/crates/f8-core/Cargo.toml +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.2}/crates/f8-core/src/compiler/compiled/error.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.2}/crates/f8-core/src/compiler/compiled/model.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.2}/crates/f8-core/src/compiler/emission/error.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.2}/crates/f8-core/src/compiler/emission/format.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.2}/crates/f8-core/src/compiler/emission/mod.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.2}/crates/f8-core/src/compiler/error.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.2}/crates/f8-core/src/compiler/eval/error.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.2}/crates/f8-core/src/compiler/eval/mod.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.2}/crates/f8-core/src/compiler/graph/cycle.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.2}/crates/f8-core/src/compiler/graph/dependency.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.2}/crates/f8-core/src/compiler/graph/error.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.2}/crates/f8-core/src/compiler/graph/mod.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.2}/crates/f8-core/src/compiler/ir/error.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.2}/crates/f8-core/src/compiler/ir/id.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.2}/crates/f8-core/src/compiler/ir/mod.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.2}/crates/f8-core/src/compiler/layout/error.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.2}/crates/f8-core/src/compiler/layout/mod.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.2}/crates/f8-core/src/compiler/lowering/address.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.2}/crates/f8-core/src/compiler/lowering/error.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.2}/crates/f8-core/src/compiler/mod.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.2}/crates/f8-core/src/expr/error.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.2}/crates/f8-core/src/expr/mod.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.2}/crates/f8-core/src/functions/date/constructors.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.2}/crates/f8-core/src/functions/date/mod.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.2}/crates/f8-core/src/functions/date/parts.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.2}/crates/f8-core/src/functions/date/yearfrac.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.2}/crates/f8-core/src/functions/error.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.2}/crates/f8-core/src/functions/financial/annuity.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.2}/crates/f8-core/src/functions/financial/discounting.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.2}/crates/f8-core/src/functions/financial/irr.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.2}/crates/f8-core/src/functions/financial/mod.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.2}/crates/f8-core/src/functions/logical/boolean.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.2}/crates/f8-core/src/functions/logical/error_handling.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.2}/crates/f8-core/src/functions/logical/mod.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.2}/crates/f8-core/src/functions/lookup/mod.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.2}/crates/f8-core/src/functions/lookup/xlookup.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.2}/crates/f8-core/src/functions/lookup/xmatch.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.2}/crates/f8-core/src/functions/math/aggregation.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.2}/crates/f8-core/src/functions/math/basic.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.2}/crates/f8-core/src/functions/math/mod.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.2}/crates/f8-core/src/functions/math/product.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.2}/crates/f8-core/src/functions/math/rounding.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.2}/crates/f8-core/src/functions/mod.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.2}/crates/f8-core/src/functions/registry.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.2}/crates/f8-core/src/functions/traits.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.2}/crates/f8-core/src/lib.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.2}/crates/f8-core/src/model/error.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.2}/crates/f8-core/src/model/format.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.2}/crates/f8-core/src/model/id.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.2}/crates/f8-core/src/model/manifest.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.2}/crates/f8-core/src/model/mod.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.2}/crates/f8-core/src/model/theme.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.2}/crates/f8-core/src/value/error.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.2}/crates/f8-python/Cargo.toml +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.2}/crates/f8-python/src/lib.rs +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.2}/pyproject.toml +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.2}/python/f8/__init__.py +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.2}/python/f8/__main__.py +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.2}/python/f8/_core.pyi +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.2}/python/f8/audit.py +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.2}/python/f8/builder.py +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.2}/python/f8/cli.py +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.2}/python/f8/py.typed +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.2}/python/f8/skills/f8-modeling/SKILL.md +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.2}/python/f8/skills/f8-modeling/references/auditing-and-repair.md +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.2}/python/f8/skills/f8-modeling/references/functions.md +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.2}/python/f8/skills/f8-modeling/references/syntax-and-grid.md +0 -0
- {f8_engine-0.3.1 → f8_engine-0.3.2}/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.2"
|
|
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.2"
|
|
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.2"
|
|
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.2
|
|
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
|
|
|
@@ -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],
|
|
@@ -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
|
|
|
@@ -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
|
}
|
|
@@ -80,7 +80,20 @@ impl<'a> Token<'a> {
|
|
|
80
80
|
Self::Lte => Some(BinaryOp::Lte),
|
|
81
81
|
Self::Gt => Some(BinaryOp::Gt),
|
|
82
82
|
Self::Gte => Some(BinaryOp::Gte),
|
|
83
|
-
_
|
|
83
|
+
Self::Number(_)
|
|
84
|
+
| Self::String(_)
|
|
85
|
+
| Self::Boolean(_)
|
|
86
|
+
| Self::Ident(_)
|
|
87
|
+
| Self::Underscore
|
|
88
|
+
| Self::LParen
|
|
89
|
+
| Self::RParen
|
|
90
|
+
| Self::LBracket
|
|
91
|
+
| Self::RBracket
|
|
92
|
+
| Self::Comma
|
|
93
|
+
| Self::Dot
|
|
94
|
+
| Self::DotDot
|
|
95
|
+
| Self::AtCol
|
|
96
|
+
| Self::AtRow => None,
|
|
84
97
|
}
|
|
85
98
|
}
|
|
86
99
|
}
|
|
@@ -681,7 +694,24 @@ fn parse_prefix(stream: &mut TokenStream<'_>) -> Result<Expr, ParseError> {
|
|
|
681
694
|
}),
|
|
682
695
|
}
|
|
683
696
|
}
|
|
684
|
-
other
|
|
697
|
+
other @ (Token::Underscore
|
|
698
|
+
| Token::RParen
|
|
699
|
+
| Token::LBracket
|
|
700
|
+
| Token::RBracket
|
|
701
|
+
| Token::Comma
|
|
702
|
+
| Token::Dot
|
|
703
|
+
| Token::DotDot
|
|
704
|
+
| Token::AtCol
|
|
705
|
+
| Token::AtRow
|
|
706
|
+
| Token::Star
|
|
707
|
+
| Token::Slash
|
|
708
|
+
| Token::Caret
|
|
709
|
+
| Token::Eq
|
|
710
|
+
| Token::NotEq
|
|
711
|
+
| Token::Lt
|
|
712
|
+
| Token::Lte
|
|
713
|
+
| Token::Gt
|
|
714
|
+
| Token::Gte) => {
|
|
685
715
|
let found = other.to_string();
|
|
686
716
|
Err(ParseError::UnexpectedToken {
|
|
687
717
|
expected: "expression",
|
|
@@ -834,16 +864,20 @@ fn parse_relative_offset(
|
|
|
834
864
|
let k = if stream.peek_token() == Some(&Token::LParen) {
|
|
835
865
|
stream.advance();
|
|
836
866
|
let k = match stream.consume() {
|
|
837
|
-
Some(num_st) =>
|
|
838
|
-
Token::Number(n)
|
|
839
|
-
|
|
867
|
+
Some(num_st) => {
|
|
868
|
+
if let Token::Number(n) = num_st.token
|
|
869
|
+
&& n.fract() == 0.0
|
|
870
|
+
&& n >= 0.0
|
|
871
|
+
{
|
|
872
|
+
n as u32
|
|
873
|
+
} else {
|
|
840
874
|
return Err(ParseError::UnexpectedToken {
|
|
841
875
|
expected: "integer offset",
|
|
842
|
-
found:
|
|
876
|
+
found: num_st.token.to_string(),
|
|
843
877
|
offset: num_st.offset,
|
|
844
878
|
});
|
|
845
879
|
}
|
|
846
|
-
}
|
|
880
|
+
}
|
|
847
881
|
None => {
|
|
848
882
|
return Err(ParseError::UnexpectedEof {
|
|
849
883
|
expected: expected_rparen,
|
|
@@ -895,7 +929,27 @@ fn parse_row_endpoint(stream: &mut TokenStream<'_>) -> Result<RowEndpoint, Parse
|
|
|
895
929
|
stream.advance();
|
|
896
930
|
Err(ParseError::UnquotedCoordinateKey { found, offset })
|
|
897
931
|
}
|
|
898
|
-
other
|
|
932
|
+
other @ (Token::Boolean(_)
|
|
933
|
+
| Token::Underscore
|
|
934
|
+
| Token::LParen
|
|
935
|
+
| Token::RParen
|
|
936
|
+
| Token::LBracket
|
|
937
|
+
| Token::RBracket
|
|
938
|
+
| Token::Comma
|
|
939
|
+
| Token::Dot
|
|
940
|
+
| Token::DotDot
|
|
941
|
+
| Token::AtCol
|
|
942
|
+
| Token::Plus
|
|
943
|
+
| Token::Minus
|
|
944
|
+
| Token::Star
|
|
945
|
+
| Token::Slash
|
|
946
|
+
| Token::Caret
|
|
947
|
+
| Token::Eq
|
|
948
|
+
| Token::NotEq
|
|
949
|
+
| Token::Lt
|
|
950
|
+
| Token::Lte
|
|
951
|
+
| Token::Gt
|
|
952
|
+
| Token::Gte) => {
|
|
899
953
|
let found = other.to_string();
|
|
900
954
|
Err(ParseError::UnexpectedToken {
|
|
901
955
|
expected: "row selector ('@row', quoted string key, 'row.prev', or 'row.next')",
|
|
@@ -949,7 +1003,27 @@ fn parse_col_endpoint(stream: &mut TokenStream<'_>) -> Result<ColEndpoint, Parse
|
|
|
949
1003
|
stream.advance();
|
|
950
1004
|
Err(ParseError::UnquotedCoordinateKey { found, offset })
|
|
951
1005
|
}
|
|
952
|
-
other
|
|
1006
|
+
other @ (Token::Boolean(_)
|
|
1007
|
+
| Token::Underscore
|
|
1008
|
+
| Token::LParen
|
|
1009
|
+
| Token::RParen
|
|
1010
|
+
| Token::LBracket
|
|
1011
|
+
| Token::RBracket
|
|
1012
|
+
| Token::Comma
|
|
1013
|
+
| Token::Dot
|
|
1014
|
+
| Token::DotDot
|
|
1015
|
+
| Token::AtRow
|
|
1016
|
+
| Token::Plus
|
|
1017
|
+
| Token::Minus
|
|
1018
|
+
| Token::Star
|
|
1019
|
+
| Token::Slash
|
|
1020
|
+
| Token::Caret
|
|
1021
|
+
| Token::Eq
|
|
1022
|
+
| Token::NotEq
|
|
1023
|
+
| Token::Lt
|
|
1024
|
+
| Token::Lte
|
|
1025
|
+
| Token::Gt
|
|
1026
|
+
| Token::Gte) => {
|
|
953
1027
|
let found = other.to_string();
|
|
954
1028
|
Err(ParseError::UnexpectedToken {
|
|
955
1029
|
expected: "column selector ('@col', quoted string key, 'col.prev', or 'col.next')",
|
|
@@ -972,7 +1046,7 @@ fn parse_col_spec(stream: &mut TokenStream<'_>) -> Result<ColSelector, ParseErro
|
|
|
972
1046
|
}
|
|
973
1047
|
|
|
974
1048
|
#[cfg(test)]
|
|
975
|
-
#[allow(clippy::unwrap_used, clippy::expect_used)]
|
|
1049
|
+
#[allow(clippy::unwrap_used, clippy::expect_used, reason = "test code")]
|
|
976
1050
|
mod tests {
|
|
977
1051
|
use super::*;
|
|
978
1052
|
use crate::model::id::{ColId, RowId, TableId};
|
|
@@ -1119,27 +1193,25 @@ mod tests {
|
|
|
1119
1193
|
#[test]
|
|
1120
1194
|
fn test_function_calls() {
|
|
1121
1195
|
let expr = parse_expr_str("IF(Assumptions[\"flag\", \"active\"] = 1, 100, 0)").unwrap();
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
);
|
|
1138
|
-
assert_eq!(args[1], Expr::number(100.0));
|
|
1139
|
-
assert_eq!(args[2], Expr::number(0.0));
|
|
1196
|
+
let Expr::FunctionCall { name, args } = expr else {
|
|
1197
|
+
panic!("Expected FunctionCall, got {expr:?}");
|
|
1198
|
+
};
|
|
1199
|
+
assert_eq!(name, "IF");
|
|
1200
|
+
assert_eq!(args.len(), 3);
|
|
1201
|
+
assert_eq!(
|
|
1202
|
+
args[0],
|
|
1203
|
+
Expr::Binary {
|
|
1204
|
+
op: BinaryOp::Eq,
|
|
1205
|
+
left: Box::new(Expr::Reference(TableRef::new(
|
|
1206
|
+
"Assumptions",
|
|
1207
|
+
RowSelector::Key(RowId::new("flag")),
|
|
1208
|
+
ColSelector::Key(ColId::new("active")),
|
|
1209
|
+
))),
|
|
1210
|
+
right: Box::new(Expr::number(1.0)),
|
|
1140
1211
|
}
|
|
1141
|
-
|
|
1142
|
-
|
|
1212
|
+
);
|
|
1213
|
+
assert_eq!(args[1], Expr::number(100.0));
|
|
1214
|
+
assert_eq!(args[2], Expr::number(0.0));
|
|
1143
1215
|
|
|
1144
1216
|
let nullary = parse_expr_str("PI()").unwrap();
|
|
1145
1217
|
assert_eq!(
|
|
@@ -1295,81 +1367,68 @@ mod tests {
|
|
|
1295
1367
|
fn test_reject_dot_access() {
|
|
1296
1368
|
// Dot access with active column
|
|
1297
1369
|
let err_dot = parse_expr_str("IncomeStatement.revenue[@col]").unwrap_err();
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
other => panic!("Expected UnexpectedToken for dot, got {other:?}"),
|
|
1304
|
-
}
|
|
1370
|
+
let ParseError::UnexpectedToken { found, offset, .. } = err_dot else {
|
|
1371
|
+
panic!("Expected UnexpectedToken for dot, got {err_dot:?}");
|
|
1372
|
+
};
|
|
1373
|
+
assert_eq!(found, ".");
|
|
1374
|
+
assert_eq!(offset, 15);
|
|
1305
1375
|
|
|
1306
1376
|
// Dot access with row identifier only
|
|
1307
1377
|
let err_dot_bare = parse_expr_str("IncomeStatement.revenue").unwrap_err();
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
other => panic!("Expected UnexpectedToken for dot, got {other:?}"),
|
|
1314
|
-
}
|
|
1378
|
+
let ParseError::UnexpectedToken { found, offset, .. } = err_dot_bare else {
|
|
1379
|
+
panic!("Expected UnexpectedToken for dot, got {err_dot_bare:?}");
|
|
1380
|
+
};
|
|
1381
|
+
assert_eq!(found, ".");
|
|
1382
|
+
assert_eq!(offset, 15);
|
|
1315
1383
|
}
|
|
1316
1384
|
|
|
1317
1385
|
#[test]
|
|
1318
1386
|
fn test_reject_unquoted_coordinate_keys() {
|
|
1319
1387
|
let err1 = parse_expr_str("IncomeStatement[\"revenue\", 2024E]").unwrap_err();
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1388
|
+
let ParseError::UnquotedCoordinateKey { found, .. } = err1 else {
|
|
1389
|
+
panic!("Expected UnquotedCoordinateKey, got {err1:?}");
|
|
1390
|
+
};
|
|
1391
|
+
assert_eq!(found, "2024E");
|
|
1324
1392
|
|
|
1325
1393
|
let err2 = parse_expr_str("Opex[r_and_d, @col]").unwrap_err();
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1394
|
+
let ParseError::UnquotedCoordinateKey { found, .. } = err2 else {
|
|
1395
|
+
panic!("Expected UnquotedCoordinateKey, got {err2:?}");
|
|
1396
|
+
};
|
|
1397
|
+
assert_eq!(found, "r_and_d");
|
|
1330
1398
|
}
|
|
1331
1399
|
|
|
1332
1400
|
#[test]
|
|
1333
1401
|
fn test_reject_lowercase_function_name() {
|
|
1334
1402
|
let err = parse_expr_str("sum(1, 2)").unwrap_err();
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1403
|
+
let ParseError::InvalidFunctionName { name, .. } = err else {
|
|
1404
|
+
panic!("Expected InvalidFunctionName, got {err:?}");
|
|
1405
|
+
};
|
|
1406
|
+
assert_eq!(name, "sum");
|
|
1339
1407
|
}
|
|
1340
1408
|
|
|
1341
1409
|
#[test]
|
|
1342
1410
|
fn test_reject_bare_identifiers() {
|
|
1343
1411
|
// Bare table identifier without access operator
|
|
1344
1412
|
let err_table = parse_expr_str("IncomeStatement").unwrap_err();
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1413
|
+
let ParseError::UnexpectedToken { found, .. } = err_table else {
|
|
1414
|
+
panic!("Expected UnexpectedToken, got {err_table:?}");
|
|
1415
|
+
};
|
|
1416
|
+
assert_eq!(found, "IncomeStatement");
|
|
1349
1417
|
}
|
|
1350
1418
|
|
|
1351
1419
|
#[test]
|
|
1352
1420
|
fn test_keyword_boundary_validation() {
|
|
1353
1421
|
// col.prevent should not parse as col.prev
|
|
1354
1422
|
let err = parse_expr_str("Table[\"row\", col.prevent]").unwrap_err();
|
|
1355
|
-
|
|
1356
|
-
ParseError::UnexpectedToken { .. } => {}
|
|
1357
|
-
other => panic!("Expected unexpected token error, got {other:?}"),
|
|
1358
|
-
}
|
|
1423
|
+
assert!(matches!(err, ParseError::UnexpectedToken { .. }));
|
|
1359
1424
|
|
|
1360
1425
|
// row.prevent should not parse as row.prev
|
|
1361
1426
|
let err_row = parse_expr_str("Table[row.prevent, \"col\"]").unwrap_err();
|
|
1362
|
-
|
|
1363
|
-
ParseError::UnexpectedToken { .. } => {}
|
|
1364
|
-
other => panic!("Expected unexpected token error, got {other:?}"),
|
|
1365
|
-
}
|
|
1427
|
+
assert!(matches!(err_row, ParseError::UnexpectedToken { .. }));
|
|
1366
1428
|
|
|
1367
1429
|
// col.nextly should not parse as col.next
|
|
1368
1430
|
let err = parse_expr_str("Table[\"row\", col.nextly]").unwrap_err();
|
|
1369
|
-
|
|
1370
|
-
ParseError::UnexpectedToken { .. } => {}
|
|
1371
|
-
other => panic!("Expected unexpected token error, got {other:?}"),
|
|
1372
|
-
}
|
|
1431
|
+
assert!(matches!(err, ParseError::UnexpectedToken { .. }));
|
|
1373
1432
|
|
|
1374
1433
|
// Bare @ is retired
|
|
1375
1434
|
let err_at = parse_expr_str("Table[\"row\", @]").unwrap_err();
|
|
@@ -452,6 +452,8 @@ pub fn extract_scalar_number(arg: &FunctionArg<'_>) -> Result<f64, ExcelError> {
|
|
|
452
452
|
match arg {
|
|
453
453
|
FunctionArg::Scalar(val) => val.coerce_to_number(),
|
|
454
454
|
FunctionArg::Array { values, .. } if values.len() == 1 => values[0].coerce_to_number(),
|
|
455
|
-
_ =>
|
|
455
|
+
FunctionArg::Array { .. } | FunctionArg::Lazy(_) | FunctionArg::Omitted => {
|
|
456
|
+
Err(ExcelError::Value)
|
|
457
|
+
}
|
|
456
458
|
}
|
|
457
459
|
}
|
|
@@ -85,7 +85,9 @@ impl ExcelFunction for IfFunction {
|
|
|
85
85
|
} else {
|
|
86
86
|
match &args[2] {
|
|
87
87
|
FunctionArg::Omitted => Ok(CellValue::Boolean(false)),
|
|
88
|
-
other
|
|
88
|
+
other @ (FunctionArg::Scalar(_)
|
|
89
|
+
| FunctionArg::Array { .. }
|
|
90
|
+
| FunctionArg::Lazy(_)) => eval_branch_arg(other, self.name(), ctx),
|
|
89
91
|
}
|
|
90
92
|
}
|
|
91
93
|
}
|
|
@@ -79,7 +79,9 @@ impl ExcelFunction for IndexFunction {
|
|
|
79
79
|
}
|
|
80
80
|
(1, 1, std::slice::from_ref(val))
|
|
81
81
|
}
|
|
82
|
-
_ =>
|
|
82
|
+
FunctionArg::Lazy(_) | FunctionArg::Omitted => {
|
|
83
|
+
return Ok(CellValue::Error(ExcelError::Value));
|
|
84
|
+
}
|
|
83
85
|
};
|
|
84
86
|
|
|
85
87
|
if rows == 0 || cols == 0 || values.is_empty() {
|