From a667cdef0dba0c637e523c006d7f6b2950a88d58 Mon Sep 17 00:00:00 2001 From: Josh Goebel Date: Sat, 14 Dec 2024 10:18:05 -0500 Subject: [PATCH] fix(rust) emoji supported in single quote strings (#4156) --- CHANGES.md | 1 + src/languages/rust.js | 13 +++++++++++-- test/markup/rust/strings.expect.txt | 8 ++++---- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index df89831fb1..82b956d9e0 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -7,6 +7,7 @@ CAVEATS / POTENTIALLY BREAKING CHANGES Core Grammars: +- fix(rust) - adds emoji support in single quote strings [joshgoebel][] - fix(apache) - support line continuation via `\` [Josh Goebel][] - fix(makefile) - allow strings inside `$()` expressions [aneesh98][] - enh(arcade) updated to ArcGIS Arcade version 1.29 [Kristian Ekenes][] diff --git a/src/languages/rust.js b/src/languages/rust.js index d0e36fa6bf..7c88d6045b 100644 --- a/src/languages/rust.js +++ b/src/languages/rust.js @@ -199,10 +199,19 @@ export default function(hljs) { illegal: null }), { - className: 'string', + scope: 'string', variants: [ { begin: /b?r(#*)"(.|\n)*?"\1(?!#)/ }, - { begin: /b?'\\?(x\w{2}|u\w{4}|U\w{8}|.)'/ } + { + begin: /b?'/, + end: /'/, + contains: [ + { + scope: "char.escape", + match: /\\(\w|x\w{2}|u\w{4}|U\w{8})/ + } + ] + } ] }, { diff --git a/test/markup/rust/strings.expect.txt b/test/markup/rust/strings.expect.txt index 030300a5c0..ceff4aeff9 100644 --- a/test/markup/rust/strings.expect.txt +++ b/test/markup/rust/strings.expect.txt @@ -1,8 +1,8 @@ 'a'; -'\n'; -'\x1A'; -'\u12AS'; -'\U1234ASDF'; +'\n'; +'\x1A'; +'\u12AS'; +'\U1234ASDF'; b'a'; "hello";