fix(grammar): Fix syntax highlighting for Kernel.` method in Ruby grammar #2493
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.
Motivation
Closes #1470
The issue was that syntax highlighting breaks when using the
Kernel.\`
method in Ruby code. The grammar was incorrectly treating the backtick in this context as the start of an interpolated string literal, leading to incorrect tokenization and highlighting.Implementation
To address this, the Ruby grammar was updated to properly distinguish between backtick string literals and the
Kernel.`
method calls. Specifically, thebegin
pattern for backticks was modified to include a negative lookbehind(?<!\\.)
, ensuring that only standalone backticks are treated as string delimiters.ref. https://rbuckton.github.io/regexp-features/engines/oniguruma.html
Additionally, I added new test cases to cover both standard backtick strings and
Kernel.\`
method calls. These tests verify that the grammar correctly tokenizes each scenario, ensuring that backtick strings are recognized as interpolated strings, whileKernel.\`
methods are handled without string interpretation.Automated Tests
Unit tests were added as part of this change to ensure that both scenarios (standard backtick strings and
Kernel.\`
method calls) are correctly handled by the grammar.Manual Tests
Before
After