Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(lxlquery): Improve grammar + lint #1199

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from

Conversation

jesperengstrom
Copy link
Contributor

@jesperengstrom jesperengstrom commented Jan 14, 2025

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:

Skärmavbild 2025-01-14 kl  10 56 31

Summary of changes

  • Rewrite grammar
  • Add lxlLinter extension for language
  • Update (still rudimentary) styling
  • Rewrite tests
  • Fixed a bug in insertQuotes that inserted quotes for 'special' qualifiers without key/value such as includeEplikt

@jesperengstrom jesperengstrom marked this pull request as ready for review January 14, 2025 10:35
@jesperengstrom jesperengstrom force-pushed the feat/lxlquery-grammar-lint-etc branch from e2bfc3f to 2f651cb Compare January 15, 2025 10:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant