Skip to content

C-string literal updates #522

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions RustEnhanced.sublime-syntax
Original file line number Diff line number Diff line change
@@ -12,7 +12,6 @@ variables:
identifier: '(?:(?:(?:r\#)?{{non_raw_ident}})\b)'
camel_ident: '\b_*[A-Z][a-zA-Z0-9_]*[a-z][a-zA-Z0-9_]*\b'
lifetime: '''(?:_|{{non_raw_ident}})(?!\'')\b'
escaped_byte: '\\([nrt0\"''\\]|x\h{2})'
escaped_char: '\\([nrt0\"''\\]|x[0-7]\h|u\{(?:\h_*){1,6}\})'
int_suffixes: '[iu](?:8|16|32|64|128|size)'
float_suffixes: 'f(32|64)'
@@ -1249,8 +1248,7 @@ contexts:
# not valid syntax.
- match: '\n'
pop: true
- match: '{{escaped_byte}}'
scope: constant.character.escape.rust
- include: escaped-byte
set: byte-tail
- match: ''
set: byte-tail
@@ -1275,10 +1273,8 @@ contexts:
- match: '"'
scope: punctuation.definition.string.end.rust
pop: true
- match: '{{escaped_byte}}'
scope: constant.character.escape.rust
- match: '(\\)$'
scope: punctuation.separator.continuation.line.rust
- include: escaped-byte
- include: line-continuation
- match: '\\.'
scope: invalid.illegal.character.escape.rust

@@ -1294,6 +1290,14 @@ contexts:
scope: punctuation.definition.string.end.rust
pop: true

line-continuation:
- match: '\\$'
scope: punctuation.separator.continuation.line.rust

escaped-byte:
- match: '\\([nrt0\"''\\]|x\h{2})'
scope: constant.character.escape.rust

escaped-char:
- match: '{{escaped_char}}'
scope: constant.character.escape.rust
@@ -1338,8 +1342,7 @@ contexts:
scope: punctuation.definition.string.end.rust
pop: true
- include: escaped-char
- match: '(\\)$'
scope: punctuation.separator.continuation.line.rust
- include: line-continuation

raw-string:
- match: (r)((#*)")
@@ -1364,10 +1367,8 @@ contexts:
- match: '"'
scope: punctuation.definition.string.end.rust
pop: true
- match: '{{escaped_byte}}'
scope: constant.character.escape.rust
- match: '(\\)$'
scope: punctuation.separator.continuation.line.rust
- include: escaped-byte
- include: line-continuation
- include: escaped-char

raw-c-string:
@@ -1393,8 +1394,7 @@ contexts:
pop: true
- include: escaped-char
- include: format-escapes
- match: '(\\)$'
scope: punctuation.separator.continuation.line.rust
- include: line-continuation

format-raw-string:
- match: (r)(#*)"
15 changes: 12 additions & 3 deletions tests/syntax-rust/syntax_test_literals.rs
Original file line number Diff line number Diff line change
@@ -175,10 +175,16 @@ let cstr_empty = c"";
let cstr_unicode = c"æ";
// ^ string.quoted.double storage.type.string
// ^^^^ string.quoted.double
let cstr_byte_escape = c"\xFF\xC3\xA6";
let cstr_byte_escape = c"\xFF\xC3\xA6\n\r\t\0\"\'\\";
// ^ storage.type.string
// ^^^^^^^^^^^^^^^ string.quoted.double
// ^^^^^^^^^^^^ constant.character.escape
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.double
// ^^^^^^^^^^^^^^^^^^^^^^^^^^ constant.character.escape
let cstr_byte_escape_invalid = c"\a";
// ^^^^^ string.quoted.double
// ^ storage.type.string
// ^ punctuation.definition.string.begin
// ^^ invalid.illegal.character.escape
// ^ punctuation.definition.string.end
let cstr_unicode_escape = c"\u{00E6}";
// ^^^^^^^^^^^ string.quoted.double
// ^^^^^^^^ constant.character.escape
@@ -205,6 +211,9 @@ let raw_cstr_multiline = cr##"
This text has "multiple lines"
"##;
// ^^ string.quoted.double.raw punctuation.definition.string.end
let raw_cstr_escape_ignore = cr"\n\x01\u{0123}\";
// ^^^^^^^^^^^^^^^^^^^ string.quoted.double.raw
// ^^^^^^^^^^^^^^^ -constant.character.escape

0;
// <- constant.numeric.integer.decimal