Skip to content

Comments

Improve formula validation#1359

Open
simonvoelcker wants to merge 5 commits intofrequenz-floss:v1.x.xfrom
simonvoelcker:improve-formula-validation
Open

Improve formula validation#1359
simonvoelcker wants to merge 5 commits intofrequenz-floss:v1.x.xfrom
simonvoelcker:improve-formula-validation

Conversation

@simonvoelcker
Copy link

@simonvoelcker simonvoelcker commented Feb 19, 2026

This PR improves formula validation and adds test coverage for all parser and lexer validation errors.

Changes

  1. Switch to conventional token span start/end semantics: [start, end). Spans are only used internally now, though (see (2)).
  2. Introduced FormulaError and FormulaSyntaxError classes. FormulaSyntaxError.__str__() produces a human-readable error message, highlighting the offending span in the context of the original formula. This should be fit for non-technical end users.
  3. Removed ASTNode.span property as it was unused.
  4. Added tests and adapted existing ones to the changes described above.

Have mercy, it is my first PR 🙏 😄

@simonvoelcker simonvoelcker requested a review from a team as a code owner February 19, 2026 10:01
@simonvoelcker simonvoelcker requested review from ela-kotulska-frequenz and removed request for a team February 19, 2026 10:01
@github-actions github-actions bot added part:tests Affects the unit, integration and performance (benchmarks) tests part:data-pipeline Affects the data pipeline labels Feb 19, 2026
@simonvoelcker simonvoelcker marked this pull request as draft February 19, 2026 10:01
@simonvoelcker simonvoelcker force-pushed the improve-formula-validation branch from e3dbd70 to e570e9a Compare February 19, 2026 10:35
@github-actions github-actions bot added the part:docs Affects the documentation label Feb 19, 2026
@simonvoelcker simonvoelcker force-pushed the improve-formula-validation branch 2 times, most recently from 0bc315f to c24c7a1 Compare February 19, 2026 10:58
@simonvoelcker simonvoelcker marked this pull request as ready for review February 19, 2026 11:06
@simonvoelcker simonvoelcker marked this pull request as draft February 19, 2026 14:30
The tokens produced by our formula parser (lexer) contained
spans with unusual and inconvenient start/end indices. The
represented interval should be closed at the start and open
at the end: [start,end). This makes it easy to slice the
original formula and to compute the length of the span.

Part of frequenz-floss#1356

Signed-off-by: simon.voelcker <simon.voelcker@gmail.com>
- Added FormulaError and FormulaSyntaxError classes, using them in lexer and parser.
- Changes to how functions are parsed: Detect unknown function first, then parse parameter list.
- Removed mentions of terms, factors, unaries from error messages - Everything's an expression.
- Better message for matching paranthesis.
- Avoiding use of ASTNode.span in error messages, since it will be removed.

Part of frequenz-floss#1356

Signed-off-by: simon.voelcker <simon.voelcker@gmail.com>
Signed-off-by: simon.voelcker <simon.voelcker@gmail.com>
Signed-off-by: simon.voelcker <simon.voelcker@gmail.com>
@simonvoelcker simonvoelcker force-pushed the improve-formula-validation branch from c24c7a1 to bade27e Compare February 20, 2026 13:56
Signed-off-by: simon.voelcker <simon.voelcker@gmail.com>
@simonvoelcker simonvoelcker force-pushed the improve-formula-validation branch from a563f6a to 5a80e5e Compare February 20, 2026 14:16
@simonvoelcker simonvoelcker marked this pull request as ready for review February 20, 2026 14:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

part:data-pipeline Affects the data pipeline part:docs Affects the documentation part:tests Affects the unit, integration and performance (benchmarks) tests

Projects

Status: To do

Development

Successfully merging this pull request may close these issues.

1 participant