OpenXLSX 1.9.1
Loading...
Searching...
No Matches
XLFormulaEngine.hpp
Go to the documentation of this file.
1#ifndef OPENXLSX_XLFORMULAENGINE_HPP
2#define OPENXLSX_XLFORMULAENGINE_HPP
3
4#ifdef _MSC_VER
5# pragma warning(push)
6# pragma warning(disable : 4251)
7# pragma warning(disable : 4275)
8#endif
9
10// ===== Standard Library ===== //
11#include <functional>
12#include <memory>
13#include <string>
14#include <string_view>
15#include <unordered_map>
16#include <vector>
17
18// ===== GSL ===== //
19#include <gsl/gsl>
20
21// ===== OpenXLSX Includes ===== //
22#include "OpenXLSX-Exports.hpp"
23#include "XLCellValue.hpp"
24#include "XLCellReference.hpp"
25
26
27// Forward declare XLWorksheet so callers can use makeResolver without pulling the full header.
28namespace OpenXLSX
29{
30 class XLWorksheet;
31}
32
33namespace OpenXLSX
34{
35 // =========================================================================
36 // Lexer
37 // =========================================================================
38
42 enum class XLTokenKind : uint8_t {
43 Number,
44 String,
45 Bool,
46 CellRef,
47 Ident,
48 Plus,
49 Minus,
50 Star,
51 Slash,
52 Caret,
53 Percent,
54 Amp,
55 Eq,
56 NEq,
57 Lt,
58 Le,
59 Gt,
60 Ge,
61 LParen,
62 RParen,
63 Comma,
64 Semicolon,
65 Colon,
66 End,
67 Error
68 };
69
73 struct OPENXLSX_EXPORT XLToken
74 {
75 XLTokenKind kind{XLTokenKind::Error};
76 std::string text;
77 double number{0.0};
78 bool boolean{false};
79 };
80
87 class OPENXLSX_EXPORT XLFormulaLexer
88 {
89 public:
95 static std::vector<XLToken> tokenize(std::string_view formula);
96
97 private:
98 // Stateless helper – everything runs in tokenize().
99 };
100
101 // =========================================================================
102 // AST
103 // =========================================================================
104
106 enum class XLNodeKind : uint8_t {
107 Number,
108 StringLit,
109 BoolLit,
110 CellRef,
111 Range,
112 BinOp,
113 UnaryOp,
114 FuncCall,
115 ErrorLit
116 };
117
122 struct OPENXLSX_EXPORT XLASTNode
123 {
125
126 // ---- Leaf payloads ----
127 double number{0.0};
128 std::string text;
129 bool boolean{false};
130 XLTokenKind op{XLTokenKind::Error};
131
132 // ---- Children ----
133 std::vector<std::unique_ptr<XLASTNode>> children;
134
135 explicit XLASTNode(XLNodeKind k) : kind(k) {}
136
137 // Non-copyable due to unique_ptr children; movable.
138 XLASTNode(const XLASTNode&) = delete;
139 XLASTNode& operator=(const XLASTNode&) = delete;
140 XLASTNode(XLASTNode&&) = default;
142 };
143
144 // =========================================================================
145 // Parser
146 // =========================================================================
147
151 class OPENXLSX_EXPORT XLFormulaParser
152 {
153 public:
160 static std::unique_ptr<XLASTNode> parse(gsl::span<const XLToken> tokens);
161
162 private:
163 // All state is local to the recursive parse calls below.
164 struct ParseContext
165 {
166 gsl::span<const XLToken> tokens;
167 std::size_t pos{0};
168
169 [[nodiscard]] const XLToken& current() const;
170 [[nodiscard]] const XLToken& peek(std::size_t offset = 1) const;
171 const XLToken& consume();
172 bool matchKind(XLTokenKind k);
173 };
174
175 static std::unique_ptr<XLASTNode> parseExpr(ParseContext& ctx, int minPrec = 0);
176 static std::unique_ptr<XLASTNode> parseUnary(ParseContext& ctx);
177 static std::unique_ptr<XLASTNode> parsePrimary(ParseContext& ctx);
178 static std::unique_ptr<XLASTNode> parseFuncCall(std::string name, ParseContext& ctx);
179
180 static int precedence(XLTokenKind k);
181 static bool isRightAssoc(XLTokenKind k);
182 };
183
184 // =========================================================================
185 // Evaluator / Engine
186 // =========================================================================
187
199 using XLCellResolver = std::function<XLCellValue(std::string_view ref)>;
200
215 class OPENXLSX_EXPORT XLFormulaArg
216 {
217 public:
218 enum class Type { Empty, Scalar, Array, LazyRange };
219
220 private:
221 Type m_type{Type::Empty};
222 XLCellValue m_scalar;
223 std::vector<XLCellValue> m_array;
224 uint32_t m_r1{0}, m_r2{0};
225 uint16_t m_c1{0}, m_c2{0};
226 std::string m_sheetName;
227 const std::function<XLCellValue(std::string_view)>* m_resolver{nullptr};
228
229 public:
230 XLFormulaArg() = default;
231 XLFormulaArg(XLCellValue v) : m_type(Type::Scalar), m_scalar(std::move(v)) {}
232 XLFormulaArg(std::vector<XLCellValue> arr) : m_type(Type::Array), m_array(std::move(arr)) {}
233 XLFormulaArg(uint32_t r1,
234 uint32_t r2,
235 uint16_t c1,
236 uint16_t c2,
237 std::string sheetName,
238 const std::function<XLCellValue(std::string_view)>* resolver)
239 : m_type(Type::LazyRange),
240 m_r1(r1),
241 m_r2(r2),
242 m_c1(c1),
243 m_c2(c2),
244 m_sheetName(std::move(sheetName)),
245 m_resolver(resolver)
246 {}
247
248 Type type() const { return m_type; }
249
250 size_t rows() const {
251 if (m_type == Type::LazyRange) return static_cast<size_t>(m_r2 - m_r1 + 1);
252 if (m_type == Type::Array) return m_array.size(); // simplified, arrays might be 2d but we treat as 1d column
253 return m_type == Type::Scalar ? 1 : 0;
254 }
255
256 size_t cols() const {
257 if (m_type == Type::LazyRange) return static_cast<size_t>(m_c2 - m_c1 + 1);
258 return m_type == Type::Scalar || m_type == Type::Array ? 1 : 0;
259 }
260
261 bool empty() const
262 {
263 if (m_type == Type::Empty) return true;
264 if (m_type == Type::Scalar) return m_scalar.type() == XLValueType::Empty;
265 if (m_type == Type::Array) return m_array.empty();
266 return m_r1 > m_r2 || m_c1 > m_c2;
267 }
268 size_t size() const
269 {
270 if (m_type == Type::Empty) return 0;
271 if (m_type == Type::Scalar) return 1;
272 if (m_type == Type::Array) return m_array.size();
273 return static_cast<size_t>(m_r2 - m_r1 + 1) * static_cast<size_t>(m_c2 - m_c1 + 1);
274 }
275
276 XLCellValue operator[](size_t index) const
277 {
278 if (m_type == Type::Scalar) return index == 0 ? m_scalar : XLCellValue();
279 if (m_type == Type::Array) return index < m_array.size() ? m_array[index] : XLCellValue();
280 if (m_type == Type::LazyRange) {
281 uint16_t w = m_c2 - m_c1 + 1;
282 uint32_t row = m_r1 + static_cast<uint32_t>(index / w);
283 uint16_t col = m_c1 + static_cast<uint16_t>(index % w);
284 std::string ref = m_sheetName;
285 if (!ref.empty()) ref += "!";
286 ref += XLCellReference(row, col).address();
287 if (m_resolver && *m_resolver) return (*m_resolver)(ref);
288 }
289 return XLCellValue();
290 }
291
293 {
294 const XLFormulaArg* arg;
295 size_t index;
296
297 public:
298 Iterator(const XLFormulaArg* a, size_t i) : arg(a), index(i) {}
299 XLCellValue operator*() const { return (*arg)[index]; }
301 {
302 ++index;
303 return *this;
304 }
305 bool operator!=(const Iterator& other) const { return index != other.index; }
306 };
307 Iterator begin() const { return Iterator(this, 0); }
308 Iterator end() const { return Iterator(this, size()); }
309 };
310
311 class OPENXLSX_EXPORT XLFormulaEngine
312 {
313 public:
315 ~XLFormulaEngine() = default;
316
321
329 [[nodiscard]] XLCellValue evaluate(std::string_view formula, const XLCellResolver& resolver = {}) const;
330
337 [[nodiscard]] static XLCellResolver makeResolver(const XLWorksheet& wks);
338
339 private:
340 // ---- Internal evaluation helpers ----
341
345 static XLFormulaArg expandRange(std::string_view rangeRef, const XLCellResolver& resolver);
346
350 static std::vector<double> collectNumbers(const std::vector<XLCellValue>& flat, bool countBlanks = false);
351
356 [[nodiscard]] XLCellValue evalNode(const XLASTNode& node, const XLCellResolver& resolver) const;
357
362 [[nodiscard]] XLFormulaArg expandArg(const XLASTNode& argNode, const XLCellResolver& resolver) const;
363
364 // ---- Built-in function table ----
365 // Each entry maps an uppercase function name to its implementation.
366 using FuncArgs = std::vector<XLCellValue>;
367 using FuncImpl = std::function<XLCellValue(const std::vector<XLFormulaArg>&)>;
368 std::unordered_map<std::string, FuncImpl> m_functions;
369
370 void registerBuiltins();
371
372 // ---- Helpers registered as lambdas in registerBuiltins() ----
373 static XLCellValue fnSum(const std::vector<XLFormulaArg>& args);
374 static XLCellValue fnAverage(const std::vector<XLFormulaArg>& args);
375 static XLCellValue fnMin(const std::vector<XLFormulaArg>& args);
376 static XLCellValue fnMax(const std::vector<XLFormulaArg>& args);
377 static XLCellValue fnCount(const std::vector<XLFormulaArg>& args);
378 static XLCellValue fnCounta(const std::vector<XLFormulaArg>& args);
379 static XLCellValue fnIf(const std::vector<XLFormulaArg>& args);
380 static XLCellValue fnIfs(const std::vector<XLFormulaArg>& args);
381 static XLCellValue fnSwitch(const std::vector<XLFormulaArg>& args);
382 static XLCellValue fnAnd(const std::vector<XLFormulaArg>& args);
383 static XLCellValue fnOr(const std::vector<XLFormulaArg>& args);
384 static XLCellValue fnNot(const std::vector<XLFormulaArg>& args);
385 static XLCellValue fnIferror(const std::vector<XLFormulaArg>& args);
386 static XLCellValue fnAbs(const std::vector<XLFormulaArg>& args);
387 static XLCellValue fnRound(const std::vector<XLFormulaArg>& args);
388 static XLCellValue fnRoundup(const std::vector<XLFormulaArg>& args);
389 static XLCellValue fnRounddown(const std::vector<XLFormulaArg>& args);
390 static XLCellValue fnSqrt(const std::vector<XLFormulaArg>& args);
391 static XLCellValue fnPi(const std::vector<XLFormulaArg>& args);
392 static XLCellValue fnSin(const std::vector<XLFormulaArg>& args);
393 static XLCellValue fnCos(const std::vector<XLFormulaArg>& args);
394 static XLCellValue fnTan(const std::vector<XLFormulaArg>& args);
395 static XLCellValue fnAsin(const std::vector<XLFormulaArg>& args);
396 static XLCellValue fnAcos(const std::vector<XLFormulaArg>& args);
397 static XLCellValue fnDegrees(const std::vector<XLFormulaArg>& args);
398 static XLCellValue fnRadians(const std::vector<XLFormulaArg>& args);
399 static XLCellValue fnRand(const std::vector<XLFormulaArg>& args);
400 static XLCellValue fnRandbetween(const std::vector<XLFormulaArg>& args);
401 static XLCellValue fnInt(const std::vector<XLFormulaArg>& args);
402 static XLCellValue fnMod(const std::vector<XLFormulaArg>& args);
403 static XLCellValue fnPower(const std::vector<XLFormulaArg>& args);
404 static XLCellValue fnVlookup(const std::vector<XLFormulaArg>& args);
405 static XLCellValue fnHlookup(const std::vector<XLFormulaArg>& args);
406 static XLCellValue fnXlookup(const std::vector<XLFormulaArg>& args);
407 static XLCellValue fnIndex(const std::vector<XLFormulaArg>& args);
408 static XLCellValue fnMatch(const std::vector<XLFormulaArg>& args);
409 static XLCellValue fnConcatenate(const std::vector<XLFormulaArg>& args);
410 static XLCellValue fnLen(const std::vector<XLFormulaArg>& args);
411 static XLCellValue fnLeft(const std::vector<XLFormulaArg>& args);
412 static XLCellValue fnRight(const std::vector<XLFormulaArg>& args);
413 static XLCellValue fnMid(const std::vector<XLFormulaArg>& args);
414 static XLCellValue fnUpper(const std::vector<XLFormulaArg>& args);
415 static XLCellValue fnLower(const std::vector<XLFormulaArg>& args);
416 static XLCellValue fnTrim(const std::vector<XLFormulaArg>& args);
417 static XLCellValue fnText(const std::vector<XLFormulaArg>& args);
418 static XLCellValue fnIsnumber(const std::vector<XLFormulaArg>& args);
419 static XLCellValue fnIsblank(const std::vector<XLFormulaArg>& args);
420 static XLCellValue fnIserror(const std::vector<XLFormulaArg>& args);
421 static XLCellValue fnIstext(const std::vector<XLFormulaArg>& args);
422
423 // ---- Date / Time ----
424 static XLCellValue fnToday(const std::vector<XLFormulaArg>& args);
425 static XLCellValue fnNow(const std::vector<XLFormulaArg>& args);
426 static XLCellValue fnDate(const std::vector<XLFormulaArg>& args);
427 static XLCellValue fnTime(const std::vector<XLFormulaArg>& args);
428 static XLCellValue fnYear(const std::vector<XLFormulaArg>& args);
429 static XLCellValue fnMonth(const std::vector<XLFormulaArg>& args);
430 static XLCellValue fnDay(const std::vector<XLFormulaArg>& args);
431 static XLCellValue fnHour(const std::vector<XLFormulaArg>& args);
432 static XLCellValue fnMinute(const std::vector<XLFormulaArg>& args);
433 static XLCellValue fnSecond(const std::vector<XLFormulaArg>& args);
434 static XLCellValue fnDays(const std::vector<XLFormulaArg>& args);
435 static XLCellValue fnWeekday(const std::vector<XLFormulaArg>& args);
436 static XLCellValue fnEdate(const std::vector<XLFormulaArg>& args);
437 static XLCellValue fnEomonth(const std::vector<XLFormulaArg>& args);
438 static XLCellValue fnWorkday(const std::vector<XLFormulaArg>& args);
439 static XLCellValue fnNetworkdays(const std::vector<XLFormulaArg>& args);
440
441 // ---- Financial ----
442 static XLCellValue fnPmt(const std::vector<XLFormulaArg>& args);
443 static XLCellValue fnFv(const std::vector<XLFormulaArg>& args);
444 static XLCellValue fnPv(const std::vector<XLFormulaArg>& args);
445 static XLCellValue fnNpv(const std::vector<XLFormulaArg>& args);
446
447 // ---- Math extended ----
448 static XLCellValue fnSumproduct(const std::vector<XLFormulaArg>& args);
449 static XLCellValue fnCeil(const std::vector<XLFormulaArg>& args);
450 static XLCellValue fnFloor(const std::vector<XLFormulaArg>& args);
451 static XLCellValue fnLog(const std::vector<XLFormulaArg>& args);
452 static XLCellValue fnLog10(const std::vector<XLFormulaArg>& args);
453 static XLCellValue fnExp(const std::vector<XLFormulaArg>& args);
454 static XLCellValue fnSign(const std::vector<XLFormulaArg>& args);
455
456 // ---- Text extended ----
457 static XLCellValue fnFind(const std::vector<XLFormulaArg>& args);
458 static XLCellValue fnSearch(const std::vector<XLFormulaArg>& args);
459 static XLCellValue fnSubstitute(const std::vector<XLFormulaArg>& args);
460 static XLCellValue fnReplace(const std::vector<XLFormulaArg>& args);
461 static XLCellValue fnRept(const std::vector<XLFormulaArg>& args);
462 static XLCellValue fnExact(const std::vector<XLFormulaArg>& args);
463 static XLCellValue fnT(const std::vector<XLFormulaArg>& args);
464 static XLCellValue fnValue(const std::vector<XLFormulaArg>& args);
465 static XLCellValue fnTextjoin(const std::vector<XLFormulaArg>& args);
466 static XLCellValue fnClean(const std::vector<XLFormulaArg>& args);
467 static XLCellValue fnProper(const std::vector<XLFormulaArg>& args);
468
469 // ---- Statistical / Conditional ----
470 static XLCellValue fnSumif(const std::vector<XLFormulaArg>& args);
471 static XLCellValue fnCountif(const std::vector<XLFormulaArg>& args);
472 static XLCellValue fnSumifs(const std::vector<XLFormulaArg>& args);
473 static XLCellValue fnCountifs(const std::vector<XLFormulaArg>& args);
474 static XLCellValue fnMaxifs(const std::vector<XLFormulaArg>& args);
475 static XLCellValue fnMinifs(const std::vector<XLFormulaArg>& args);
476 static XLCellValue fnAverageif(const std::vector<XLFormulaArg>& args);
477 static XLCellValue fnRank(const std::vector<XLFormulaArg>& args);
478 static XLCellValue fnLarge(const std::vector<XLFormulaArg>& args);
479 static XLCellValue fnSmall(const std::vector<XLFormulaArg>& args);
480 static XLCellValue fnStdev(const std::vector<XLFormulaArg>& args);
481 static XLCellValue fnVar(const std::vector<XLFormulaArg>& args);
482 static XLCellValue fnMedian(const std::vector<XLFormulaArg>& args);
483 static XLCellValue fnCountblank(const std::vector<XLFormulaArg>& args);
484
485 // ---- Info extended ----
486 static XLCellValue fnIsna(const std::vector<XLFormulaArg>& args);
487 static XLCellValue fnIfna(const std::vector<XLFormulaArg>& args);
488 static XLCellValue fnIslogical(const std::vector<XLFormulaArg>& args);
489
490 // ---- Easy Additions (Logical, Math, Stat, Text, Financial) ----
491 static XLCellValue fnTrue(const std::vector<XLFormulaArg>& args);
492 static XLCellValue fnFalse(const std::vector<XLFormulaArg>& args);
493 static XLCellValue fnIseven(const std::vector<XLFormulaArg>& args);
494 static XLCellValue fnIsodd(const std::vector<XLFormulaArg>& args);
495 static XLCellValue fnMround(const std::vector<XLFormulaArg>& args);
496 static XLCellValue fnCeilingMath(const std::vector<XLFormulaArg>& args);
497 static XLCellValue fnFloorMath(const std::vector<XLFormulaArg>& args);
498 static XLCellValue fnVarp(const std::vector<XLFormulaArg>& args);
499 static XLCellValue fnStdevp(const std::vector<XLFormulaArg>& args);
500 static XLCellValue fnVara(const std::vector<XLFormulaArg>& args);
501 static XLCellValue fnVarpa(const std::vector<XLFormulaArg>& args);
502 static XLCellValue fnStdeva(const std::vector<XLFormulaArg>& args);
503 static XLCellValue fnStdevpa(const std::vector<XLFormulaArg>& args);
504 static XLCellValue fnPermut(const std::vector<XLFormulaArg>& args);
505 static XLCellValue fnPermutationa(const std::vector<XLFormulaArg>& args);
506 static XLCellValue fnFisher(const std::vector<XLFormulaArg>& args);
507 static XLCellValue fnFisherinv(const std::vector<XLFormulaArg>& args);
508 static XLCellValue fnStandardize(const std::vector<XLFormulaArg>& args);
509 static XLCellValue fnPearson(const std::vector<XLFormulaArg>& args);
510 static XLCellValue fnRsq(const std::vector<XLFormulaArg>& args);
511 static XLCellValue fnAverageifs(const std::vector<XLFormulaArg>& args);
512 static XLCellValue fnIsoweeknum(const std::vector<XLFormulaArg>& args);
513 static XLCellValue fnWeeknum(const std::vector<XLFormulaArg>& args);
514 static XLCellValue fnDays360(const std::vector<XLFormulaArg>& args);
515 static XLCellValue fnNper(const std::vector<XLFormulaArg>& args);
516 static XLCellValue fnDb(const std::vector<XLFormulaArg>& args);
517 static XLCellValue fnDdb(const std::vector<XLFormulaArg>& args);
518 static XLCellValue fnIserr(const std::vector<XLFormulaArg>& args);
519 static XLCellValue fnTrunc(const std::vector<XLFormulaArg>& args);
520 static XLCellValue fnSumsq(const std::vector<XLFormulaArg>& args);
521 static XLCellValue fnSumx2my2(const std::vector<XLFormulaArg>& args);
522 static XLCellValue fnSumx2py2(const std::vector<XLFormulaArg>& args);
523 static XLCellValue fnSumxmy2(const std::vector<XLFormulaArg>& args);
524 static XLCellValue fnAvedev(const std::vector<XLFormulaArg>& args);
525 static XLCellValue fnDevsq(const std::vector<XLFormulaArg>& args);
526 static XLCellValue fnAveragea(const std::vector<XLFormulaArg>& args);
527 static XLCellValue fnSln(const std::vector<XLFormulaArg>& args);
528 static XLCellValue fnSyd(const std::vector<XLFormulaArg>& args);
529 static XLCellValue fnChar(const std::vector<XLFormulaArg>& args);
530 static XLCellValue fnUnichar(const std::vector<XLFormulaArg>& args);
531 static XLCellValue fnCode(const std::vector<XLFormulaArg>& args);
532 static XLCellValue fnUnicode(const std::vector<XLFormulaArg>& args);
533 static XLCellValue fnCovarianceP(const std::vector<XLFormulaArg>& args);
534 static XLCellValue fnCovarianceS(const std::vector<XLFormulaArg>& args);
535 static XLCellValue fnTrimmean(const std::vector<XLFormulaArg>& args);
536 static XLCellValue fnSlope(const std::vector<XLFormulaArg>& args);
537 static XLCellValue fnIntercept(const std::vector<XLFormulaArg>& args);
538 static XLCellValue fnPercentileInc(const std::vector<XLFormulaArg>& args);
539 static XLCellValue fnPercentileExc(const std::vector<XLFormulaArg>& args);
540 static XLCellValue fnQuartileInc(const std::vector<XLFormulaArg>& args);
541 static XLCellValue fnQuartileExc(const std::vector<XLFormulaArg>& args);
542 static XLCellValue fnIsnontext(const std::vector<XLFormulaArg>& args);
543 };
544
545} // namespace OpenXLSX
546
547#ifdef _MSC_VER
548# pragma warning(pop)
549#endif
550
551#endif // OPENXLSX_XLFORMULAENGINE_HPP
Definition XLCellReference.hpp:34
std::string address() const
Get the address of the XLCellReference.
Definition XLCellReference.cpp:193
Class encapsulating a cell value.
Definition XLCellValue.hpp:79
Definition XLFormulaEngine.hpp:293
Iterator(const XLFormulaArg *a, size_t i)
Definition XLFormulaEngine.hpp:298
bool operator!=(const Iterator &other) const
Definition XLFormulaEngine.hpp:305
Iterator & operator++()
Definition XLFormulaEngine.hpp:300
XLCellValue operator*() const
Definition XLFormulaEngine.hpp:299
Lightweight formula evaluation engine.
Definition XLFormulaEngine.hpp:216
size_t rows() const
Definition XLFormulaEngine.hpp:250
XLFormulaArg(uint32_t r1, uint32_t r2, uint16_t c1, uint16_t c2, std::string sheetName, const std::function< XLCellValue(std::string_view)> *resolver)
Definition XLFormulaEngine.hpp:233
Iterator end() const
Definition XLFormulaEngine.hpp:308
bool empty() const
Definition XLFormulaEngine.hpp:261
XLFormulaArg(std::vector< XLCellValue > arr)
Definition XLFormulaEngine.hpp:232
XLCellValue operator[](size_t index) const
Definition XLFormulaEngine.hpp:276
size_t cols() const
Definition XLFormulaEngine.hpp:256
XLFormulaArg(XLCellValue v)
Definition XLFormulaEngine.hpp:231
size_t size() const
Definition XLFormulaEngine.hpp:268
Iterator begin() const
Definition XLFormulaEngine.hpp:307
Type type() const
Definition XLFormulaEngine.hpp:248
Type
Definition XLFormulaEngine.hpp:218
Definition XLFormulaEngine.hpp:312
XLFormulaEngine & operator=(const XLFormulaEngine &)=delete
XLFormulaEngine(XLFormulaEngine &&)=default
XLFormulaEngine(const XLFormulaEngine &)=delete
XLFormulaEngine & operator=(XLFormulaEngine &&)=default
Tokenises a raw Excel formula string (with or without leading '=').
Definition XLFormulaEngine.hpp:88
Recursive-descent (Pratt) parser that converts a token stream into an AST.
Definition XLFormulaEngine.hpp:152
A class encapsulating an Excel worksheet. Access to XLWorksheet objects should be via the workbook ob...
Definition XLWorksheet.hpp:118
Definition IZipArchive.hpp:18
XLNodeKind
Kind discriminator for AST nodes.
Definition XLFormulaEngine.hpp:106
@ Range
e.g. "A1:B10" – evaluated lazily by the resolver
@ ErrorLit
#NAME?, etc. – propagated as-is
XLTokenKind
Kinds of tokens produced by the lexer.
Definition XLFormulaEngine.hpp:42
@ Amp
& (string concat)
@ Ident
Function name or named range.
@ Colon
: (used inside range references parsed by lexer)
@ CellRef
Cell reference A1, $B$2, Sheet1!C3.
@ End
Sentinel – end of input.
@ Semicolon
; (alternative argument separator in some locales)
@ Bool
TRUE or FALSE keyword.
std::function< XLCellValue(std::string_view ref)> XLCellResolver
Callback type: resolves a cell reference string to a cell value.
Definition XLFormulaEngine.hpp:199
Definition XLCellIterator.hpp:121
Polymorphic AST node. Uses a tagged-union approach with std::unique_ptr children.
Definition XLFormulaEngine.hpp:123
XLASTNode(const XLASTNode &)=delete
XLASTNode(XLNodeKind k)
Definition XLFormulaEngine.hpp:135
std::vector< std::unique_ptr< XLASTNode > > children
operands or function arguments
Definition XLFormulaEngine.hpp:133
XLASTNode & operator=(XLASTNode &&)=default
std::string text
string literal, cell-ref text, range text, identifier, error text
Definition XLFormulaEngine.hpp:128
XLNodeKind kind
Definition XLFormulaEngine.hpp:124
XLASTNode & operator=(const XLASTNode &)=delete
XLASTNode(XLASTNode &&)=default
A single lexical token from a formula string.
Definition XLFormulaEngine.hpp:74
std::string text
Raw text of the token (number string, identifier, …)
Definition XLFormulaEngine.hpp:76