Add support for Ruby string interpolation highlighting - #911
Open
Toshimaru (toshimaru) wants to merge 3 commits into
Open
Add support for Ruby string interpolation highlighting#911Toshimaru (toshimaru) wants to merge 3 commits into
Toshimaru (toshimaru) wants to merge 3 commits into
Conversation
The two forms differed only by an optional `\w+\.` receiver prefix, so they collapse into one regex with fewer redundant "def" prefix tests on the common path.
The exponent suffix (?:e[+-]?[\d_]+)? was duplicated across separate float and integer alternatives. Making the fractional part optional instead expresses the same constraint with one shared exponent clause.
Inline the double-quote and backtick string loops so an interpolation
branch can highlight #{...} as variable, matching how shellscript.lsh
handles $var. Nested braces aren't supported, matching the same
limitation there.
There was a problem hiding this comment.
Pull request overview
This pull request refines the Ruby LSH definition to better tokenize double-quoted and backtick strings by recognizing interpolations (#{...}) and distinguishing them from escaped interpolations (\#{...}), while also simplifying method definition matching and tightening numeric literal parsing to avoid swallowing . in ranges and method calls.
Changes:
- Add interpolation recognition to
"and`string parsing, with correct handling of escaped interpolation (\#{...}). - Simplify
defparsing to handle both regular and singleton methods with one regex. - Adjust numeric literal regex to reduce false positives around
1..2and1.upto(2)patterns, and extend highlighting tests accordingly.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| crates/lsh/definitions/ruby.lsh | Updates Ruby lexer rules for interpolated strings, method definitions, and numeric literals. |
| assets/highlighting-tests/ruby.rb | Adds highlighting fixtures for escaped interpolation and interpolation in backtick strings. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Follow-up to #849.
This pull request improves the Ruby syntax highlighting logic and its corresponding test cases. The main focus is on better handling of string interpolation and escape sequences, as well as simplifying and correcting method definition parsing.
String and interpolation handling
"...") and backtick (`...`) strings to properly distinguish between escape sequences, interpolations (e.g.,#{...}), and regular string content. Escaped interpolations (e.g.,\#{...}) are now correctly recognized as plain strings, not variables.ruby.rbto verify correct handling of escaped interpolations and interpolations in backtick strings.Before:
After:
Method definition parsing
def fooanddef self.foo) in a single pattern, reducing code duplication.Number literal parsing
1..2and1.upto(2).