Skip to content

Expression grammar improvements #468

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

cdce8p
Copy link

@cdce8p cdce8p commented May 3, 2025

This PR bundles a few expression grammar improvements. To review it might help to look at each commit individually. If preferred, I can also split these of into separate PRs.

The examples below are mainly taken from https://github.com/home-assistant/core/blob/dev/.github/workflows/ci.yaml

Fix syntax highlighting for if blocks

Before After
Screenshot 2025-05-03 at 15 05 46 Screenshot 2025-05-03 at 15 06 14

Before the || would be interpreted as the start of an unquoted block and break the syntax highlighting until the next job starts.

Fixes #224

Disable syntax highlighting for if keys in comments

Before After
Screenshot 2025-05-03 at 15 12 08 Screenshot 2025-05-03 at 15 12 42
Screenshot 2025-05-03 at 15 14 51 Screenshot 2025-05-03 at 15 14 51

Multiline if blocks didn't change since they weren't even recognized in the first place previously

Fixes: #259
Fixes partially: #158 (not addressed here inline-expressions inside comments: #158 (comment))

Fix syntax highlighting for inline expressions spanning multiple lines

Before After
Screenshot 2025-05-03 at 15 18 48 Screenshot 2025-05-03 at 15 19 05

This is quite a common pattern, especially for cache key and restore-keys.

One caveat of this change is how it affects invalid expressions. E.g. missing the closing }}. IMO it isn't as bad since it clearly highlights the invalid syntax. There is also the opportunity to improve on it later.

Before After
Screenshot 2025-05-03 at 15 20 52 Screenshot 2025-05-03 at 15 21 24

Fix nested curly brackets

Before After
Screenshot 2025-05-03 at 19 14 53 Screenshot 2025-05-03 at 19 15 13

Side effect I discovered while testing. Seems these cases are also fixed now.

Fixes #394
Fixes #223

@cdce8p cdce8p requested a review from a team as a code owner May 3, 2025 17:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant