Improve Regex syntax highlighting (#25332)
chbk
and
João Marcos
created
Release Notes:
- Improved Regex syntax highlighting
| Zed 0.174.6 | With this PR |
| --- | --- |
|

|

|
- `(?P=`, `<`: `punctuation.bracket`
- `group_name`: `property` -> `label`
- `^`, `$`: `string.escape` -> `operator`
- `\b`, `\B`, `\k`: `string.escape` -> `keyword.operator`
- added `regex` scope to target regex tokens specifically
```js
regex = /^(?<group>[!\.\?])\b[a-z]+word\k<group>$/g
```
---------
Co-authored-by: João Marcos <marcospb19@hotmail.com>
Change summary
crates/languages/src/regex/highlights.scm | 26 +++++++++++++++---------
1 file changed, 16 insertions(+), 10 deletions(-)
Detailed changes
@@ -4,24 +4,22 @@
"(?"
"(?:"
"(?<"
+ "(?P="
+ "<"
">"
"["
"]"
"{"
"}"
-] @string
+] @punctuation.bracket.regex
-(group_name) @property
+(group_name) @label.regex
[
(identity_escape)
(control_letter_escape)
(character_class_escape)
(control_escape)
- (start_assertion)
- (end_assertion)
- (boundary_assertion)
- (non_boundary_assertion)
] @string.escape
[
@@ -31,17 +29,25 @@
"|"
"="
"!"
+ (start_assertion)
+ (end_assertion)
(any_character)
-] @operator
+] @operator.regex
+
+[
+ (boundary_assertion)
+ (non_boundary_assertion)
+ (backreference_escape)
+] @keyword.operator.regex
(count_quantifier
[
(decimal_digits) @number
- "," @punctuation.delimiter
+ "," @punctuation.delimiter.regex
])
(character_class
[
- "^" @operator
- (class_range "-" @operator)
+ "^" @operator.regex
+ (class_range "-" @operator.regex)
])