fix: Prevent parsing invalid tokens #236
Merged
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.
Fixes #217
The user will often produce invalid/incomplete config as they type, so diagnostics are ignored - which is by design in case of the parser. However the parser also assumes that the sequence of tokens it receives from the lexer is valid, i.e. that the important check for invalid tokens is not ignored.
There are some configs which one might expect to be "parseable", e.g.
but the parser isn't ready to deal with such config yet and the lexer returns the trailing
}
as string literal.If we wanted to perform completion near the opening quote we would be completing in the context of a string literal. We don't do RHS completion yet anyway, so it is not a big deal to just error out now, but I reckon we will need to revisit this to e.g. support the following
We could virtually append closing quote there, to make it a valid sequence, but the question is when (in terms of codepath). If that has to be done before we send bytes to the lexer, then we are practically reimplementing the lexer. We could also just check for particular diagnostics and rerun the lexer - which might be fragile, but it could be guarded by tests, so probably fine.