Skip to content
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

[Rust] Add C-string literals #3882

Merged
merged 4 commits into from
Dec 9, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
31 changes: 31 additions & 0 deletions Rust/Rust.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -1269,6 +1269,8 @@ contexts:
- include: raw-byte-string
- include: string
- include: raw-string
- include: c-string
- include: raw-c-string

chars:
- include: char
Expand Down Expand Up @@ -1393,6 +1395,35 @@ contexts:
scope: punctuation.definition.string.end.rust
pop: true

c-string:
- match: '(c)(")'
captures:
1: storage.type.string.rust
deathaxe marked this conversation as resolved.
Show resolved Hide resolved
2: punctuation.definition.string.begin.rust
push:
- meta_include_prototype: false
- meta_scope: string.quoted.double.rust
- match: '"'
scope: punctuation.definition.string.end.rust
pop: true
- match: '{{escaped_byte}}'
scope: constant.character.escape.rust
- match: '(\\)$'
deathaxe marked this conversation as resolved.
Show resolved Hide resolved
scope: punctuation.separator.continuation.line.rust
- include: escaped-char
michaelblyons marked this conversation as resolved.
Show resolved Hide resolved

raw-c-string:
- match: (cr)((#*)")
captures:
1: storage.type.string.rust
2: punctuation.definition.string.begin.rust
push:
- meta_include_prototype: false
- meta_scope: string.quoted.double.raw.rust
- match: '"\3'
scope: punctuation.definition.string.end.rust
pop: true

format-string:
- match: '"'
scope: punctuation.definition.string.begin.rust
Expand Down
40 changes: 40 additions & 0 deletions Rust/tests/syntax_test_literals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,46 @@ let s_uni_esc_under3 = "\u{10__FFFF}";
let s_uni_esc_extra = "\u{1234567}";
// ^^^^^^^^^^^ string.quoted.double invalid.illegal.character.escape

let cstr_empty = c"";
// ^ string.quoted.double storage.type.string
// ^^^ string.quoted.double
// ^ punctuation.definition.string.begin
// ^ punctuation.definition.string.end
// ^ punctuation.terminator
let cstr_unicode = c"æ";
// ^ string.quoted.double storage.type.string
// ^^^^ string.quoted.double
let cstr_byte_escape = c"\xFF\xC3\xA6";
// ^ storage.type.string
// ^^^^^^^^^^^^^^^ string.quoted.double
// ^^^^^^^^^^^^ constant.character.escape
let cstr_unicode_escape = c"\u{00E6}";
// ^^^^^^^^^^^ string.quoted.double
// ^^^^^^^^ constant.character.escape
let cstr_continue = c"\
\xFF";
// ^^^^ string.quoted.double constant.character.escape

let raw_cstr_empty = cr"";
// ^^^^ string.quoted.double.raw
// ^^ storage.type.string
// ^ punctuation.definition.string.begin
// ^ punctuation.definition.string.end
let raw_cstr_unicode = cr"東京";
// ^^^^^^ string.quoted.double.raw
// ^^ storage.type.string
let raw_cstr_hash = cr#"text with "quote" in it."#;
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.double.raw
// ^^ storage.type.string
// ^^ punctuation.definition.string.begin
// ^^ punctuation.definition.string.end
let raw_cstr_multiline = cr##"
// ^^ string.quoted.double.raw storage.type.string
// ^^^^^^ string.quoted.double.raw
This text has "multiple lines"
"##;
// ^^ string.quoted.double.raw punctuation.definition.string.end

0;
// <- constant.numeric.integer.decimal
1_000u32;
Expand Down