From f4d1e7901cbf12cae5eab8c10eb0935855066747 Mon Sep 17 00:00:00 2001 From: chbk Date: Sat, 22 Mar 2025 20:11:19 +0100 Subject: [PATCH] Improve Regex syntax highlighting (#25332) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 = /^(?[!\.\?])\b[a-z]+word\k$/g ``` --------- Co-authored-by: João Marcos --- crates/languages/src/regex/highlights.scm | 26 ++++++++++++++--------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/crates/languages/src/regex/highlights.scm b/crates/languages/src/regex/highlights.scm index 2504dab79ea58e93547a22f8ae6dd4fe9f73c012..3829c3834bc3f145d8697080ad05ad8191bfa96f 100644 --- a/crates/languages/src/regex/highlights.scm +++ b/crates/languages/src/regex/highlights.scm @@ -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) ])