Improve Regex syntax highlighting (#25332)

Release Notes:

  - Improved Regex syntax highlighting

| Zed 0.174.6 | With this PR |
| --- | --- |
|
![Image](https://github.com/user-attachments/assets/2a0bb1d9-cbba-490c-b2be-08c94bc79517)
|
![Image](https://github.com/user-attachments/assets/b19f3871-ee83-4165-a026-207bdbbcad44)
|

- `(?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>
This commit is contained in:
chbk 2025-03-22 20:11:19 +01:00 committed by GitHub
parent 044eb7b990
commit f4d1e7901c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -4,24 +4,22 @@
"(?" "(?"
"(?:" "(?:"
"(?<" "(?<"
"(?P="
"<"
">" ">"
"[" "["
"]" "]"
"{" "{"
"}" "}"
] @string ] @punctuation.bracket.regex
(group_name) @property (group_name) @label.regex
[ [
(identity_escape) (identity_escape)
(control_letter_escape) (control_letter_escape)
(character_class_escape) (character_class_escape)
(control_escape) (control_escape)
(start_assertion)
(end_assertion)
(boundary_assertion)
(non_boundary_assertion)
] @string.escape ] @string.escape
[ [
@ -31,17 +29,25 @@
"|" "|"
"=" "="
"!" "!"
(start_assertion)
(end_assertion)
(any_character) (any_character)
] @operator ] @operator.regex
[
(boundary_assertion)
(non_boundary_assertion)
(backreference_escape)
] @keyword.operator.regex
(count_quantifier (count_quantifier
[ [
(decimal_digits) @number (decimal_digits) @number
"," @punctuation.delimiter "," @punctuation.delimiter.regex
]) ])
(character_class (character_class
[ [
"^" @operator "^" @operator.regex
(class_range "-" @operator) (class_range "-" @operator.regex)
]) ])