Skip to main content

Module swissknife

Module swissknife 

Source
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 constants E and PI

Two details trip up implementations that reach for a C-like grammar, and both appear in the majority of real vendor descriptions:

  1. = is equality, <> is inequality. There is no assignment in the language, so = is never ambiguous. == and != are accepted as tolerated aliases.
  2. Integer formulas evaluate in i64, not f64. IntSwissKnife and IntConverter use EvalMode::Integer, where / truncates and 64-bit register values stay exact. Evaluating (HIGH << 32) | LOW in f64 silently 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§

ParseError
Error produced while parsing a GenApi formula.

Enums§

AstNode
Parsed GenApi formula represented as an abstract syntax tree.
BinaryOp
Binary operator kinds supported by the GenApi formula language.
EvalError
Error produced while evaluating a GenApi formula.
EvalMode
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 name denotes one.
collect_identifiers
Collect all variable identifiers referenced by the AST.
evaluate
Evaluate an AstNode using the provided variable resolver.
is_builtin_constant
Whether name denotes a GenApi built-in constant.
parse_expression
Parse a GenApi formula into an AstNode.
substitute
Replace variable references with sub-expressions.