feat(lxlquery): Improve grammar + lint #1199
Open
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.
Description
Tickets involved
LWS-292
Solves
Upon discovering that the frontend language parsing was allowing stuff that the backend don't and vice versa, I tried to fill in the gaps in our grammar, but ended up rewriting the whole thing after inspecting the backend code.
see source
The root node now being
orcomb
(not exported), this exports pretty much the same nodes as before, but with more robust logic and less code. For example:Used to be valid but is invalid:
key>(sommar AND vinter)
Used to be invalid but is valid:
!(sommar AND vinter)
The query language is clearly not settled (whitespace discussion), but with frontend/backend in sync, we can (must!) do parallel changes moving forward.
Instead of rewriting all of our tests, I replaced many of them with the backend tests most relevant for our use case.
Lint
To spot valid/invalid queries, I tried adding mark decorations to error nodes. This feels pretty useful for us and maybe for the end user too. So i ended up doing a linting extension that is now bundled with the language. This simply highlights syntax errors from the language + a couple of manual cases (next step can be to use Codemirror lint package for tooltips etc). Try some invalid queries:
()
AND sommar
"Astrid Lindgren
NOT sommar NOT OR vinter
code:("something" and code:"whatever")
sommar!
(pretty strange that this is invalid, but as long as it is, the frontend should point it out)NOT
The language now exports inequality term nodes, which can be used to highlight excluded terms. I added very basic styling, but this needs improvement if we want to handle double negatives (NOT NOT) for example, or style pills like we do today:
Summary of changes
includeEplikt