Skip to content

Commit

Permalink
[Rust] Refine scopes of variable declaration keywords
Browse files Browse the repository at this point in the history
  • Loading branch information
FichteFoll committed Jan 31, 2024
1 parent 7f7708c commit 8125ea5
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 25 deletions.
19 changes: 12 additions & 7 deletions Rust/Rust.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -176,20 +176,20 @@ contexts:

- match: '\b(const)\s+({{identifier}})'
captures:
1: keyword.declaration.rust
1: keyword.declaration.variable.constant.rust
2: entity.name.constant.rust
push: declaration-after-identifier

- match: '\b(static)\s+(?:(mut)\s+)?({{identifier}})'
captures:
1: keyword.declaration.rust
1: keyword.declaration.variable.static.rust
2: storage.modifier.rust
3: entity.name.constant.rust
push: declaration-after-identifier

- match: \b(let)\s+(?:(mut)\s+)?
captures:
1: keyword.declaration.rust
1: keyword.declaration.variable.rust
2: storage.modifier.rust
push: declaration-identifier

Expand Down Expand Up @@ -1739,15 +1739,20 @@ contexts:
scope: storage.modifier.rust

keywords:
# All keywords. Note in `statements` some of these are superseded by more
# All keywords. Note in `statements` most of these are superseded by more
# specific rules.
- include: bool

- match: \b(let|static)\b
scope: keyword.declaration.rust
- match: \blet\b
scope: keyword.declaration.variable.rust

- match: \bstatic\b
scope: keyword.declaration.variable.static.rust

- match: \bconst\b
scope: storage.type.rust
# The storage keyword seems more likely to not have been matched earlier.
scope: storage.modifier.rust
# scope: keyword.declaration.variable.constant.rust

- match: \bfn\b
scope: keyword.declaration.function.rust
Expand Down
4 changes: 2 additions & 2 deletions Rust/tests/syntax_test_control_flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ if n < 0 {
// <- meta.block punctuation.section.block.end

if let BasicStruct(i) = j {
// ^^^ keyword.declaration
// ^^^ keyword.declaration.variable.rust
// ^ keyword.operator.assignment
// ^ meta.block punctuation.section.block.begin
println!("Basic value: {}", i);
Expand All @@ -80,7 +80,7 @@ if let BasicStruct(i) = j {

while let BasicStruct(k) = j {
//^^^ keyword.control
// ^^^ keyword.declaration
// ^^^ keyword.declaration.variable.rust
// ^ keyword.operator.assignment
// ^ meta.block punctuation.section.block.begin
println!("Constructed example: {}", j)
Expand Down
6 changes: 3 additions & 3 deletions Rust/tests/syntax_test_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
// specific categories.

let big_n =
// <- keyword.declaration
// <- keyword.declaration
//^ keyword.declaration
// <- keyword.declaration.variable.rust
// <- keyword.declaration.variable.rust
//^ keyword.declaration.variable.rust
// ^ keyword.operator.assignment
if n < 10 && n > -10 {
// ^ keyword.operator.comparison
Expand Down
12 changes: 6 additions & 6 deletions Rust/tests/syntax_test_literals.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
// SYNTAX TEST "Packages/Rust/Rust.sublime-syntax"

let c = 'c';
// <- keyword.declaration
// <- keyword.declaration.variable.rust
// ^ keyword.operator.assignment
// ^^^ string.quoted.single
let b = b'c';
// <- keyword.declaration
// <- keyword.declaration.variable.rust
// ^ keyword.operator.assignment
// ^ storage.type
// ^^^ string.quoted.single
let ch = '∞';
// ^^^ string.quoted.single

let s = "This is a string \x01_\u{007F}_\"_\'_\\_\r_\n_\t_\0";
// <- keyword.declaration
// <- keyword.declaration.variable.rust
// ^ keyword.operator.assignment
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.double
// ^^^^ constant.character.escape
Expand All @@ -26,7 +26,7 @@ let s = "This is a string \x01_\u{007F}_\"_\'_\\_\r_\n_\t_\0";
// ^^ constant.character.escape
// ^^ constant.character.escape
let r = r##"This is a raw string, no escapes! \x00 \0 \n"##;
// <- keyword.declaration
// <- keyword.declaration.variable.rust
// ^ keyword.operator.assignment
// ^ storage.type
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.double.raw - constant.character.escape
Expand All @@ -46,7 +46,7 @@ println!("Continuation in format \
");

let bytes = b"This won't escape unicode \u{0123}, but will do \x01_\"_\'_\\_\r_\n_\t_\0";
// <- keyword.declaration
// <- keyword.declaration.variable.rust
// ^ keyword.operator.assignment
// ^ storage.type
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.double
Expand All @@ -60,7 +60,7 @@ let bytes = b"This won't escape unicode \u{0123}, but will do \x01_\"_\'_\\_\r_\
// ^^ constant.character.escape

let raw_bytes = br#"This won't escape anything either \x01 \""#;
// <- keyword.declaration
// <- keyword.declaration.variable.rust
// ^ keyword.operator.assignment
// ^^ storage.type
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.double - constant.character.escape
Expand Down
10 changes: 5 additions & 5 deletions Rust/tests/syntax_test_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,22 @@ type GenFnPointer2 = Bar<extern "C" fn()>;
// ^ - meta.generic

const ZERO: u64 = 0;
// <- keyword.declaration
// <- keyword.declaration.variable.constant.rust
// ^^^^ entity.name.constant
// ^ punctuation.separator
// ^^^ storage.type
// ^ keyword.operator.assignment
// ^ constant.numeric.integer.decimal
static NAME: &'static str = "John";
// <- keyword.declaration
// <- keyword.declaration.variable.static.rust
// ^^^^ entity.name.constant
// ^ keyword.operator
// ^^^^^^^ storage.modifier.lifetime
// ^^^ storage.type
// ^ keyword.operator.assignment
// ^^^^^^ string.quoted.double
static mut BRAVO: u32 = 0;
// <- keyword.declaration
// <- keyword.declaration.variable.static.rust
// ^^^ storage.modifier
// ^^^^^ entity.name.constant

Expand All @@ -65,7 +65,7 @@ fn factory() -> Box<Fn(i32) -> i32> {
}

let x: __m128i = __m128i::from_bits(f32x4::from_bits(m32x4::new(true, true, true, true)));
// <- keyword.declaration
// <- keyword.declaration.variable.rust
// ^^^^^^^ storage.type
// ^^^^^^^ storage.type
// ^^^^^ meta.group storage.type
Expand Down Expand Up @@ -94,7 +94,7 @@ type Pair<'a> = (i32, &'a str);
// ^ punctuation.terminator

let p: Pair<'static> = (10, "ten");
// <- keyword.declaration
// <- keyword.declaration.variable.rust
// ^ punctuation.separator
// ^^^^^^^^^ meta.generic
// ^ punctuation.definition.generic.begin
Expand Down
4 changes: 2 additions & 2 deletions Rust/tests/syntax_test_visibility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ pub ( in self ) enum E {A,B}
pub ( in super ) const CONST: i32 = 1;
// ^^ keyword.other
// ^^^^^ keyword.other
// ^^^^^ keyword.declaration
// ^^^^^ keyword.declaration.variable.constant.rust
pub ( in super::super ) static STATIC: i32 = 1;
// ^^ keyword.other
// ^^^^^ keyword.other
// ^^ meta.path
// ^^^^^ keyword.other
// ^^^^^^ keyword.declaration
// ^^^^^^ keyword.declaration.variable.static.rust

struct S {
pub f1: i32,
Expand Down

0 comments on commit 8125ea5

Please sign in to comment.