From dea304ea91c4288fb017d54be3984c3a67333b19 Mon Sep 17 00:00:00 2001 From: Alex Ross <38270282+alexr00@users.noreply.github.com> Date: Thu, 3 Apr 2025 12:08:00 +0200 Subject: [PATCH] Tree sitter: A lot of detail gone from RegExp (#245427) Fixes #244572 --- .../test_regexp.ts.json | 88 +++++++++---------- .../common/languages/highlights/regex.scm | 14 ++- 2 files changed, 56 insertions(+), 46 deletions(-) diff --git a/extensions/vscode-colorize-tests/test/colorize-tree-sitter-results/test_regexp.ts.json b/extensions/vscode-colorize-tests/test/colorize-tree-sitter-results/test_regexp.ts.json index 864a8b2af01..6cdeff20a9a 100644 --- a/extensions/vscode-colorize-tests/test/colorize-tree-sitter-results/test_regexp.ts.json +++ b/extensions/vscode-colorize-tests/test/colorize-tree-sitter-results/test_regexp.ts.json @@ -57,21 +57,21 @@ }, { "c": "\\\\", - "t": "string.regexp.ts", + "t": "string.regexp.ts constant.character.escape.regexp", "r": { - "dark_plus": "string.regexp: #D16969", - "light_plus": "string.regexp: #811F3F", + "dark_plus": "constant.character.escape: #D7BA7D", + "light_plus": "constant.character.escape: #EE0000", "dark_vs": "string.regexp: #D16969", "light_vs": "string.regexp: #811F3F", - "hc_black": "string.regexp: #D16969", - "dark_modern": "string.regexp: #D16969", - "hc_light": "string.regexp: #811F3F", - "light_modern": "string.regexp: #811F3F" + "hc_black": "constant.character: #569CD6", + "dark_modern": "constant.character.escape: #D7BA7D", + "hc_light": "constant.character.escape: #EE0000", + "light_modern": "constant.character.escape: #EE0000" } }, { "c": "\\x", - "t": "string.regexp.ts internal.regexp constant.character.numeric.regexp", + "t": "string.regexp.ts constant.character.escape.regexp internal.regexp constant.character.numeric.regexp", "r": { "dark_plus": "constant.character: #569CD6", "light_plus": "constant.character: #0000FF", @@ -253,16 +253,16 @@ }, { "c": "\\-", - "t": "string.regexp.ts", + "t": "string.regexp.ts constant.character.escape.regexp", "r": { - "dark_plus": "string.regexp: #D16969", - "light_plus": "string.regexp: #811F3F", + "dark_plus": "constant.character.escape: #D7BA7D", + "light_plus": "constant.character.escape: #EE0000", "dark_vs": "string.regexp: #D16969", "light_vs": "string.regexp: #811F3F", - "hc_black": "string.regexp: #D16969", - "dark_modern": "string.regexp: #D16969", - "hc_light": "string.regexp: #811F3F", - "light_modern": "string.regexp: #811F3F" + "hc_black": "constant.character: #569CD6", + "dark_modern": "constant.character.escape: #D7BA7D", + "hc_light": "constant.character.escape: #EE0000", + "light_modern": "constant.character.escape: #EE0000" } }, { @@ -393,30 +393,30 @@ }, { "c": "\\]", - "t": "string.regexp.ts", + "t": "string.regexp.ts constant.character.escape.regexp", "r": { - "dark_plus": "string.regexp: #D16969", - "light_plus": "string.regexp: #811F3F", + "dark_plus": "constant.character.escape: #D7BA7D", + "light_plus": "constant.character.escape: #EE0000", "dark_vs": "string.regexp: #D16969", "light_vs": "string.regexp: #811F3F", - "hc_black": "string.regexp: #D16969", - "dark_modern": "string.regexp: #D16969", - "hc_light": "string.regexp: #811F3F", - "light_modern": "string.regexp: #811F3F" + "hc_black": "constant.character: #569CD6", + "dark_modern": "constant.character.escape: #D7BA7D", + "hc_light": "constant.character.escape: #EE0000", + "light_modern": "constant.character.escape: #EE0000" } }, { "c": "\\\\", - "t": "string.regexp.ts", + "t": "string.regexp.ts constant.character.escape.regexp", "r": { - "dark_plus": "string.regexp: #D16969", - "light_plus": "string.regexp: #811F3F", + "dark_plus": "constant.character.escape: #D7BA7D", + "light_plus": "constant.character.escape: #EE0000", "dark_vs": "string.regexp: #D16969", "light_vs": "string.regexp: #811F3F", - "hc_black": "string.regexp: #D16969", - "dark_modern": "string.regexp: #D16969", - "hc_light": "string.regexp: #811F3F", - "light_modern": "string.regexp: #811F3F" + "hc_black": "constant.character: #569CD6", + "dark_modern": "constant.character.escape: #D7BA7D", + "hc_light": "constant.character.escape: #EE0000", + "light_modern": "constant.character.escape: #EE0000" } }, { @@ -659,30 +659,30 @@ }, { "c": "\\/", - "t": "string.regexp.ts", + "t": "string.regexp.ts constant.character.escape.regexp", "r": { - "dark_plus": "string.regexp: #D16969", - "light_plus": "string.regexp: #811F3F", + "dark_plus": "constant.character.escape: #D7BA7D", + "light_plus": "constant.character.escape: #EE0000", "dark_vs": "string.regexp: #D16969", "light_vs": "string.regexp: #811F3F", - "hc_black": "string.regexp: #D16969", - "dark_modern": "string.regexp: #D16969", - "hc_light": "string.regexp: #811F3F", - "light_modern": "string.regexp: #811F3F" + "hc_black": "constant.character: #569CD6", + "dark_modern": "constant.character.escape: #D7BA7D", + "hc_light": "constant.character.escape: #EE0000", + "light_modern": "constant.character.escape: #EE0000" } }, { "c": "\\/", - "t": "string.regexp.ts", + "t": "string.regexp.ts constant.character.escape.regexp", "r": { - "dark_plus": "string.regexp: #D16969", - "light_plus": "string.regexp: #811F3F", + "dark_plus": "constant.character.escape: #D7BA7D", + "light_plus": "constant.character.escape: #EE0000", "dark_vs": "string.regexp: #D16969", "light_vs": "string.regexp: #811F3F", - "hc_black": "string.regexp: #D16969", - "dark_modern": "string.regexp: #D16969", - "hc_light": "string.regexp: #811F3F", - "light_modern": "string.regexp: #811F3F" + "hc_black": "constant.character: #569CD6", + "dark_modern": "constant.character.escape: #D7BA7D", + "hc_light": "constant.character.escape: #EE0000", + "light_modern": "constant.character.escape: #EE0000" } }, { @@ -1625,7 +1625,7 @@ }, { "c": "\\u", - "t": "string.regexp.ts internal.regexp constant.character.numeric.regexp", + "t": "string.regexp.ts constant.character.escape.regexp internal.regexp constant.character.numeric.regexp", "r": { "dark_plus": "constant.character: #569CD6", "light_plus": "constant.character: #0000FF", diff --git a/src/vs/editor/common/languages/highlights/regex.scm b/src/vs/editor/common/languages/highlights/regex.scm index 27b29813943..39106c3c0b6 100644 --- a/src/vs/editor/common/languages/highlights/regex.scm +++ b/src/vs/editor/common/languages/highlights/regex.scm @@ -43,6 +43,10 @@ (boundary_assertion) ] @keyword.control.anchor.regexp +(class_character) @constant.character-class.regexp + +(identity_escape) @constant.character.escape.regexp + [ ((identity_escape) @internal.regexp (#match? @internal.regexp "\\[^ux]")) ] @constant.character.escape.regexp @@ -67,6 +71,14 @@ (pattern_character) @constant.character.numeric.regexp ) @constant.character.numeric.regexp +( + ((identity_escape) @internal.regexp (#eq? @internal.regexp "\\x")) + . + (class_character) @constant.character.numeric.regexp + . + (class_character) @constant.character.numeric.regexp +) @constant.character.numeric.regexp + [ (character_class_escape) (control_escape) @@ -92,5 +104,3 @@ "^" @keyword.operator.negation.regexp (class_range "-" @constant.other.character-class.range.regexp) ]) - -(class_character) @constant.character-class.regexp