Skip to content

Commit 1422f25

Browse files
authored
Merge pull request #522 from ehuss/c-string-lit-more
C-string literal updates
2 parents 6e60055 + 519ecda commit 1422f25

File tree

2 files changed

+27
-18
lines changed

2 files changed

+27
-18
lines changed

RustEnhanced.sublime-syntax

+15-15
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ variables:
1212
identifier: '(?:(?:(?:r\#)?{{non_raw_ident}})\b)'
1313
camel_ident: '\b_*[A-Z][a-zA-Z0-9_]*[a-z][a-zA-Z0-9_]*\b'
1414
lifetime: '''(?:_|{{non_raw_ident}})(?!\'')\b'
15-
escaped_byte: '\\([nrt0\"''\\]|x\h{2})'
1615
escaped_char: '\\([nrt0\"''\\]|x[0-7]\h|u\{(?:\h_*){1,6}\})'
1716
int_suffixes: '[iu](?:8|16|32|64|128|size)'
1817
float_suffixes: 'f(32|64)'
@@ -1249,8 +1248,7 @@ contexts:
12491248
# not valid syntax.
12501249
- match: '\n'
12511250
pop: true
1252-
- match: '{{escaped_byte}}'
1253-
scope: constant.character.escape.rust
1251+
- include: escaped-byte
12541252
set: byte-tail
12551253
- match: ''
12561254
set: byte-tail
@@ -1275,10 +1273,8 @@ contexts:
12751273
- match: '"'
12761274
scope: punctuation.definition.string.end.rust
12771275
pop: true
1278-
- match: '{{escaped_byte}}'
1279-
scope: constant.character.escape.rust
1280-
- match: '(\\)$'
1281-
scope: punctuation.separator.continuation.line.rust
1276+
- include: escaped-byte
1277+
- include: line-continuation
12821278
- match: '\\.'
12831279
scope: invalid.illegal.character.escape.rust
12841280

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

1293+
line-continuation:
1294+
- match: '\\$'
1295+
scope: punctuation.separator.continuation.line.rust
1296+
1297+
escaped-byte:
1298+
- match: '\\([nrt0\"''\\]|x\h{2})'
1299+
scope: constant.character.escape.rust
1300+
12971301
escaped-char:
12981302
- match: '{{escaped_char}}'
12991303
scope: constant.character.escape.rust
@@ -1338,8 +1342,7 @@ contexts:
13381342
scope: punctuation.definition.string.end.rust
13391343
pop: true
13401344
- include: escaped-char
1341-
- match: '(\\)$'
1342-
scope: punctuation.separator.continuation.line.rust
1345+
- include: line-continuation
13431346

13441347
raw-string:
13451348
- match: (r)((#*)")
@@ -1364,10 +1367,8 @@ contexts:
13641367
- match: '"'
13651368
scope: punctuation.definition.string.end.rust
13661369
pop: true
1367-
- match: '{{escaped_byte}}'
1368-
scope: constant.character.escape.rust
1369-
- match: '(\\)$'
1370-
scope: punctuation.separator.continuation.line.rust
1370+
- include: escaped-byte
1371+
- include: line-continuation
13711372
- include: escaped-char
13721373

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

13991399
format-raw-string:
14001400
- match: (r)(#*)"

tests/syntax-rust/syntax_test_literals.rs

+12-3
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,16 @@ let cstr_empty = c"";
175175
let cstr_unicode = c"æ";
176176
// ^ string.quoted.double storage.type.string
177177
// ^^^^ string.quoted.double
178-
let cstr_byte_escape = c"\xFF\xC3\xA6";
178+
let cstr_byte_escape = c"\xFF\xC3\xA6\n\r\t\0\"\'\\";
179179
// ^ storage.type.string
180-
// ^^^^^^^^^^^^^^^ string.quoted.double
181-
// ^^^^^^^^^^^^ constant.character.escape
180+
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.double
181+
// ^^^^^^^^^^^^^^^^^^^^^^^^^^ constant.character.escape
182+
let cstr_byte_escape_invalid = c"\a";
183+
// ^^^^^ string.quoted.double
184+
// ^ storage.type.string
185+
// ^ punctuation.definition.string.begin
186+
// ^^ invalid.illegal.character.escape
187+
// ^ punctuation.definition.string.end
182188
let cstr_unicode_escape = c"\u{00E6}";
183189
// ^^^^^^^^^^^ string.quoted.double
184190
// ^^^^^^^^ constant.character.escape
@@ -205,6 +211,9 @@ let raw_cstr_multiline = cr##"
205211
This text has "multiple lines"
206212
"##;
207213
// ^^ string.quoted.double.raw punctuation.definition.string.end
214+
let raw_cstr_escape_ignore = cr"\n\x01\u{0123}\";
215+
// ^^^^^^^^^^^^^^^^^^^ string.quoted.double.raw
216+
// ^^^^^^^^^^^^^^^ -constant.character.escape
208217

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

0 commit comments

Comments
 (0)