Expand description
GenApi formula parser and evaluator.
Covers the expression language used by <SwissKnife>, <IntSwissKnife>,
<Converter> and <IntConverter> nodes:
- Arithmetic:
+ - * / %and**for power - Comparison:
< <= > >=,=(equality) and<>(inequality) - Logical:
&& || - Bitwise:
& | ^ ~ << >> - Ternary:
condition ? then : else - Functions:
SGN NEG ATAN SIN COS TAN ABS EXP LN LG SQRT TRUNC ROUND FLOOR CEIL ASIN ACOS, plus the constantsEandPI
Two details trip up implementations that reach for a C-like grammar, and both appear in the majority of real vendor descriptions:
=is equality,<>is inequality. There is no assignment in the language, so=is never ambiguous.==and!=are accepted as tolerated aliases.- Integer formulas evaluate in
i64, notf64.IntSwissKnifeandIntConverteruseEvalMode::Integer, where/truncates and 64-bit register values stay exact. Evaluating(HIGH << 32) | LOWinf64silently loses the low bits.
Operator precedence and the integer/float promotion rules follow the GenApi
specification, cross-checked against the reference implementation in
aravis (src/arvevaluator.c: arv_evaluator_token_infos for precedence,
the integer_mode branches of arv_evaluator_evaluate for promotion).
Structs§
- Parse
Error - Error produced while parsing a GenApi formula.
Enums§
- AstNode
- Parsed GenApi formula represented as an abstract syntax tree.
- Binary
Op - Binary operator kinds supported by the GenApi formula language.
- Eval
Error - Error produced while evaluating a GenApi formula.
- Eval
Mode - Arithmetic mode for a formula.
- UnaryOp
- Unary operator kinds supported by the GenApi formula language.
- Value
- Numeric value flowing through a GenApi formula.
Functions§
- builtin_
constant - Value of a GenApi built-in constant, if
namedenotes one. - collect_
identifiers - Collect all variable identifiers referenced by the AST.
- evaluate
- Evaluate an
AstNodeusing the provided variable resolver. - is_
builtin_ constant - Whether
namedenotes a GenApi built-in constant. - parse_
expression - Parse a GenApi formula into an
AstNode. - substitute
- Replace variable references with sub-expressions.