From bf27c55563994a634b76b6f78afcf538a8b89839 Mon Sep 17 00:00:00 2001 From: pommicket Date: Wed, 17 Jul 2024 23:12:30 -0700 Subject: fix highlighting of '\u{1023}' in Rust --- syntax.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'syntax.c') diff --git a/syntax.c b/syntax.c index e68797a..956f653 100644 --- a/syntax.c +++ b/syntax.c @@ -596,14 +596,31 @@ static void syntax_highlight_rust(SyntaxState *state, const char32_t *line, u32 if (line[char_end] == '\'' && backslashes % 2 == 0) { break; } + if (backslashes % 2 == 1 && line[char_end] == 'u' + && char_end + 3 < line_len && line[char_end + 1] == '{') { + // unicode character literal e.g. '\u{1234}' + char_end += 2; // skip u{ + while (char_end + 1 < line_len) { + char_end++; + if (line[char_end] == '}') { + char_end++; + break; + } + } + if (line[char_end - 1] != '}') { + // not a unicode character + char_end = line_len; + } + break; + } + if (line[char_end] < CHAR_MAX + && backslashes % 2 == 0 + && !strchr("abcdefABCDEF0123456789", (char)line[char_end])) + break; if (line[char_end] == '\\') ++backslashes; else backslashes = 0; - if (line[char_end] < CHAR_MAX - && line[char_end - 1] != '\\' - && !strchr("abcdefABCDEF0123456789", (char)line[char_end])) - break; } if (char_end < line_len && line[char_end] == '\'') { // a character literal -- cgit v1.2.3