Improve formula validation#1359
Open
simonvoelcker wants to merge 5 commits intofrequenz-floss:v1.x.xfrom
Open
Conversation
e3dbd70 to
e570e9a
Compare
0bc315f to
c24c7a1
Compare
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>
c24c7a1 to
bade27e
Compare
Signed-off-by: simon.voelcker <simon.voelcker@gmail.com>
a563f6a to
5a80e5e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR improves formula validation and adds test coverage for all parser and lexer validation errors.
Changes
FormulaErrorandFormulaSyntaxErrorclasses.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.ASTNode.spanproperty as it was unused.Have mercy, it is my first PR 🙏 😄