Skip to content

Synchronize syntax with sublime hq. #431

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 22 commits into from
Dec 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
d40037d
[Rust] Improve punctuation scoping for , and ;
wbond Dec 16, 2016
1e332e7
[Rust] improved comment scoping
keith-hall Mar 8, 2017
ed5f313
[Rust] scope simple string line continuation characters
keith-hall Mar 8, 2017
9810a61
[Rust] Patch for catastrophic backtracking (#798)
trishume Apr 5, 2017
a3e21a6
Add tests for tuple types in parameters.
ehuss Feb 14, 2020
fbda350
Add test for -> in type path in return.
ehuss Feb 14, 2020
c1184d8
[Rust] Migrate punctuation.definition to punctuation.section as outli…
wbond Apr 5, 2017
cfd004b
[Rust] Update attributes to use standardized annotation scopes
wbond Apr 5, 2017
dddd271
[Rust] Add punctuation.accessor scopes
wbond Apr 5, 2017
65c6717
[Rust] fix nested array template arguments
keith-hall Dec 20, 2017
7e931b5
[Rust] add punctuation accessor dot scope
keith-hall Dec 20, 2017
e38dab5
[Rust] scope punctuation accessor dot after a function call
keith-hall Dec 20, 2017
a538934
[Rust] support paths to constants for sizes in nested array types (#1…
keith-hall Nov 28, 2018
92e94c0
[Rust] scope support types in generics (#1820)
keith-hall Jan 7, 2019
863667c
[Rust] Refine operator matches (for ligatures) (#1846)
FichteFoll Feb 4, 2019
7aec4e3
[Rust] Fix raw string punctuation (#1847)
FichteFoll Feb 4, 2019
46d3851
[Rust] Add scope to leading asterisk on each line in multiline commen…
DavidW1024 Jul 31, 2019
b8e3392
Add missing meta.block for tuple types.
ehuss Mar 1, 2020
d73c919
Add missing meta.block for enum body.
ehuss Mar 1, 2020
42e25e3
Add some clarifying comments to syntax definition.
ehuss Mar 1, 2020
c6a52fd
Syntax: Fix `+` in where clause, and `;` in trait functions.
ehuss May 10, 2020
1aff33a
Syntax: Fix issues from code review.
ehuss May 18, 2020
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
296 changes: 217 additions & 79 deletions RustEnhanced.sublime-syntax

Large diffs are not rendered by default.

117 changes: 99 additions & 18 deletions tests/syntax-rust/syntax_test_attributes.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,39 @@
// SYNTAX TEST "Packages/Rust Enhanced/RustEnhanced.sublime-syntax"

#![warn(unused)]
// <- meta.annotation
// <- meta.annotation punctuation.definition.annotation
//^^^^^^^^^^^^^^ meta.annotation
// ^^^^ support.function
// ^ meta.group punctuation.definition.group.begin
// ^^^^^^ meta.group
// ^ meta.group punctuation.definition.group.end
//^ punctuation.section.group.begin
// ^^^^ variable.annotation
// ^^^^^^^^ meta.annotation.parameters meta.group
// ^ punctuation.section.group.begin
// ^ punctuation.section.group.end
// ^ punctuation.section.group.end

#[macro_use]
// <- meta.annotation
//^^^^^^^^^^ meta.annotation
# [ macro_use ]
//^^^^^^^^^^^^^^^ meta.annotation
//^ punctuation.definition.annotation
// ^ punctuation.section.group.begin
// ^^^^^^^^^ variable.annotation
// ^ punctuation.section.group.end

#[cfg(all(unix, not(target_os = "haiku")))]
// <- meta.annotation
// <- meta.annotation punctuation.definition.annotation
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.annotation
//^^^ support.function
// ^^^ meta.group support.function
// ^^^^^^ meta.group meta.group
// ^^^ meta.group meta.group support.function
// ^^^^^^^^^^ meta.group meta.group meta.group
// ^ meta.group meta.group meta.group keyword.operator
// ^^^^^^^ meta.group meta.group meta.group string.quoted.double
//^^^ variable.annotation
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.annotation.parameters meta.group
// ^ punctuation.section.group.begin
// ^^^ meta.function-call variable.function
// ^ meta.annotation.parameters meta.group meta.function-call meta.group punctuation.section.group.begin
// ^ punctuation.separator
// ^^^ meta.function-call meta.function-call variable.function
// ^ punctuation.section.group.begin
// ^ keyword.operator.assignment
// ^^^^^^^ string.quoted.double
// ^ punctuation.section.group.end
// ^ punctuation.section.group.end
// ^ punctuation.section.group.end
// ^ punctuation.section.group.end

// Test highlighting/scope with struct field attributes
// https://github.com/rust-lang/sublime-rust/issues/120
Expand All @@ -35,7 +47,7 @@ pub struct Claim {
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.annotation
pub referring: Option<String>,
#[serde(skip_serializing_if="Option::is_none")]
// ^^^^^ support.function
// ^^^^^ variable.annotation
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.annotation
pub drug: Option<Vec<String>>,
#[serde(skip_serializing_if="Option::is_none")]
Expand All @@ -50,7 +62,7 @@ pub struct Claim {
enum E {
#[allow(dead_code)]
// ^^^^^^^^^^^^^^^^^^^ meta.enum meta.annotation
// ^^^^^ support.function
// ^^^^^ variable.annotation
A(i32),
// ^^^ meta.enum meta.struct meta.group storage.type
}
Expand All @@ -59,3 +71,72 @@ enum E {
unsafe impl<#[may_dangle] T: ?Sized> Drop for Box<T> { }
// ^^^^^^^^^^^^^ meta.annotation
// ^^^^^^^^^^^^^^^^^^^^^^^^^ meta.impl meta.generic

#[test = "foo ] bar"]
//^^^^^^^^^^^^^^^^^^^^^ meta.annotation
//^ punctuation.definition.annotation
// ^ punctuation.section.group.begin
// ^^^^ variable.annotation
// ^ keyword.operator.assignment
// ^^^^^^^^^^^ string.quoted.double
// ^ punctuation.section.group.end

// All the things.
# ! [
//^^^^^^ meta.annotation
//^ punctuation.definition.annotation
// ^ punctuation.definition.annotation
// ^ punctuation.section.group.begin
// comment
// ^^^^^^^^^^^ comment.line.double-slash
attr_name (
// ^^^^^^^^^ variable.annotation
// ^ meta.annotation.parameters meta.group punctuation.section.group.begin
// comment
// ^^^^^^^^^^^ comment.line.double-slash
"string",
// ^^^^^^^^ string.quoted.double
// ^ punctuation.separator
r##"raw"##,
// ^^^^^^^^^^ string.quoted.double.raw
b"bytes",
// ^ storage.type.string
// ^^^^^^^^ string.quoted.double
br"raw byte",
// ^^^^^^^^^^^^ string.quoted.double.raw
'c',
// ^^^ string.quoted.single
b'c',
// ^^^^ string.quoted.single
1_000,
// ^^^^^ constant.numeric.integer.decimal
1.618,
// ^^^^^ constant.numeric.float
true,
// ^^^^ constant.language
struct,
// ^^^^^^ storage.type.struct
1 + 1,
// ^ constant.numeric.integer.decimal
// ^ keyword.operator.arithmetic
// ^ constant.numeric.integer.decimal
)
// ^ punctuation.section.group.end
]
//^ punctuation.section.group.end

// quote! uses #var syntax
#[doc=#foo]
//^^^^^^^^^ meta.annotation
// ^ keyword.operator.assignment

// Macros often use replacement.
#[doc = $doc]
//^^^^^^^^^^^ meta.annotation
// ^ punctuation.section.group.end
// ^ keyword.operator.assignment

#[rustfmt::skip]
//^^^^^^^^^^^^^^ meta.annotation
//^^^^^^^^^^^^^ meta.path
// ^^^^ variable.annotation
40 changes: 29 additions & 11 deletions tests/syntax-rust/syntax_test_closures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,48 @@ let inferred_closure = |i, j: u32| i + 1;
// ^^^^^^^^^^^^^^^^ entity.name.function
// ^^^^^^^^^^^^^^^^^ meta.function.closure
// ^^^^^^^^^^^ meta.function.parameters
// ^ punctuation.definition.parameters.begin
// ^ punctuation.section.parameters.begin
// ^ variable.parameter
// ^ punctuation.separator
// ^ variable.parameter
// ^ punctuation.separator
// ^^^ storage.type
// ^ punctuation.definition.parameters.end
// ^ punctuation.section.parameters.end
let closure = || -> i32 { | | 1 + 2 };
// ^^^^^^^ entity.name.function
// ^^^^^^^^^^^^^^^^^^^^^^^ meta.function.closure
// ^^ meta.function.parameters
// ^ punctuation.definition.parameters.begin
// ^ punctuation.definition.parameters.end
// ^ punctuation.section.parameters.begin
// ^ punctuation.section.parameters.end
// ^^^ storage.type
// ^^^^^^^^^^^^^ meta.block
// ^ meta.block punctuation.definition.block.begin
// ^ meta.block punctuation.section.block.begin
// ^ constant.numeric.integer.decimal
// ^ constant.numeric.integer.decimal
// ^ meta.block punctuation.definition.block.end
// ^ meta.block punctuation.section.block.end

// Make sure "or" is not confused with closure.
let c = a | b;
// ^ keyword.operator
// ^ keyword.operator.bitwise

call_func(|c| 1 + 2 + c);
// ^^^^^^^^^^^^^ meta.function.closure
// ^^^ meta.function.parameters

fn lambdas() {
let c = |foo,
// ^ meta.function.closure meta.function.parameters punctuation.definition.parameters.begin
// ^ meta.function.closure meta.function.parameters punctuation.section.parameters.begin
// ^^^ meta.function.parameters variable.parameter
bar| {};
// ^^^ meta.function.parameters variable.parameter
// ^ meta.function.closure meta.function.parameters punctuation.definition.parameters.end
// ^ meta.function.closure meta.function.parameters punctuation.section.parameters.end
let c = |foo, // weird, but should work
// ^ meta.function.closure meta.function.parameters punctuation.definition.parameters.begin
// ^ meta.function.closure meta.function.parameters punctuation.section.parameters.begin
// ^^^ meta.function.parameters variable.parameter
// ^^^^^^^^^^^^^^^^^^^^^^^^^ comment.line
bar| {};
// ^^^ meta.function.parameters variable.parameter
// ^ meta.function.closure meta.function.parameters punctuation.definition.parameters.end
// ^ meta.function.closure meta.function.parameters punctuation.section.parameters.end
}


Expand Down Expand Up @@ -179,3 +180,20 @@ let x = |/*comment*/(/*c*/a, [b/*c*/], S{/*c*/f: c})| {};
// ^^^^^^^^^^^ meta.block
// ^^^^^ comment.block
// ^ variable.parameter

let f = |(x, y): (u32, &mut u32)| { x + y };
// ^ punctuation.section.parameters.begin
// ^^^^^^ meta.group
// ^ variable.parameter
// ^ punctuation.separator
// ^ variable.parameter
// ^ punctuation.section.group.end
// ^ punctuation.separator
// ^ punctuation.section.group.begin
// ^^^ storage.type
// ^ punctuation.separator
// ^ keyword.operator
// ^^^ storage.modifier
// ^^^ storage.type
// ^ punctuation.section.group.end
// ^ punctuation.section.parameters.end
12 changes: 10 additions & 2 deletions tests/syntax-rust/syntax_test_comments.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
// SYNTAX TEST "Packages/Rust Enhanced/RustEnhanced.sublime-syntax"

// Line comments
// <- comment.line.double-slash
// <- comment.line.double-slash punctuation.definition.comment
// ^^^^^^^^^^^^^^ comment.line.double-slash

// <- -comment

/// Line doc comments
// <- comment.line.documentation
// ^^^^^^^^^^^^^ comment.line.documentation

/*!
// <- comment.block.documentation
// <- comment.block.documentation punctuation.definition.comment
// <- comment.block.documentation
//^ comment.block.documentation
Block doc comments
Expand All @@ -17,6 +20,11 @@ Block doc comments
// ^^^^^^^^^^^^^^^^^^ comment.block.documentation comment.block
*/

/**
*
// ^ comment.block.documentation punctuation.definition.comment
*/

// Verify comment is cleared.
mod a {}
// ^^^^^ -comment
Expand Down
33 changes: 17 additions & 16 deletions tests/syntax-rust/syntax_test_control_flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@ for i in 1..10 {
// <- keyword.control
// ^^ keyword.operator
// ^ constant.numeric.integer.decimal
// ^^ keyword.operator
// ^^ keyword.operator.range
// ^^ constant.numeric.integer.decimal
println!("I: {}", i);
// ^^^^^^^^^^^^^^^^^^^^^^ meta.block
}
// <- meta.block punctuation.definition.block.end
// <- meta.block punctuation.section.block.end

'label_name: loop {
// ^^^^^^^^ entity.name.label
// ^ punctuation.separator
// ^^^^ keyword.control
// ^ meta.block punctuation.definition.block.begin
// ^ meta.block punctuation.section.block.begin
n += 1;
if n / 2 == 5 {
// ^ keyword.operator
// ^ keyword.operator.arithmetic
continue;
// ^^^^^^^^ keyword.control
}
Expand Down Expand Up @@ -51,45 +51,46 @@ for i in 1..10 {
}

if n < 0 {
// ^ meta.block punctuation.definition.block.begin
// ^ meta.block punctuation.section.block.begin
// <- keyword.control
print!("{} is negative", n);
// ^ punctuation.terminator
} else if n > 0 {
// <- meta.block punctuation.definition.block.end
// <- meta.block punctuation.section.block.end
// ^^^ keyword.control
// ^ meta.block punctuation.definition.block.begin
// ^ meta.block punctuation.section.block.begin
// ^^ keyword.control
print!("{0} is positive", n);
} else {
// <- meta.block punctuation.definition.block.end
// <- meta.block punctuation.section.block.end
// ^^^ keyword.control
// ^ meta.block punctuation.definition.block.begin
// ^ meta.block punctuation.section.block.begin
print!("{} is zero", n);
// ^^^^^^^^^^^^^^^^^^^^^^^^^ meta.block
}
// <- meta.block punctuation.definition.block.end
// <- meta.block punctuation.section.block.end

if let BasicStruct(i) = j {
// ^^^ storage.type
// ^ keyword.operator
// ^ meta.block punctuation.definition.block.begin
// ^ keyword.operator.assignment
// ^ meta.block punctuation.section.block.begin
println!("Basic value: {}", i);
}
// <- meta.block punctuation.definition.block.end
// <- meta.block punctuation.section.block.end

while let BasicStruct(k) = j {
//^^^ keyword.control
// ^^^ storage.type
// ^ keyword.operator
// ^ meta.block punctuation.definition.block.begin
// ^ keyword.operator.assignment
// ^ meta.block punctuation.section.block.begin
println!("Constructed example: {}", j)
j = BasicStruct(j + 1);
if k > 20 {
break;
//^^^ meta.block meta.block keyword.control
}
}
// <- meta.block punctuation.definition.block.end
// <- meta.block punctuation.section.block.end

continue_running();
//^^^^^^^^^^^^^^ support.function
Expand Down
10 changes: 5 additions & 5 deletions tests/syntax-rust/syntax_test_enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ enum OperatingSystem
// ^^^^^^^^^^^^^^^^^ meta.enum
// ^^^^^^^^^^^^^^^ entity.name.enum
{
// <- meta.enum punctuation.definition.block.begin
// <- meta.block meta.enum punctuation.section.block.begin
Osx,
// ^^^ meta.enum storage.type.source
Windows,
Linux,
Bsd(String),
// ^^^^^^ support.type
Info { field: i32, value: str }
// ^ punctuation.definition.block.begin
// ^ punctuation.section.block.begin
// ^^^ storage.type
// ^^^ storage.type
// ^ meta.block punctuation.definition.block.end
// ^ meta.block punctuation.section.block.end
}
// <- meta.enum punctuation.definition.block.end
// <- meta.block meta.enum punctuation.section.block.end

let q = Message::Quit;
// ^^^^^^^ storage.type.source
Expand Down Expand Up @@ -51,7 +51,7 @@ enum Discriminant {
// ^^ meta.enum constant.other
// ^^^^^^ meta.enum meta.group
// ^ constant.numeric.integer.decimal
// ^^ keyword.operator
// ^^ keyword.operator.bitwise
// ^ constant.numeric.integer.decimal
lowercase,
// ^^^^^^^^^^^ meta.enum
Expand Down
Loading