From d40037d1e55d62e3b376b8d967d8672fb3b3e5bc Mon Sep 17 00:00:00 2001 From: wbond Date: Fri, 16 Dec 2016 10:18:08 -0500 Subject: [PATCH 01/22] [Rust] Improve punctuation scoping for , and ; --- RustEnhanced.sublime-syntax | 30 +++- tests/syntax-rust/syntax_test_control_flow.rs | 1 + tests/syntax-rust/syntax_test_expr.rs | 10 ++ tests/syntax-rust/syntax_test_modules.rs | 1 + tests/syntax-rust/syntax_test_punct.rs | 142 ++++++++++++++++++ tests/syntax-rust/syntax_test_types.rs | 1 + 6 files changed, 179 insertions(+), 6 deletions(-) create mode 100644 tests/syntax-rust/syntax_test_punct.rs diff --git a/RustEnhanced.sublime-syntax b/RustEnhanced.sublime-syntax index 90473c16..7ab5a5dc 100644 --- a/RustEnhanced.sublime-syntax +++ b/RustEnhanced.sublime-syntax @@ -49,7 +49,8 @@ contexts: push: - meta_scope: meta.module.rust - match: ';' - set: after-operator + scope: punctuation.terminator.rust + pop: true - include: statements-block - match: '\b({{identifier}})\s*(=)\s*(?=\|)' @@ -196,15 +197,23 @@ contexts: - match: '\]' scope: punctuation.definition.group.end.rust pop: true + - match: ';' + scope: punctuation.separator.rust - include: statements - include: return-type - include: symbols - include: keywords + - match: ',' + scope: punctuation.separator.rust + push: after-operator + + - match: '\b[[:lower:]_][[:lower:][:digit:]_]*(?=\()' scope: support.function.rust + - match: '{{identifier}}' visibility: @@ -385,6 +394,9 @@ contexts: pop: true - include: type-any-identifier + - match: ',' + scope: punctuation.separator.rust + closure: - meta_content_scope: meta.function.closure.rust - match: '\|' @@ -521,6 +533,8 @@ contexts: - match: '\)' scope: punctuation.definition.type.end.rust pop: true + - match: ',' + scope: punctuation.separator.rust - include: type-any-identifier - match: \bextern\b scope: keyword.other.rust @@ -608,6 +622,8 @@ contexts: - include: comments - include: visibility - include: type-any-identifier + - match: ',' + scope: punctuation.separator.rust struct-classic: - meta_scope: meta.struct.rust @@ -631,7 +647,10 @@ contexts: - match: '{{identifier}}(?=\s*:)' scope: variable.other.member.rust push: - - match: ',|(?=\})' + - match: ',' + scope: punctuation.separator.rust + pop: true + - match: '(?=\})' pop: true - include: comments - match: ':' @@ -721,6 +740,7 @@ contexts: - match: '(?=\})' pop: true - match: ',' + scope: punctuation.separator.rust pop: true - match: '=' set: enum-discriminant @@ -1036,7 +1056,7 @@ contexts: - match: \bwhere\b scope: keyword.other.rust - include: type-any-identifier - - match: ':' + - match: '[:,]' scope: punctuation.separator.rust - match: ';' pop: true @@ -1337,9 +1357,7 @@ contexts: - match: '=(?!=)' scope: keyword.operator.rust - - match: '[;,]' - - - match: ':' + - match: '[:;,]' scope: punctuation.separator.rust - match: '\.\.\.' diff --git a/tests/syntax-rust/syntax_test_control_flow.rs b/tests/syntax-rust/syntax_test_control_flow.rs index baeb9675..2857e4f3 100644 --- a/tests/syntax-rust/syntax_test_control_flow.rs +++ b/tests/syntax-rust/syntax_test_control_flow.rs @@ -54,6 +54,7 @@ if n < 0 { // ^ meta.block punctuation.definition.block.begin // <- keyword.control print!("{} is negative", n); +// ^ punctuation.terminator } else if n > 0 { // <- meta.block punctuation.definition.block.end // ^^^ keyword.control diff --git a/tests/syntax-rust/syntax_test_expr.rs b/tests/syntax-rust/syntax_test_expr.rs index cdebc415..3a9bc1de 100644 --- a/tests/syntax-rust/syntax_test_expr.rs +++ b/tests/syntax-rust/syntax_test_expr.rs @@ -41,6 +41,16 @@ let x = arr[1]; // ^ constant.numeric.integer.decimal // ^ punctuation.definition.group.end +// Array expression. +let x = [1; 2]; +// ^^^^^^ meta.group +// ^ punctuation.definition.group.begin +// ^ punctuation.separator +// ^ constant.numeric.integer.decimal +// ^ punctuation.terminator +let x = [1; SOME_CONST]; +// ^^^^^^^^^^ constant.other + // Borrow expression. let xsl = &xs; // ^ keyword.operator diff --git a/tests/syntax-rust/syntax_test_modules.rs b/tests/syntax-rust/syntax_test_modules.rs index 0a833135..9d4c21b5 100644 --- a/tests/syntax-rust/syntax_test_modules.rs +++ b/tests/syntax-rust/syntax_test_modules.rs @@ -19,6 +19,7 @@ mod bar; // <- meta.module storage.type.module //^^^^^^ meta.module // ^^^ entity.name.module +// ^ punctuation.terminator pub mod my_mod { // ^^^^^^^^^^^^ meta.module diff --git a/tests/syntax-rust/syntax_test_punct.rs b/tests/syntax-rust/syntax_test_punct.rs new file mode 100644 index 00000000..adadcadc --- /dev/null +++ b/tests/syntax-rust/syntax_test_punct.rs @@ -0,0 +1,142 @@ +// SYNTAX TEST "Packages/Rust Enhanced/RustEnhanced.sublime-syntax" +// Various usages of punctuation. + +/************* semicolon *************/ +; +// <- punctuation.terminator +let x = 1; +// ^ punctuation.terminator +[12; 34] +// ^ punctuation.separator +type T = [i32; 3]; +// ^ punctuation.separator +const X: i32 = 1; +// ^ punctuation.terminator +static Y: i32 = 1; +// ^ punctuation.terminator +extern "C" { + fn f(); +// ^ punctuation.terminator + static S: i32 = 1; +// ^ punctuation.terminator +} +trait T { + fn f(); +// ^ punctuation.terminator + const C: i32; +// ^ punctuation.terminator + type T; +// ^ punctuation.terminator +} +extern crate name; +// ^ punctuation.terminator +mod m; +// ^ punctuation.terminator +struct S; +// ^ punctuation.terminator +type T = i32; +// ^ punctuation.terminator +use foo; +// ^ punctuation.terminator + + +/************* colon *************/ +match v { + Point{x: 10, y: 20} => {} +// ^ punctuation.separator +// ^ punctuation.separator +} +let x: i32 = 1; +// ^ punctuation.separator +let c = |a: i32| {} +// ^ punctuation.separator +let s = Foo{x: 50}; +// ^ punctuation.separator +struct S { + f1: 1, +// ^ punctuation.separator +} +enum E { + Foo{x: i32}, +// ^ punctuation.separator +} +'label: +// ^ punctuation.separator +fn f<'a: 'b>(x: i32) where T: Bound {} +// ^ punctuation.separator +// ^ punctuation.separator +// ^ punctuation.separator +// See syntax_test_generics for more generics tests (all separator). +trait T: Bound { +// ^ punctuation.separator + type T: Bound; +// ^ punctuation.separator + const C: i32; +// ^ punctuation.separator + fn f(x: i32); +// ^ punctuation.separator +} +static S: i32 = 1; +// ^ punctuation.separator +const C: i32 = 1; +// ^ punctuation.separator +type T = fn(a: i32); +// ^ punctuation.separator + + +/************* comma *************/ +#[cfg(a, b)] +// ^ punctuation.separator +fn f() where A: B, C: D {} +// ^ punctuation.separator +// ^ punctuation.separator +X +// ^ punctuation.separator +type T = Box; +// ^ punctuation.separator +type T = fn(i32, i32); +// ^ punctuation.separator +type T = (i32, i32); +// ^ punctuation.separator +let S{f1, f2} = a; +// ^ punctuation.separator +let (a, b) = c; +// ^ punctuation.separator +let [a, b] = c; +// ^ punctuation.separator +let a = [1, 2]; +// ^ punctuation.separator +let x = (a, b); +// ^ punctuation.separator +foo(1, 2); +// ^ punctuation.separator +let a = |a, b| {}; +// ^ punctuation.separator +fn f(a: i32, b: i32) {} +// ^ punctuation.separator +struct S { + f1: i32, +// ^ punctuation.separator +} +struct S(i32, i32); +// ^ punctuation.separator +enum E { + Variant1, +// ^ punctuation.separator + Variant2{f1: i32,}, +// ^ punctuation.separator +// ^ punctuation.separator + Variant3(i32, i32), +// ^ punctuation.separator +// ^ punctuation.separator +} +Foo{f1: a,}; +// ^ punctuation.separator +Foo(a, b); +// ^ punctuation.separator +match a { + x => 1, +// ^ punctuation.separator +} +use a::{a,b}; +// ^ punctuation.separator diff --git a/tests/syntax-rust/syntax_test_types.rs b/tests/syntax-rust/syntax_test_types.rs index 26b8d462..08a884f3 100644 --- a/tests/syntax-rust/syntax_test_types.rs +++ b/tests/syntax-rust/syntax_test_types.rs @@ -109,6 +109,7 @@ let xs: [i32; 5] = [1, 2, 3, 4, 5]; // ^^^^^^^^ meta.group // ^ punctuation.definition.group.begin // ^^^ storage.type +// ^ punctuation.separator // ^ constant.numeric.integer.decimal // ^ punctuation.definition.group.end // ^^^^^^^^^^^^^^^ meta.group From 1e332e7aff16e75ef85aa4238f282e6cf5504a24 Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Wed, 8 Mar 2017 14:22:34 +0200 Subject: [PATCH 02/22] [Rust] improved comment scoping --- RustEnhanced.sublime-syntax | 6 ++++++ tests/syntax-rust/syntax_test_comments.rs | 7 +++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/RustEnhanced.sublime-syntax b/RustEnhanced.sublime-syntax index 7ab5a5dc..130d28ec 100644 --- a/RustEnhanced.sublime-syntax +++ b/RustEnhanced.sublime-syntax @@ -1086,11 +1086,13 @@ contexts: comments: - include: block-comments - match: "//[!/]" + scope: punctuation.definition.comment.rust push: - meta_scope: comment.line.documentation.rust - match: $\n? pop: true - match: // + scope: punctuation.definition.comment.rust push: - meta_scope: comment.line.double-slash.rust - match: $\n? @@ -1098,15 +1100,19 @@ contexts: block-comments: - match: '/\*[!\*][^\*/]' + scope: punctuation.definition.comment.rust push: - meta_scope: comment.block.documentation.rust - match: \*/ + scope: punctuation.definition.comment.rust pop: true - include: block-comments - match: /\* + scope: punctuation.definition.comment.rust push: - meta_scope: comment.block.rust - match: \*/ + scope: punctuation.definition.comment.rust pop: true - include: block-comments diff --git a/tests/syntax-rust/syntax_test_comments.rs b/tests/syntax-rust/syntax_test_comments.rs index 50262e11..0de2a4bf 100644 --- a/tests/syntax-rust/syntax_test_comments.rs +++ b/tests/syntax-rust/syntax_test_comments.rs @@ -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 From ed5f313ab1d74818e689001f6b1f573cfac7e35e Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Wed, 8 Mar 2017 21:57:14 +0200 Subject: [PATCH 03/22] [Rust] scope simple string line continuation characters https://doc.rust-lang.org/book/strings.html --- RustEnhanced.sublime-syntax | 6 ++++++ tests/syntax-rust/syntax_test_literals.rs | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/RustEnhanced.sublime-syntax b/RustEnhanced.sublime-syntax index 130d28ec..375e5d98 100644 --- a/RustEnhanced.sublime-syntax +++ b/RustEnhanced.sublime-syntax @@ -1169,6 +1169,8 @@ contexts: pop: true - match: '{{escaped_byte}}' scope: constant.character.escape.rust + - match: '(\\)$' + scope: punctuation.separator.continuation.line.rust - match: '\\.' scope: invalid.illegal.character.escape.rust @@ -1228,6 +1230,8 @@ contexts: scope: punctuation.definition.string.end.rust pop: true - include: escaped-char + - match: '(\\)$' + scope: punctuation.separator.continuation.line.rust raw-string: - match: (r)(#*)" @@ -1252,6 +1256,8 @@ contexts: pop: true - include: escaped-char - include: format-escapes + - match: '(\\)$' + scope: punctuation.separator.continuation.line.rust format-raw-string: - match: (r)(#*)" diff --git a/tests/syntax-rust/syntax_test_literals.rs b/tests/syntax-rust/syntax_test_literals.rs index c7ae52e2..8c1ae361 100644 --- a/tests/syntax-rust/syntax_test_literals.rs +++ b/tests/syntax-rust/syntax_test_literals.rs @@ -31,6 +31,18 @@ let r = r#"This is a raw string, no escapes! \x00 \0 \n"#; // ^ storage.type // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.double - constant.character.escape +let s = "\ +// ^ string.quoted.double punctuation.separator.continuation.line +continued \ +// ^ string.quoted.double punctuation.separator.continuation.line +line"; +let b = b"\ +// ^ punctuation.separator.continuation.line +"; +println!("Continuation in format \ +// ^ punctuation.separator.continuation.line +"); + let bytes = b"This won't escape unicode \u{0123}, but will do \x01_\"_\'_\\_\r_\n_\t_\0"; // <- storage.type // ^ keyword.operator From 9810a61984feaf4240d823c3a0b1fa8a0677397f Mon Sep 17 00:00:00 2001 From: Tristan Hume Date: Wed, 5 Apr 2017 09:22:28 -0400 Subject: [PATCH 04/22] [Rust] Patch for catastrophic backtracking (#798) Non-Sublime implementations of sublime-syntax that use Oniguruma take exponential time to parse `impl SomeIdentifier {` lines without this change --- RustEnhanced.sublime-syntax | 4 +++- tests/syntax-rust/syntax_test_misc.rs | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/RustEnhanced.sublime-syntax b/RustEnhanced.sublime-syntax index 375e5d98..38a0062b 100644 --- a/RustEnhanced.sublime-syntax +++ b/RustEnhanced.sublime-syntax @@ -7,7 +7,9 @@ file_extensions: scope: source.rust variables: non_raw_ident: '[[:alpha:]][_[:alnum:]]*|_[_[:alnum:]]+' - identifier: '(?:(?:r\#)?{{non_raw_ident}})' + # include a word boundary at the end to ensure all possible characters are + # consumed, to prevent catastrophic backtracking + 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})' diff --git a/tests/syntax-rust/syntax_test_misc.rs b/tests/syntax-rust/syntax_test_misc.rs index 1ba473f0..3261aebd 100644 --- a/tests/syntax-rust/syntax_test_misc.rs +++ b/tests/syntax-rust/syntax_test_misc.rs @@ -56,3 +56,8 @@ let y = future.await; // try keyword in 2018 edition let x = try {} // ^^^ keyword.control.rust + +// Performance test for catastrophic backtracking. +impl ApplicationPreferenceseeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee { +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ entity.name.impl +} From a3e21a663db1339fec757d4095f04da62f3e0963 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Fri, 14 Feb 2020 15:09:50 -0800 Subject: [PATCH 05/22] Add tests for tuple types in parameters. --- tests/syntax-rust/syntax_test_closures.rs | 18 ++++++++++++++++++ tests/syntax-rust/syntax_test_functions.rs | 14 ++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/tests/syntax-rust/syntax_test_closures.rs b/tests/syntax-rust/syntax_test_closures.rs index 74fca101..6be620a7 100644 --- a/tests/syntax-rust/syntax_test_closures.rs +++ b/tests/syntax-rust/syntax_test_closures.rs @@ -6,6 +6,7 @@ let inferred_closure = |i, j: u32| i + 1; // ^^^^^^^^^^^ meta.function.parameters // ^ punctuation.definition.parameters.begin // ^ variable.parameter +// ^ punctuation.separator // ^ variable.parameter // ^ punctuation.separator // ^^^ storage.type @@ -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.definition.parameters.begin + // ^^^^^^ meta.group + // ^ variable.parameter + // ^ punctuation.separator + // ^ variable.parameter + // ^ punctuation.section.group.end + // ^ punctuation.separator + // ^ punctuation.definition.type.begin + // ^^^ storage.type + // ^ punctuation.separator + // ^ keyword.operator + // ^^^ storage.modifier + // ^^^ storage.type + // ^ punctuation.definition.type.end + // ^ punctuation.definition.parameters.end diff --git a/tests/syntax-rust/syntax_test_functions.rs b/tests/syntax-rust/syntax_test_functions.rs index 259ae88b..6b0283ad 100644 --- a/tests/syntax-rust/syntax_test_functions.rs +++ b/tests/syntax-rust/syntax_test_functions.rs @@ -130,3 +130,17 @@ fn foo(&'a self) {} // ^ keyword.operator // ^^ storage.modifier.lifetime // ^^^^ variable.parameter + +fn sum((x, y): (i32, i32)) -> i32 { +// ^^^^^^ meta.group +// ^ punctuation.section.group.begin +// ^ variable.parameter +// ^ punctuation.separator +// ^ variable.parameter +// ^ punctuation.section.group.end +// ^ punctuation.separator +// ^ punctuation.definition.type.begin +// ^^^ storage.type +// ^ punctuation.separator +// ^^^ storage.type +// ^ punctuation.definition.type.end From fbda3500cff23ba6604a47b35c324dcfc855cad1 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Fri, 14 Feb 2020 15:28:41 -0800 Subject: [PATCH 06/22] Add test for -> in type path in return. --- tests/syntax-rust/syntax_test_generics.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/syntax-rust/syntax_test_generics.rs b/tests/syntax-rust/syntax_test_generics.rs index 87f04ca5..9d3a6149 100644 --- a/tests/syntax-rust/syntax_test_generics.rs +++ b/tests/syntax-rust/syntax_test_generics.rs @@ -317,3 +317,17 @@ fn f(a: for<'a, 'b> fn() -> String) {} // ^ meta.generic punctuation.separator // ^^ meta.generic storage.modifier.lifetime // ^ meta.function meta.function.parameters meta.generic punctuation.definition.generic.end + +// Function in type path with return type. +fn factory() -> Box i32> { +// <- storage.type.function +// ^^^^^^^ entity.name.function +// ^^^^^^^^^^^^^^^^ meta.generic +// ^^ support.type +// ^ punctuation.definition.type.begin +// ^^^ storage.type +// ^ punctuation.definition.type.end +// ^^ punctuation.separator +// ^^^ storage.type + Box::new(|x| x + 1) +} From c1184d8067ceb4b70d363ac8fb3470b617060034 Mon Sep 17 00:00:00 2001 From: wbond Date: Wed, 5 Apr 2017 10:13:47 -0400 Subject: [PATCH 07/22] [Rust] Migrate punctuation.definition to punctuation.section as outlined by scope naming guidelines --- RustEnhanced.sublime-syntax | 68 +++++++++---------- tests/syntax-rust/syntax_test_attributes.rs | 4 +- tests/syntax-rust/syntax_test_closures.rs | 28 ++++---- tests/syntax-rust/syntax_test_control_flow.rs | 24 +++---- tests/syntax-rust/syntax_test_enum.rs | 8 +-- tests/syntax-rust/syntax_test_expr.rs | 22 +++--- tests/syntax-rust/syntax_test_functions.rs | 20 +++--- tests/syntax-rust/syntax_test_generics.rs | 48 ++++++------- tests/syntax-rust/syntax_test_macros.rs | 40 +++++------ tests/syntax-rust/syntax_test_match.rs | 4 +- tests/syntax-rust/syntax_test_modules.rs | 24 +++---- tests/syntax-rust/syntax_test_struct.rs | 22 +++--- tests/syntax-rust/syntax_test_traits.rs | 16 ++--- tests/syntax-rust/syntax_test_types.rs | 20 +++--- tests/syntax-rust/syntax_test_union.rs | 8 +-- tests/syntax-rust/syntax_test_visibility.rs | 28 ++++---- 16 files changed, 192 insertions(+), 192 deletions(-) diff --git a/RustEnhanced.sublime-syntax b/RustEnhanced.sublime-syntax index 38a0062b..3e308b16 100644 --- a/RustEnhanced.sublime-syntax +++ b/RustEnhanced.sublime-syntax @@ -147,7 +147,7 @@ contexts: - match: '\b((?:format(?:_args)?|e?print(?:ln)?|panic|unreachable|unimplemented)!)\s*(\()' captures: 1: support.macro.rust - 2: meta.group.rust punctuation.definition.group.begin.rust + 2: meta.group.rust punctuation.section.group.begin.rust push: - meta_content_scope: meta.group.rust - include: comments @@ -160,7 +160,7 @@ contexts: - match: '\b((?:write(?:ln)?|(?:debug_)?assert)!)\s*(\()' captures: 1: support.macro.rust - 2: meta.group.rust punctuation.definition.group.begin.rust + 2: meta.group.rust punctuation.section.group.begin.rust push: - meta_scope: meta.group.rust - include: comments @@ -193,11 +193,11 @@ contexts: push: group - match: '\[' - scope: punctuation.definition.group.begin.rust + scope: punctuation.section.group.begin.rust push: - meta_scope: meta.group.rust - match: '\]' - scope: punctuation.definition.group.end.rust + scope: punctuation.section.group.end.rust pop: true - match: ';' scope: punctuation.separator.rust @@ -222,11 +222,11 @@ contexts: - match: '\b(pub)\s*(\()' captures: 1: storage.modifier.rust - 2: punctuation.definition.group.begin.rust + 2: punctuation.section.group.begin.rust push: - include: comments - match: '\)' - scope: punctuation.definition.group.end.rust + scope: punctuation.section.group.end.rust pop: true - match: '(crate|in|self|super)' scope: keyword.other.rust @@ -248,10 +248,10 @@ contexts: block: - match: '\}' - scope: meta.block.rust punctuation.definition.block.end.rust + scope: meta.block.rust punctuation.section.block.end.rust pop: true - match: '\{' - scope: punctuation.definition.block.begin.rust + scope: punctuation.section.block.begin.rust push: [block-body, try-closure] block-body: @@ -263,10 +263,10 @@ contexts: group: - match: '\)' - scope: meta.group.rust punctuation.definition.group.end.rust + scope: meta.group.rust punctuation.section.group.end.rust pop: true - match: '\(' - scope: punctuation.definition.group.begin.rust + scope: punctuation.section.group.begin.rust push: [group-body, try-closure] group-body: @@ -278,7 +278,7 @@ contexts: group-tail: - meta_scope: meta.group.rust - match: '\)' - scope: punctuation.definition.group.end.rust + scope: punctuation.section.group.end.rust pop: true - include: statements @@ -402,13 +402,13 @@ contexts: closure: - meta_content_scope: meta.function.closure.rust - match: '\|' - scope: punctuation.definition.parameters.begin.rust + scope: punctuation.section.parameters.begin.rust set: [closure-return, closure-parameters] closure-parameters: - meta_scope: meta.function.parameters.rust - match: '\|' - scope: punctuation.definition.parameters.end.rust + scope: punctuation.section.parameters.end.rust pop: true - include: pattern-param # If the user has just typed a |, exit the params @@ -508,11 +508,11 @@ contexts: - match: \b(fn)\b\s*(\() captures: 1: storage.type.function.rust - 2: meta.group.rust punctuation.definition.group.begin.rust + 2: meta.group.rust punctuation.section.group.begin.rust push: - meta_content_scope: meta.group.rust - match: \) - scope: meta.group.rust punctuation.definition.group.end.rust + scope: meta.group.rust punctuation.section.group.end.rust set: - include: return-type - match: '(?=\S)' @@ -530,10 +530,10 @@ contexts: - match: '(?=<)' push: generic-angles - match: '\(' - scope: punctuation.definition.type.begin.rust + scope: punctuation.section.group.begin.rust push: - match: '\)' - scope: punctuation.definition.type.end.rust + scope: punctuation.section.group.end.rust pop: true - match: ',' scope: punctuation.separator.rust @@ -572,10 +572,10 @@ contexts: type-slice: - match: '\[' - scope: punctuation.definition.group.begin.rust + scope: punctuation.section.group.begin.rust push: - match: '\]' - scope: punctuation.definition.group.end.rust + scope: punctuation.section.group.end.rust pop: true - include: type-any-identifier @@ -613,10 +613,10 @@ contexts: struct-tuple: - meta_scope: meta.struct.rust - match: '\)' - scope: punctuation.definition.group.end.rust + scope: punctuation.section.group.end.rust pop: true - match: '\(' - scope: punctuation.definition.group.begin.rust + scope: punctuation.section.group.begin.rust push: - match: '(?=\))' pop: true @@ -630,10 +630,10 @@ contexts: struct-classic: - meta_scope: meta.struct.rust - match: '\}' - scope: meta.block.rust punctuation.definition.block.end.rust + scope: meta.block.rust punctuation.section.block.end.rust pop: true - match: '\{' - scope: punctuation.definition.block.begin.rust + scope: punctuation.section.block.begin.rust push: struct-classic-body - match: '(?=\S)' # Abort for an invalid match. @@ -683,10 +683,10 @@ contexts: - match: '(?=\bwhere\b)' push: impl-where - match: '\{' - scope: punctuation.definition.block.begin.rust + scope: punctuation.section.block.begin.rust push: struct-classic-body - match: '\}' - scope: meta.block.rust punctuation.definition.block.end.rust + scope: meta.block.rust punctuation.section.block.end.rust pop: true - match: '(?=;)' pop: true @@ -715,7 +715,7 @@ contexts: - match: '(?=\bwhere\b)' push: impl-where - match: '\{' - scope: punctuation.definition.block.begin.rust + scope: punctuation.section.block.begin.rust set: enum-body - match: '(?=\S)' # Abort on invalid character. @@ -726,7 +726,7 @@ contexts: - include: comments - include: attribute - match: '\}' - scope: punctuation.definition.block.end.rust + scope: punctuation.section.block.end.rust pop: true - match: '\b[[:upper:]_][[:upper:][:digit:]_]*\b' scope: constant.other.rust @@ -872,7 +872,7 @@ contexts: - meta_include_prototype: false - match: '(\))\s*[^?*+]*\s*([?*+])' captures: - 1: punctuation.definition.group.end.rust + 1: punctuation.section.group.end.rust 2: keyword.operator.rust pop: true - include: macro-matchers @@ -1027,10 +1027,10 @@ contexts: fn-parameters: - meta_scope: meta.function.rust - match: '\)' - scope: meta.function.parameters.rust punctuation.definition.parameters.end.rust + scope: meta.function.parameters.rust punctuation.section.parameters.end.rust set: fn-return - match: '\(' - scope: punctuation.definition.parameters.begin.rust + scope: punctuation.section.parameters.begin.rust push: - meta_scope: meta.function.parameters.rust - include: comments @@ -1066,10 +1066,10 @@ contexts: fn-body: - meta_scope: meta.function.rust - match: '\}' - scope: meta.block.rust punctuation.definition.block.end.rust + scope: meta.block.rust punctuation.section.block.end.rust pop: true - match: '\{' - scope: punctuation.definition.block.begin.rust + scope: punctuation.section.block.begin.rust push: - meta_scope: meta.block.rust - match: '(?=\})' @@ -1079,10 +1079,10 @@ contexts: statements-block: - include: comments - match: '\}' - scope: meta.block.rust punctuation.definition.block.end.rust + scope: meta.block.rust punctuation.section.block.end.rust pop: true - match: '\{' - scope: punctuation.definition.block.begin.rust + scope: punctuation.section.block.begin.rust push: [block-body, try-closure] comments: diff --git a/tests/syntax-rust/syntax_test_attributes.rs b/tests/syntax-rust/syntax_test_attributes.rs index 08fd8381..34ab9ce4 100644 --- a/tests/syntax-rust/syntax_test_attributes.rs +++ b/tests/syntax-rust/syntax_test_attributes.rs @@ -4,9 +4,9 @@ // <- meta.annotation //^^^^^^^^^^^^^^ meta.annotation // ^^^^ support.function -// ^ meta.group punctuation.definition.group.begin +// ^ meta.group punctuation.section.group.begin // ^^^^^^ meta.group -// ^ meta.group punctuation.definition.group.end +// ^ meta.group punctuation.section.group.end #[macro_use] // <- meta.annotation diff --git a/tests/syntax-rust/syntax_test_closures.rs b/tests/syntax-rust/syntax_test_closures.rs index 6be620a7..54e0168f 100644 --- a/tests/syntax-rust/syntax_test_closures.rs +++ b/tests/syntax-rust/syntax_test_closures.rs @@ -4,25 +4,25 @@ 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; @@ -34,18 +34,18 @@ call_func(|c| 1 + 2 + c); 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 } @@ -182,18 +182,18 @@ let x = |/*comment*/(/*c*/a, [b/*c*/], S{/*c*/f: c})| {}; // ^ variable.parameter let f = |(x, y): (u32, &mut u32)| { x + y }; - // ^ punctuation.definition.parameters.begin + // ^ punctuation.section.parameters.begin // ^^^^^^ meta.group // ^ variable.parameter // ^ punctuation.separator // ^ variable.parameter // ^ punctuation.section.group.end // ^ punctuation.separator - // ^ punctuation.definition.type.begin + // ^ punctuation.section.group.begin // ^^^ storage.type // ^ punctuation.separator // ^ keyword.operator // ^^^ storage.modifier // ^^^ storage.type - // ^ punctuation.definition.type.end - // ^ punctuation.definition.parameters.end + // ^ punctuation.section.group.end + // ^ punctuation.section.parameters.end diff --git a/tests/syntax-rust/syntax_test_control_flow.rs b/tests/syntax-rust/syntax_test_control_flow.rs index 2857e4f3..5bfa2953 100644 --- a/tests/syntax-rust/syntax_test_control_flow.rs +++ b/tests/syntax-rust/syntax_test_control_flow.rs @@ -14,13 +14,13 @@ for i in 1..10 { 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 @@ -51,38 +51,38 @@ 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 +// ^ 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 +// ^ meta.block punctuation.section.block.begin println!("Constructed example: {}", j) j = BasicStruct(j + 1); if k > 20 { @@ -90,7 +90,7 @@ while let BasicStruct(k) = j { //^^^ meta.block meta.block keyword.control } } -// <- meta.block punctuation.definition.block.end +// <- meta.block punctuation.section.block.end continue_running(); //^^^^^^^^^^^^^^ support.function diff --git a/tests/syntax-rust/syntax_test_enum.rs b/tests/syntax-rust/syntax_test_enum.rs index 6b0ab736..d27fb9ec 100644 --- a/tests/syntax-rust/syntax_test_enum.rs +++ b/tests/syntax-rust/syntax_test_enum.rs @@ -5,7 +5,7 @@ enum OperatingSystem // ^^^^^^^^^^^^^^^^^ meta.enum // ^^^^^^^^^^^^^^^ entity.name.enum { -// <- meta.enum punctuation.definition.block.begin +// <- meta.enum punctuation.section.block.begin Osx, // ^^^ meta.enum storage.type.source Windows, @@ -13,12 +13,12 @@ enum OperatingSystem 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.enum punctuation.section.block.end let q = Message::Quit; // ^^^^^^^ storage.type.source diff --git a/tests/syntax-rust/syntax_test_expr.rs b/tests/syntax-rust/syntax_test_expr.rs index 3a9bc1de..a24773a1 100644 --- a/tests/syntax-rust/syntax_test_expr.rs +++ b/tests/syntax-rust/syntax_test_expr.rs @@ -10,25 +10,25 @@ let big_n = // ^ keyword.operator // ^ keyword.operator // ^^ constant.numeric.integer.decimal -// ^ meta.block punctuation.definition.block.begin +// ^ meta.block punctuation.section.block.begin 10 * n // ^ meta.block keyword.operator } else { -// ^ meta.block punctuation.definition.block.end -// ^ meta.block punctuation.definition.block.begin +// ^ meta.block punctuation.section.block.end +// ^ meta.block punctuation.section.block.begin n / 2 // ^ meta.block keyword.operator }; -// ^ meta.block punctuation.definition.block.end +// ^ meta.block punctuation.section.block.end let tuple = (1.0, 0i32, "Hello"); // ^^^^^^^^^^^^^^^^^^^^ meta.group -// ^ punctuation.definition.group.begin +// ^ punctuation.section.group.begin // ^^^ constant.numeric.float // ^ constant.numeric.integer.decimal // ^^^ storage.type // ^^^^^^^ string.quoted.double -// ^ punctuation.definition.group.end +// ^ punctuation.section.group.end // Tuple access. let x = tuple.1; @@ -37,14 +37,14 @@ let x = tuple.1; // Array access. let x = arr[1]; // ^^^ meta.group -// ^ punctuation.definition.group.begin +// ^ punctuation.section.group.begin // ^ constant.numeric.integer.decimal -// ^ punctuation.definition.group.end +// ^ punctuation.section.group.end // Array expression. let x = [1; 2]; // ^^^^^^ meta.group -// ^ punctuation.definition.group.begin +// ^ punctuation.section.group.begin // ^ punctuation.separator // ^ constant.numeric.integer.decimal // ^ punctuation.terminator @@ -71,13 +71,13 @@ assert_eq!(*x, 7); // Block expression. let z = { -// ^ meta.block punctuation.definition.block.begin +// ^ meta.block punctuation.section.block.begin 2 * 5 // ^ constant.numeric.integer.decimal // ^ keyword.operator // ^ constant.numeric.integer.decimal }; -// <- meta.block punctuation.definition.block.end +// <- meta.block punctuation.section.block.end // Various operators. let x = !6; diff --git a/tests/syntax-rust/syntax_test_functions.rs b/tests/syntax-rust/syntax_test_functions.rs index 6b0283ad..60aa9dd2 100644 --- a/tests/syntax-rust/syntax_test_functions.rs +++ b/tests/syntax-rust/syntax_test_functions.rs @@ -4,15 +4,15 @@ fn my_func(x: i32) // <- storage.type.function // ^^^^^^^ entity.name.function // ^^^^^^^^ meta.function.parameters -// ^ punctuation.definition.parameters.begin +// ^ punctuation.section.parameters.begin // ^ variable.parameter // ^ punctuation.separator -// ^ punctuation.definition.parameters.end +// ^ punctuation.section.parameters.end { -// <- meta.function meta.block punctuation.definition.block.begin +// <- meta.function meta.block punctuation.section.block.begin } -// <- meta.function meta.block punctuation.definition.block.end +// <- meta.function meta.block punctuation.section.block.end fn foo(i: u32, b: i64) -> u32 { // <- storage.type.function @@ -21,10 +21,10 @@ fn foo(i: u32, b: i64) -> u32 { // ^ punctuation.definition.generic.end // ^^^^^^^^^^^^^^^^ meta.function.parameters // ^^^ storage.type -// ^ meta.block punctuation.definition.block.begin +// ^ meta.block punctuation.section.block.begin } -// <- meta.block punctuation.definition.block.end +// <- meta.block punctuation.section.block.end fn my_other_func(e: OperatingSystem) -> &'a f64 { @@ -55,8 +55,8 @@ pub unsafe extern "C" fn __sync_synchronize() { } // ^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function // ^^ storage.type.function // ^^^^^^^^^^^^^^^^^^ entity.name.function -// ^ meta.function.parameters punctuation.definition.parameters.begin -// ^ meta.function.parameters punctuation.definition.parameters.end +// ^ meta.function.parameters punctuation.section.parameters.begin +// ^ meta.function.parameters punctuation.section.parameters.end let f: extern "C" fn () = mem::transmute(0xffff0fa0u32); // ^^^^^^ keyword.other @@ -139,8 +139,8 @@ fn sum((x, y): (i32, i32)) -> i32 { // ^ variable.parameter // ^ punctuation.section.group.end // ^ punctuation.separator -// ^ punctuation.definition.type.begin +// ^ punctuation.section.group.begin // ^^^ storage.type // ^ punctuation.separator // ^^^ storage.type -// ^ punctuation.definition.type.end +// ^ punctuation.section.group.end diff --git a/tests/syntax-rust/syntax_test_generics.rs b/tests/syntax-rust/syntax_test_generics.rs index 9d3a6149..df94be98 100644 --- a/tests/syntax-rust/syntax_test_generics.rs +++ b/tests/syntax-rust/syntax_test_generics.rs @@ -17,15 +17,15 @@ impl Thing for &'a mut A {} // Various tests on `where`. fn f<'b: 'a>(self) -> &'b mut [i32] where 'a: 'b { } // ^^^^^^^^^^^^^^ meta.function meta.function.return-type -// ^ meta.function meta.function.return-type punctuation.definition.group.begin +// ^ meta.function meta.function.return-type punctuation.section.group.begin // ^^^ meta.function meta.function.return-type storage.type -// ^ meta.function meta.function.return-type punctuation.definition.group.end +// ^ meta.function meta.function.return-type punctuation.section.group.end // ^^^^^ meta.function meta.where keyword.other // ^^ meta.function meta.where storage.modifier.lifetime // ^ meta.function meta.where punctuation.separator // ^^ meta.function meta.where storage.modifier.lifetime -// ^ meta.function meta.block punctuation.definition.block.begin -// ^ meta.function meta.block punctuation.definition.block.end +// ^ meta.function meta.block punctuation.section.block.begin +// ^ meta.function meta.block punctuation.section.block.end fn f(func: F) -> usize // ^^ meta.function meta.function.return-type punctuation.separator @@ -35,13 +35,13 @@ fn f(func: F) -> usize // ^^^^^^^^^^^^^^^^^^^^^ meta.function meta.where // ^ punctuation.separator // ^^ support.type -// ^ punctuation.definition.type.begin +// ^ punctuation.section.group.begin // ^^^^^ storage.type -// ^ punctuation.definition.type.end +// ^ punctuation.section.group.end // ^^ meta.function.return-type punctuation.separator // ^^^^^ meta.function.return-type storage.type -// ^ meta.function meta.block punctuation.definition.block.begin -// ^ meta.function meta.block punctuation.definition.block.end +// ^ meta.function meta.block punctuation.section.block.begin +// ^ meta.function meta.block punctuation.section.block.end fn f(lhs: L, rhs: R) where L: IntoIterator, @@ -50,41 +50,41 @@ fn f(lhs: L, rhs: R) // ^^^^^^^^^^^^ support.type // ^^^^^^^^^^^^^^^^^^^^^^^^^ meta.generic // ^ punctuation.definition.generic.begin -// ^ punctuation.definition.type.begin +// ^ punctuation.section.group.begin // ^ keyword.operator // ^^ storage.modifier.lifetime // ^^^ storage.type // ^ keyword.operator // ^^ storage.modifier.lifetime // ^^^ storage.type -// ^ punctuation.definition.type.end +// ^ punctuation.section.group.end // ^ punctuation.definition.generic.end R: IntoIterator, {} // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function meta.where -// ^ meta.function meta.block punctuation.definition.block.begin -// ^ meta.function meta.block punctuation.definition.block.end +// ^ meta.function meta.block punctuation.section.block.begin +// ^ meta.function meta.block punctuation.section.block.end fn f usize>(func: f) {} // ^^^^^^^^^^^^^^^^^^^^^^^ meta.generic // ^ meta.generic punctuation.definition.generic.begin // ^ meta.generic punctuation.separator // ^^ meta.generic support.type -// ^ meta.generic punctuation.definition.type.begin +// ^ meta.generic punctuation.section.group.begin // ^^^^^ meta.generic storage.type -// ^ meta.generic punctuation.definition.type.end +// ^ meta.generic punctuation.section.group.end // ^^^^^ meta.generic meta.function.return-type storage.type // ^ meta.generic punctuation.definition.generic.end -// ^ meta.function meta.function.parameters punctuation.definition.parameters.begin +// ^ meta.function meta.function.parameters punctuation.section.parameters.begin // ^^^^ meta.function meta.function.parameters variable.parameter fn f>(lhs: L) {} // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.generic // ^ punctuation.definition.generic.begin // ^ punctuation.definition.generic.begin -// ^ punctuation.definition.type.begin +// ^ punctuation.section.group.begin // ^^ storage.modifier.lifetime // ^^^ storage.type // ^ punctuation.definition.generic.begin // ^ punctuation.definition.generic.end -// ^ meta.function meta.function.parameters punctuation.definition.parameters.begin +// ^ meta.function meta.function.parameters punctuation.section.parameters.begin struct A(T) where T: AsRef; //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.struct @@ -105,7 +105,7 @@ pub struct IterHolder where A: Number { // ^^^ meta.struct meta.generic // ^^^^^ meta.struct meta.where keyword.other // ^^^^^^ meta.struct meta.where -// ^ meta.struct punctuation.definition.block.begin +// ^ meta.struct punctuation.section.block.begin num: A } @@ -173,8 +173,8 @@ impl Iterator for Fibonacci } pub const FOO: Option<[i32; 1]> = Some([1]); -// ^ punctuation.definition.group.begin -// ^ punctuation.definition.group.end +// ^ punctuation.section.group.begin +// ^ punctuation.section.group.end #[derive(Clone)] pub struct GobletMiddleware { @@ -226,10 +226,10 @@ fn numbers() -> impl Iterator { fn collect_vec() { let _: Vec<(usize, usize)> = (0..10).enumerate().collect::>(); // ^^^^^^^^^^^^^^^^^^^ meta.generic -// ^ punctuation.definition.type.begin +// ^ punctuation.section.group.begin // ^^^^^ storage.type // ^^^^^ storage.type -// ^ punctuation.definition.type.end +// ^ punctuation.section.group.end // ^^^^^^^^ meta.generic // ^^^^^^ meta.generic meta.generic // ^ keyword.operator @@ -324,9 +324,9 @@ fn factory() -> Box i32> { // ^^^^^^^ entity.name.function // ^^^^^^^^^^^^^^^^ meta.generic // ^^ support.type -// ^ punctuation.definition.type.begin +// ^ punctuation.section.group.begin // ^^^ storage.type -// ^ punctuation.definition.type.end +// ^ punctuation.section.group.end // ^^ punctuation.separator // ^^^ storage.type Box::new(|x| x + 1) diff --git a/tests/syntax-rust/syntax_test_macros.rs b/tests/syntax-rust/syntax_test_macros.rs index d3b7ea1f..f1ec5ab0 100644 --- a/tests/syntax-rust/syntax_test_macros.rs +++ b/tests/syntax-rust/syntax_test_macros.rs @@ -4,20 +4,20 @@ String my_var = format!("Hello {0}", "World"); // ^^^ support.type // ^ keyword.operator // ^^^^^^^ support.macro -// ^ punctuation.definition.group.begin +// ^ punctuation.section.group.begin // ^^^^^^^^^^^^^^^^^^^^^^ meta.group // ^^^^^^^^^^^ string.quoted.double // ^^^ constant.other.placeholder -// ^ punctuation.definition.group.end +// ^ punctuation.section.group.end pub fn macro_tests() { println!(); // ^^^^^^^^ support.macro println!("Example"); // ^^^^^^^^ support.macro -// ^ punctuation.definition.group.begin +// ^ punctuation.section.group.begin // ^^^^^^^^^ string.quoted.double -// ^ punctuation.definition.group.end +// ^ punctuation.section.group.end println!("Example {} {message}", "test", message="hi"); // ^^ constant.other.placeholder // ^^^^^^^^^ constant.other.placeholder @@ -25,9 +25,9 @@ pub fn macro_tests() { // ^^^^^^ support.macro panic!("Example"); // ^^^^^^ support.macro -// ^ punctuation.definition.group.begin +// ^ punctuation.section.group.begin // ^^^^^^^^^ string.quoted.double -// ^ punctuation.definition.group.end +// ^ punctuation.section.group.end panic!("Example {} {message}", "test", message="hi"); // ^^ constant.other.placeholder // ^^^^^^^^^ constant.other.placeholder @@ -46,7 +46,7 @@ pub fn macro_tests() { my_var = format!("Hello {name}, how are you?", // ^ keyword.operator // ^^^^^^^ support.macro -// ^ punctuation.definition.group.begin +// ^ punctuation.section.group.begin // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.double // ^^^^^^ constant.other.placeholder @@ -54,15 +54,15 @@ my_var = format!("Hello {name}, how are you?", // ^^^^^^^^^^^^^ meta.group // ^ keyword.operator // ^^^^^^ string.quoted.double -// ^ punctuation.definition.group.end +// ^ punctuation.section.group.end write!(f, "{}", self.0) // ^^^^^^ support.macro // ^^^^^^^^^^^^^^^^^ meta.group -// ^ punctuation.definition.group.begin +// ^ punctuation.section.group.begin // ^^^^ string.quoted.double // ^^ constant.other.placeholder -// ^ punctuation.definition.group.end +// ^ punctuation.section.group.end write!(f, "{:10}", self.0) // ^^^^^ constant.other.placeholder eprint!("{:^10}", self.0) @@ -86,18 +86,18 @@ my_var = format!("Hello {name}, how are you?", // ^^^^ string.quoted.double // ^^ constant.other.placeholder // ^^^^ string.quoted.double -// ^ punctuation.definition.group.begin -// ^ punctuation.definition.group.end +// ^ punctuation.section.group.begin +// ^ punctuation.section.group.end writeln!(w) // ^^^^^^^^ support.macro // ^^^ meta.group -// ^ punctuation.definition.group.begin -// ^ punctuation.definition.group.end +// ^ punctuation.section.group.begin +// ^ punctuation.section.group.end println!() // ^^^^^^^^ support.macro // ^^ meta.group -// ^ punctuation.definition.group.begin -// ^ punctuation.definition.group.end +// ^ punctuation.section.group.begin +// ^ punctuation.section.group.end /*******************************************************************/ // The outer brackets can be any type. @@ -209,7 +209,7 @@ macro_rules! forward_ref_binop [ // ^ keyword.operator // ^^ storage.modifier.lifetime // ^^ variable.other -// ^ meta.macro meta.macro.transcribers meta.impl meta.block punctuation.definition.block.begin +// ^ meta.macro meta.macro.transcribers meta.impl meta.block punctuation.section.block.begin type Output = <$t as $imp<$u>>::Output; // ^^^^^^^^^^^^^^^^ meta.generic // ^^ meta.path @@ -226,7 +226,7 @@ macro_rules! forward_ref_binop [ // ^^ punctuation.separator // ^^^^^^^^^^^^^^^^ meta.generic // ^^ meta.path -// ^ meta.macro meta.macro.transcribers meta.impl meta.block meta.block punctuation.definition.block.begin +// ^ meta.macro meta.macro.transcribers meta.impl meta.block meta.block punctuation.section.block.begin $imp::$method(*self, *other) // ^^^^ variable.other // ^^^^^^^ variable.other @@ -248,7 +248,7 @@ macro_rules! kleene_star { // ^^^^ variable.parameter // ^ punctuation.separator // ^^ storage.type -// ^ punctuation.definition.group.end +// ^ punctuation.section.group.end // ^ keyword.operator // ^ punctuation.section.block.end // ^^ meta.macro keyword.operator @@ -292,7 +292,7 @@ macro_rules! kleene_star { // ^^^^^ variable.parameter // ^ punctuation.separator // ^^ storage.type -// ^ punctuation.definition.group.end +// ^ punctuation.section.group.end // ^ keyword.operator // ^ punctuation.section.block.end // ^^ meta.macro keyword.operator diff --git a/tests/syntax-rust/syntax_test_match.rs b/tests/syntax-rust/syntax_test_match.rs index a4c98d05..3ff5d106 100644 --- a/tests/syntax-rust/syntax_test_match.rs +++ b/tests/syntax-rust/syntax_test_match.rs @@ -41,7 +41,7 @@ match n { match my_func() { // ^^ keyword.control // ^^^^^^^ support.function -// ^ meta.block punctuation.definition.block.begin +// ^ meta.block punctuation.section.block.begin 0 => println!("None"), // ^ constant.numeric.integer.decimal // ^^ keyword.operator @@ -54,4 +54,4 @@ match my_func() { // ^ source // ^^ keyword.operator } -// <- meta.block punctuation.definition.block.end +// <- meta.block punctuation.section.block.end diff --git a/tests/syntax-rust/syntax_test_modules.rs b/tests/syntax-rust/syntax_test_modules.rs index 9d4c21b5..d3aef25b 100644 --- a/tests/syntax-rust/syntax_test_modules.rs +++ b/tests/syntax-rust/syntax_test_modules.rs @@ -26,9 +26,9 @@ pub mod my_mod { // <- storage.modifier // ^^^ storage.type.module // ^^^^^^ entity.name.module -// ^ meta.block punctuation.definition.block.begin +// ^ meta.block punctuation.section.block.begin } -// <- meta.module meta.block punctuation.definition.block.end +// <- meta.module meta.block punctuation.section.block.end pub use self::trafile::*; // <- storage.modifier @@ -53,40 +53,40 @@ use foo::Bar; use foo::{Baz, QUX, quux}; // ^^^^^ meta.path // ^^^^^^^^^^^^^^^^ meta.block -// ^ punctuation.definition.block.begin +// ^ punctuation.section.block.begin // ^^^ storage.type.source // ^^^ constant.other // ^^^^ meta.block -// ^ punctuation.definition.block.end +// ^ punctuation.section.block.end // ^ punctuation.terminator use std::{ // <- keyword.other // ^^^^^ meta.path -// ^ meta.block punctuation.definition.block.begin +// ^ meta.block punctuation.section.block.begin fs::{self, read_dir}, // ^^^^ meta.block meta.path -// ^ meta.block meta.block punctuation.definition.block.begin +// ^ meta.block meta.block punctuation.section.block.begin // ^^^^ meta.block meta.block variable.language // ^^^^^^^^ meta.block meta.block -// ^ meta.block meta.block punctuation.definition.block.end +// ^ meta.block meta.block punctuation.section.block.end path::{Path, PathBuf}, // ^^^^^^ meta.block meta.path -// ^ meta.block meta.block punctuation.definition.block.begin +// ^ meta.block meta.block punctuation.section.block.begin // ^^^^ meta.block meta.block storage.type.source // ^^^^^^^ meta.block meta.block storage.type.source -// ^ meta.block meta.block punctuation.definition.block.end +// ^ meta.block meta.block punctuation.section.block.end }; -// ^ meta.block punctuation.definition.block.end +// ^ meta.block punctuation.section.block.end // ^ punctuation.terminator extern { // <- keyword.other //^^^^ keyword.other -// ^ meta.block punctuation.definition.block.begin +// ^ meta.block punctuation.section.block.begin fn foo(x: i32, ...); } -// <- meta.block punctuation.definition.block.end +// <- meta.block punctuation.section.block.end extern "stdcall" { } // <- keyword.other diff --git a/tests/syntax-rust/syntax_test_struct.rs b/tests/syntax-rust/syntax_test_struct.rs index 6ecb1929..047ad7b6 100644 --- a/tests/syntax-rust/syntax_test_struct.rs +++ b/tests/syntax-rust/syntax_test_struct.rs @@ -5,21 +5,21 @@ struct BasicStruct(i32); // <- storage.type.struct //^^^^ storage.type.struct // ^^^^^^^^^^^ entity.name.struct -// ^ punctuation.definition.group.begin +// ^ punctuation.section.group.begin // ^^^ storage.type -// ^ punctuation.definition.group.end +// ^ punctuation.section.group.end struct PrintableStruct(Box); // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.struct // <- storage.type.struct //^^^^ storage.type.struct // ^^^^^^^^^^^^^^^ entity.name.struct -// ^ punctuation.definition.group.begin +// ^ punctuation.section.group.begin // ^^^^^^^^ meta.generic // ^ punctuation.definition.generic.begin // ^^^ storage.type // ^ punctuation.definition.generic.end -// ^ punctuation.definition.group.end +// ^ punctuation.section.group.end struct Nil; // ^^^^^^^ meta.struct @@ -37,7 +37,7 @@ struct /*comment*/ Comments {} struct Point // ^^^^^^^^^ meta.struct { -// <- meta.struct meta.block punctuation.definition.block.begin +// <- meta.struct meta.block punctuation.section.block.begin x: i32, // ^ variable.other.member // ^ punctuation.separator @@ -47,12 +47,12 @@ struct Point // ^ punctuation.separator // ^^^ storage.type } -// <- meta.block punctuation.definition.block.end +// <- meta.block punctuation.section.block.end impl Point //^^^^^^^^ meta.impl { -// <- meta.impl meta.block punctuation.definition.block.begin +// <- meta.impl meta.block punctuation.section.block.begin fn new(x: i32, y: i32) -> Point // <- storage.type.function // ^^^ entity.name.function @@ -73,9 +73,9 @@ struct Val (f64,); //^^^^^^^^^^^^^^^ meta.struct // ^^^ entity.name.struct // ^^^^^ meta.group -// ^ punctuation.definition.group.begin +// ^ punctuation.section.group.begin // ^^^ storage.type -// ^ punctuation.definition.group.end +// ^ punctuation.section.group.end // ^ punctuation.terminator struct F { @@ -105,10 +105,10 @@ let mut j = BasicStruct(10); let p = Point {x: 10.0, y: 20.0}; // ^^^^^ storage.type.source // ^^^^^^^^^^^^^^^^^^ meta.block -// ^ punctuation.definition.block.begin +// ^ punctuation.section.block.begin // ^ punctuation.separator // ^^^^ constant.numeric.float -// ^ punctuation.definition.block.end +// ^ punctuation.section.block.end let n = NothingInMe {}; // ^^^^^^^^^^^ storage.type.source // ^^ meta.block diff --git a/tests/syntax-rust/syntax_test_traits.rs b/tests/syntax-rust/syntax_test_traits.rs index c7ba70fb..2d48d4c2 100644 --- a/tests/syntax-rust/syntax_test_traits.rs +++ b/tests/syntax-rust/syntax_test_traits.rs @@ -3,12 +3,12 @@ pub trait Animal { // <- storage.modifier // ^^^^^^^^^^^^^^ meta.trait -// ^ meta.block punctuation.definition.block.begin +// ^ meta.block punctuation.section.block.begin fn noise(quiet: bool) { // Comment } } -// <- meta.trait meta.block punctuation.definition.block.end +// <- meta.trait meta.block punctuation.section.block.end impl<'a, T: MyTrait + OtherTrait> PrintInOption for T where // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.impl @@ -34,14 +34,14 @@ impl fmt::Display for PrintableStruct { // ^^^^^ meta.path // ^^^ keyword.other // ^^^^^^^^^^^^^^^ entity.name.impl -// ^ meta.block punctuation.definition.block.begin +// ^ meta.block punctuation.section.block.begin fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.impl // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function // ^^ storage.type.function // ^^^ entity.name.function // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.parameters -// ^ punctuation.definition.parameters.begin +// ^ punctuation.section.parameters.begin // ^ keyword.operator // ^^^^ variable.parameter // ^ variable.parameter @@ -49,15 +49,15 @@ impl fmt::Display for PrintableStruct { // ^ keyword.operator // ^^^ storage.modifier // ^^^^^ meta.path -// ^ punctuation.definition.parameters.end +// ^ punctuation.section.parameters.end // ^^ punctuation.separator // ^^^^^ meta.path -// ^ meta.block punctuation.definition.block.begin +// ^ meta.block punctuation.section.block.begin } // ^^ meta.function meta.block -// ^ punctuation.definition.block.end +// ^ punctuation.section.block.end } -// <- meta.block punctuation.definition.block.end +// <- meta.block punctuation.section.block.end impl !Send for Point {} //^^^^^^^^^^^^^^^^^^^^^ meta.impl diff --git a/tests/syntax-rust/syntax_test_types.rs b/tests/syntax-rust/syntax_test_types.rs index 08a884f3..bca07108 100644 --- a/tests/syntax-rust/syntax_test_types.rs +++ b/tests/syntax-rust/syntax_test_types.rs @@ -81,12 +81,12 @@ type Pair<'a> = (i32, &'a str); // ^ keyword.operator // ^ keyword.operator // ^^^^^^^^^^^^^^ meta.group -// ^ punctuation.definition.group.begin +// ^ punctuation.section.group.begin // ^^^ storage.type // ^ keyword.operator // ^^ storage.modifier.lifetime // ^^^ storage.type -// ^ punctuation.definition.group.end +// ^ punctuation.section.group.end // ^ punctuation.terminator let p: Pair<'static> = (10, "ten"); // <- storage.type @@ -97,31 +97,31 @@ let p: Pair<'static> = (10, "ten"); // ^ punctuation.definition.generic.end // ^ keyword.operator // ^^^^^^^^^^^ meta.group -// ^ punctuation.definition.group.begin +// ^ punctuation.section.group.begin // ^^ constant.numeric.integer.decimal // ^^^^^ string.quoted.double -// ^ punctuation.definition.group.end +// ^ punctuation.section.group.end // ^ punctuation.terminator // Array types. let xs: [i32; 5] = [1, 2, 3, 4, 5]; // ^ punctuation.separator // ^^^^^^^^ meta.group -// ^ punctuation.definition.group.begin +// ^ punctuation.section.group.begin // ^^^ storage.type // ^ punctuation.separator // ^ constant.numeric.integer.decimal -// ^ punctuation.definition.group.end +// ^ punctuation.section.group.end // ^^^^^^^^^^^^^^^ meta.group -// ^ punctuation.definition.group.begin -// ^ punctuation.definition.group.end +// ^ punctuation.section.group.begin +// ^ punctuation.section.group.end // Slice types. let slice: &[i32]; // ^ keyword.operator // ^^^^^ meta.group -// ^ punctuation.definition.group.begin -// ^ punctuation.definition.group.end +// ^ punctuation.section.group.begin +// ^ punctuation.section.group.end // ^^^ storage.type diff --git a/tests/syntax-rust/syntax_test_union.rs b/tests/syntax-rust/syntax_test_union.rs index d8e4be11..e9987087 100644 --- a/tests/syntax-rust/syntax_test_union.rs +++ b/tests/syntax-rust/syntax_test_union.rs @@ -4,13 +4,13 @@ union Union { //^^^ meta.union storage.type.union //^^^^^^^^^^^ meta.union // ^^^^^ entity.name.union -// ^ meta.block punctuation.definition.block.begin +// ^ meta.block punctuation.section.block.begin f: u32, // ^ meta.union meta.block variable.other.member // ^ meta.union meta.block punctuation.separator // ^^^ meta.union meta.block storage.type } -// <- meta.union meta.block punctuation.definition.block.end +// <- meta.union meta.block punctuation.section.block.end pub union Foo<'a, Y: Baz> // <- storage.modifier @@ -25,11 +25,11 @@ pub union Foo<'a, Y: Baz> // ^ meta.union meta.where punctuation.separator // ^^^^^^^^^^ meta.union meta.where { -// <- meta.union meta.block punctuation.definition.block.begin +// <- meta.union meta.block punctuation.section.block.begin f: SomeType, // Comment beside a field // ^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.union meta.block comment.line.double-slash } -// <- meta.union meta.block punctuation.definition.block.end +// <- meta.union meta.block punctuation.section.block.end // Union was implemented in such a way that `union` is not a keyword. Verify // that we don't accidentally interpret it as a keyword. diff --git a/tests/syntax-rust/syntax_test_visibility.rs b/tests/syntax-rust/syntax_test_visibility.rs index 5564efcd..74b74bfd 100644 --- a/tests/syntax-rust/syntax_test_visibility.rs +++ b/tests/syntax-rust/syntax_test_visibility.rs @@ -2,23 +2,23 @@ pub ( crate ) struct S {} // <- storage.modifier -// ^ punctuation.definition.group.begin +// ^ punctuation.section.group.begin // ^^^^^ keyword.other -// ^ punctuation.definition.group.end +// ^ punctuation.section.group.end // ^^^^^^^^^^^ meta.struct pub ( in foo::bar ) union U {} -// ^ punctuation.definition.group.begin +// ^ punctuation.section.group.begin // ^^ keyword.other // ^^^^^^^^ meta.path -// ^ punctuation.definition.group.end +// ^ punctuation.section.group.end // ^^^^^^^^^^ meta.union pub ( in foo :: bar ) type T = i32; -// ^ punctuation.definition.group.begin +// ^ punctuation.section.group.begin // ^^ keyword.other // ^^^ meta.path // ^^ meta.path // ^^^ meta.path -// ^ punctuation.definition.group.end +// ^ punctuation.section.group.end // ^^^^ storage.type.type pub ( in ::foo ) fn f() {} // ^^^^^ meta.path @@ -50,17 +50,17 @@ struct S { // ^^ meta.struct variable.other.member pub(crate) f2: i32, // ^^^ meta.struct storage.modifier -// ^ meta.struct punctuation.definition.group.begin +// ^ meta.struct punctuation.section.group.begin // ^^^^^ meta.struct keyword.other -// ^ meta.struct punctuation.definition.group.end +// ^ meta.struct punctuation.section.group.end // ^^ meta.struct variable.other.member pub(in super::foo) f3: i32, // ^^^ meta.struct storage.modifier -// ^ meta.struct punctuation.definition.group.begin +// ^ meta.struct punctuation.section.group.begin // ^^ meta.struct keyword.other // ^^^^^ meta.struct keyword.other // ^^^^^ meta.struct meta.path -// ^ meta.struct punctuation.definition.group.end +// ^ meta.struct punctuation.section.group.end // ^^ meta.struct variable.other.member } @@ -70,15 +70,15 @@ struct S ( // ^^^ meta.struct storage.type pub(crate) i32, // ^^^ meta.struct storage.modifier -// ^ meta.struct punctuation.definition.group.begin +// ^ meta.struct punctuation.section.group.begin // ^^^^^ meta.struct keyword.other -// ^ meta.struct punctuation.definition.group.end +// ^ meta.struct punctuation.section.group.end // ^^^ meta.struct storage.type pub(in super) i32, // ^^^ meta.struct storage.modifier -// ^ meta.struct punctuation.definition.group.begin +// ^ meta.struct punctuation.section.group.begin // ^^ meta.struct keyword.other // ^^^^^ meta.struct keyword.other -// ^ meta.struct punctuation.definition.group.end +// ^ meta.struct punctuation.section.group.end // ^^^ meta.struct storage.type ); From cfd004b203c5c2f0284ef2b9673a4715972fd3e3 Mon Sep 17 00:00:00 2001 From: wbond Date: Wed, 5 Apr 2017 10:39:05 -0400 Subject: [PATCH 08/22] [Rust] Update attributes to use standardized annotation scopes --- RustEnhanced.sublime-syntax | 57 +++++++++- tests/syntax-rust/syntax_test_attributes.rs | 117 +++++++++++++++++--- 2 files changed, 154 insertions(+), 20 deletions(-) diff --git a/RustEnhanced.sublime-syntax b/RustEnhanced.sublime-syntax index 3e308b16..f2434c3d 100644 --- a/RustEnhanced.sublime-syntax +++ b/RustEnhanced.sublime-syntax @@ -238,13 +238,66 @@ contexts: scope: storage.modifier.rust attribute: - - match: '#!?\[' + - match: '(#)\s*(!?)\s*(\[)' + captures: + 1: punctuation.definition.annotation.rust + 2: punctuation.definition.annotation.rust + 3: punctuation.section.group.begin.rust push: # https://github.com/sublimehq/Packages/issues/709#issuecomment-266835130 - meta_scope: meta.annotation.rust - - include: statements + - match: '(?:{{identifier}}\s*::\s*)*({{identifier}})' + scope: meta.path.rust + captures: + 1: variable.annotation.rust + - match: '\(' + scope: meta.annotation.parameters.rust meta.group.rust punctuation.section.group.begin.rust + push: + - meta_content_scope: meta.annotation.parameters.rust meta.group.rust + - match: \) + scope: meta.annotation.parameters.rust meta.group.rust punctuation.section.group.end.rust + pop: true + - include: attribute-call + - match: '=' + scope: keyword.operator.rust + set: + - meta_content_scope: meta.annotation.rust + - include: strings + - include: chars + - include: numbers + - include: comments + - match: '\]' + scope: meta.annotation.rust punctuation.section.group.end.rust + pop: true + - match: '\]' + scope: punctuation.section.group.end.rust pop: true + - include: comments + + attribute-call: + - match: \) + scope: meta.function-call.rust meta.group.rust punctuation.section.group.end.rust + pop: true + - match: '({{identifier}})\s*(\()' + scope: meta.function-call.rust + captures: + 1: variable.function.rust + 2: meta.group.rust punctuation.section.group.begin.rust + push: + - meta_content_scope: meta.function-call.rust + - include: attribute-call + - match: ',' + scope: punctuation.separator.rust + - match: '=' + scope: keyword.operator.rust + - include: strings + - include: chars + - include: numbers + - include: comments + - include: lifetime + - include: keywords + - include: symbols block: - match: '\}' diff --git a/tests/syntax-rust/syntax_test_attributes.rs b/tests/syntax-rust/syntax_test_attributes.rs index 34ab9ce4..35421d61 100644 --- a/tests/syntax-rust/syntax_test_attributes.rs +++ b/tests/syntax-rust/syntax_test_attributes.rs @@ -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.section.group.begin -// ^^^^^^ meta.group -// ^ meta.group punctuation.section.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 +// ^^^^^^^ 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 @@ -35,7 +47,7 @@ pub struct Claim { // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.annotation pub referring: Option, #[serde(skip_serializing_if="Option::is_none")] -// ^^^^^ support.function +// ^^^^^ variable.annotation // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.annotation pub drug: Option>, #[serde(skip_serializing_if="Option::is_none")] @@ -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 } @@ -59,3 +71,72 @@ enum E { unsafe impl<#[may_dangle] T: ?Sized> Drop for Box { } // ^^^^^^^^^^^^^ meta.annotation // ^^^^^^^^^^^^^^^^^^^^^^^^^ meta.impl meta.generic + + #[test = "foo ] bar"] +//^^^^^^^^^^^^^^^^^^^^^ meta.annotation +//^ punctuation.definition.annotation +// ^ punctuation.section.group.begin +// ^^^^ variable.annotation +// ^ keyword.operator +// ^^^^^^^^^^^ 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 +// ^ constant.numeric.integer.decimal + ) +// ^ punctuation.section.group.end + ] +//^ punctuation.section.group.end + +// quote! uses #var syntax +#[doc=#foo] +//^^^^^^^^^ meta.annotation +// ^ keyword.operator + +// Macros often use replacement. +#[doc = $doc] +//^^^^^^^^^^^ meta.annotation +// ^ punctuation.section.group.end +// ^ keyword.operator + +#[rustfmt::skip] +//^^^^^^^^^^^^^^ meta.annotation +//^^^^^^^^^^^^^ meta.path +// ^^^^ variable.annotation From dddd2718b4c721680ae98a465d14360156267f01 Mon Sep 17 00:00:00 2001 From: wbond Date: Wed, 5 Apr 2017 11:09:48 -0400 Subject: [PATCH 09/22] [Rust] Add punctuation.accessor scopes --- RustEnhanced.sublime-syntax | 16 +++++++++++----- tests/syntax-rust/syntax_test_modules.rs | 5 +++++ tests/syntax-rust/syntax_test_traits.rs | 1 + 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/RustEnhanced.sublime-syntax b/RustEnhanced.sublime-syntax index f2434c3d..3751f05d 100644 --- a/RustEnhanced.sublime-syntax +++ b/RustEnhanced.sublime-syntax @@ -572,14 +572,17 @@ contexts: pop: true - include: type-any-identifier - include: lifetime - - match: '\b([[:upper:]]|_*[[:upper:]][[:alnum:]_]*[[:lower:]][[:alnum:]_]*)\b::' + - match: '\b([[:upper:]]|_*[[:upper:]][[:alnum:]_]*[[:lower:]][[:alnum:]_]*)\b(::)' scope: meta.path.rust storage.type.rust captures: 1: storage.type.rust - - match: '{{identifier}}::' - scope: meta.path.rust - - match: '::(?={{identifier}})' + 2: punctuation.accessor.rust + - match: '{{identifier}}(::)' scope: meta.path.rust + captures: + 1: punctuation.accessor.rust + - match: '(::)(?={{identifier}})' + scope: meta.path.rust punctuation.accessor.rust - match: '(?=<)' push: generic-angles - match: '\(' @@ -1392,9 +1395,12 @@ contexts: - meta_scope: meta.path.rust - include: no-path-identifiers - match: '::' + scope: punctuation.accessor.rust set: no-type-names - - match: '::(?={{identifier}})' + - match: '(::)(?={{identifier}})' scope: meta.path.rust + captures: + 1: punctuation.accessor.rust push: no-type-names - include: no-path-identifiers diff --git a/tests/syntax-rust/syntax_test_modules.rs b/tests/syntax-rust/syntax_test_modules.rs index d3aef25b..d8a875de 100644 --- a/tests/syntax-rust/syntax_test_modules.rs +++ b/tests/syntax-rust/syntax_test_modules.rs @@ -35,23 +35,28 @@ pub use self::trafile::*; // ^^^ keyword.other // ^^^^ variable.language // ^^^^^^^^^^^^^^^ meta.path +// ^^ punctuation.accessor // ^ keyword.operator // ^ punctuation.terminator use std::fmt; // <- keyword.other // ^^^^^ meta.path +// ^^ punctuation.accessor // ^^^ - meta.path // ^ punctuation.terminator use foo::i32; // ^^^^^ meta.path +// ^^ punctuation.accessor // ^^^ - meta.path storage.type use foo::Bar; // ^^^^^ meta.path +// ^^ punctuation.accessor // ^^^ storage.type.source use foo::{Baz, QUX, quux}; // ^^^^^ meta.path +// ^^ punctuation.accessor.rust // ^^^^^^^^^^^^^^^^ meta.block // ^ punctuation.section.block.begin // ^^^ storage.type.source diff --git a/tests/syntax-rust/syntax_test_traits.rs b/tests/syntax-rust/syntax_test_traits.rs index 2d48d4c2..07e63402 100644 --- a/tests/syntax-rust/syntax_test_traits.rs +++ b/tests/syntax-rust/syntax_test_traits.rs @@ -32,6 +32,7 @@ impl fmt::Display for PrintableStruct { // <- storage.type.impl //^^ storage.type.impl // ^^^^^ meta.path +// ^^ punctuation.accessor // ^^^ keyword.other // ^^^^^^^^^^^^^^^ entity.name.impl // ^ meta.block punctuation.section.block.begin From 65c67175ecc18c9d79c0b5c9650858045a84d1bf Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Wed, 20 Dec 2017 14:35:11 +0200 Subject: [PATCH 10/22] [Rust] fix nested array template arguments --- RustEnhanced.sublime-syntax | 33 ++++++++++++++++++++++++--- tests/syntax-rust/syntax_test_expr.rs | 28 ++++++++++++++++++++++- 2 files changed, 57 insertions(+), 4 deletions(-) diff --git a/RustEnhanced.sublime-syntax b/RustEnhanced.sublime-syntax index 3751f05d..ae84c5c2 100644 --- a/RustEnhanced.sublime-syntax +++ b/RustEnhanced.sublime-syntax @@ -529,7 +529,7 @@ contexts: generic-angles-contents: - include: comments - include: attribute - - include: type-slice + - include: type-slice-or-array - match: '(?=>)' pop: true - match: '<' @@ -549,6 +549,21 @@ contexts: scope: invalid.illegal.rust pop: true + constant-integer-expression: + - include: integers + - match: \( + scope: punctuation.section.group.begin.rust + push: + - meta_scope: meta.group.rust + - match: \) + scope: punctuation.section.group.end.rust + pop: true + - include: constant-integer-expression + - match: '{{identifier}}' + scope: variable.other.constant.rust + - match: '[-+%/*]' + scope: keyword.operator.arithmetic.rust + type-any-identifier: - include: comments - include: support-type @@ -602,7 +617,7 @@ contexts: pop: true - include: hrtb - include: type - - include: type-slice + - include: type-slice-or-array - match: '\b_\b' scope: keyword.operator.rust - match: '!' @@ -626,13 +641,20 @@ contexts: - match: '(?=\S)' pop: true - type-slice: + type-slice-or-array: - match: '\[' scope: punctuation.section.group.begin.rust push: - match: '\]' scope: punctuation.section.group.end.rust pop: true + - match: ';' + scope: punctuation.separator.rust + set: + - match: '\]' + scope: punctuation.section.group.end.rust + pop: true + - include: constant-integer-expression - include: type-any-identifier struct-identifier: @@ -1351,6 +1373,10 @@ contexts: scope: constant.other.placeholder.rust numbers: + - include: floats + - include: integers + + floats: - match: '\b({{dec_literal}}(?:\.{{dec_literal}})?(?:{{float_exponent}})?)({{float_suffixes}})' captures: 1: constant.numeric.float.rust @@ -1362,6 +1388,7 @@ contexts: - match: '\b{{dec_literal}}\.(?![A-Za-z._''])' scope: constant.numeric.float.rust + integers: - match: '\b({{dec_literal}})({{int_suffixes}})?\b' captures: 1: constant.numeric.integer.decimal.rust diff --git a/tests/syntax-rust/syntax_test_expr.rs b/tests/syntax-rust/syntax_test_expr.rs index a24773a1..fbe1d8de 100644 --- a/tests/syntax-rust/syntax_test_expr.rs +++ b/tests/syntax-rust/syntax_test_expr.rs @@ -32,7 +32,7 @@ let tuple = (1.0, 0i32, "Hello"); // Tuple access. let x = tuple.1; -// ^ constant.numeric.integer.decimal.rust +// ^ constant.numeric.integer.decimal // Array access. let x = arr[1]; @@ -50,6 +50,32 @@ let x = [1; 2]; // ^ punctuation.terminator let x = [1; SOME_CONST]; // ^^^^^^^^^^ constant.other +let _: Box<[[bool; (FOO + 1) / 2]; FOO * 3 % 12 - 1]>; +// ^ punctuation.separator +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.generic +// ^ punctuation.definition.generic.begin +// ^^ punctuation.section.group.begin +// ^^^^ storage.type +// ^ punctuation.separator +// ^ meta.group punctuation.section.group.begin +// ^^^ variable.other.constant +// ^ keyword.operator.arithmetic +// ^ constant.numeric.integer.decimal +// ^ punctuation.section.group.end +// ^ keyword.operator.arithmetic +// ^ constant.numeric.integer.decimal +// ^ punctuation.section.group.end +// ^ punctuation.separator +// ^^^ variable.other.constant +// ^ keyword.operator.arithmetic +// ^ constant.numeric.integer.decimal +// ^ keyword.operator.arithmetic +// ^^ constant.numeric.integer.decimal +// ^ keyword.operator.arithmetic +// ^ constant.numeric.integer.decimal +// ^ punctuation.section.group.end +// ^ punctuation.definition.generic.end +// ^ punctuation.terminator // Borrow expression. let xsl = &xs; From 7e931b54f17d0b5c64ac34e78a2645a830036e0a Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Wed, 20 Dec 2017 14:53:08 +0200 Subject: [PATCH 11/22] [Rust] add punctuation accessor dot scope --- RustEnhanced.sublime-syntax | 10 +++++++--- tests/syntax-rust/syntax_test_macros.rs | 4 ++++ tests/syntax-rust/syntax_test_struct.rs | 3 +++ tests/syntax-rust/syntax_test_types.rs | 9 +++++++++ 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/RustEnhanced.sublime-syntax b/RustEnhanced.sublime-syntax index ae84c5c2..b71c4120 100644 --- a/RustEnhanced.sublime-syntax +++ b/RustEnhanced.sublime-syntax @@ -211,13 +211,14 @@ contexts: scope: punctuation.separator.rust push: after-operator - - match: '\b[[:lower:]_][[:lower:][:digit:]_]*(?=\()' scope: support.function.rust - - match: '{{identifier}}' + - match: '\b\.' + scope: punctuation.accessor.dot.rust + visibility: - match: '\b(pub)\s*(\()' captures: @@ -543,7 +544,7 @@ contexts: - match: '{{identifier}}' - match: ':|,' scope: punctuation.separator.rust - - match: '\+|\bas\b|=' + - match: '\+|=' scope: keyword.operator.rust - match: '(?=\S)' scope: invalid.illegal.rust @@ -573,6 +574,9 @@ contexts: - include: raw-pointer - match: \b(mut|ref|const|unsafe)\b scope: storage.modifier.rust + - match: '\bas\b' + # This is for qualified type paths + scope: keyword.operator.rust - match: \b(fn)\b\s*(\() captures: 1: storage.type.function.rust diff --git a/tests/syntax-rust/syntax_test_macros.rs b/tests/syntax-rust/syntax_test_macros.rs index f1ec5ab0..1c33bbe0 100644 --- a/tests/syntax-rust/syntax_test_macros.rs +++ b/tests/syntax-rust/syntax_test_macros.rs @@ -62,6 +62,8 @@ my_var = format!("Hello {name}, how are you?", // ^ punctuation.section.group.begin // ^^^^ string.quoted.double // ^^ constant.other.placeholder +// ^^^^ variable.language +// ^ punctuation.accessor.dot // ^ punctuation.section.group.end write!(f, "{:10}", self.0) // ^^^^^ constant.other.placeholder @@ -212,6 +214,7 @@ macro_rules! forward_ref_binop [ // ^ meta.macro meta.macro.transcribers meta.impl meta.block punctuation.section.block.begin type Output = <$t as $imp<$u>>::Output; // ^^^^^^^^^^^^^^^^ meta.generic +// ^^ keyword.operator // ^^ meta.path #[inline] @@ -225,6 +228,7 @@ macro_rules! forward_ref_binop [ // ^^ variable.other // ^^ punctuation.separator // ^^^^^^^^^^^^^^^^ meta.generic +// ^^ keyword.operator // ^^ meta.path // ^ meta.macro meta.macro.transcribers meta.impl meta.block meta.block punctuation.section.block.begin $imp::$method(*self, *other) diff --git a/tests/syntax-rust/syntax_test_struct.rs b/tests/syntax-rust/syntax_test_struct.rs index 047ad7b6..77daded1 100644 --- a/tests/syntax-rust/syntax_test_struct.rs +++ b/tests/syntax-rust/syntax_test_struct.rs @@ -64,6 +64,9 @@ impl Point fn double(&mut self) { // ^^^^^^ entity.name.function self.x *= 2; + // ^^^^ variable.language + // ^ punctuation.accessor.dot + // ^^ keyword.operator self.y *= 2; } } diff --git a/tests/syntax-rust/syntax_test_types.rs b/tests/syntax-rust/syntax_test_types.rs index bca07108..067f701b 100644 --- a/tests/syntax-rust/syntax_test_types.rs +++ b/tests/syntax-rust/syntax_test_types.rs @@ -158,3 +158,12 @@ fn f(string: &str) -> StrWrap<'_> { } // Never type. fn from_str() -> Result {} // ^ meta.function meta.function.return-type meta.generic keyword.operator + +// Qualified path with type. +// Note: This isn't actually a generics, but that gets reused for this purpose. +type Item = ::Item; +// ^^^^^^^^^^^^^^^ meta.generic +// ^^ keyword.operator +// ^^^^^^^^ support.type +// ^^ punctuation.accessor +// ^^^^ storage.type.source From e38dab5e63ac39ed4cb6db70901deefbe42a5aea Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Wed, 20 Dec 2017 14:59:02 +0200 Subject: [PATCH 12/22] [Rust] scope punctuation accessor dot after a function call --- RustEnhanced.sublime-syntax | 2 +- tests/syntax-rust/syntax_test_generics.rs | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/RustEnhanced.sublime-syntax b/RustEnhanced.sublime-syntax index b71c4120..c5943a0c 100644 --- a/RustEnhanced.sublime-syntax +++ b/RustEnhanced.sublime-syntax @@ -216,7 +216,7 @@ contexts: - match: '{{identifier}}' - - match: '\b\.' + - match: '\.' scope: punctuation.accessor.dot.rust visibility: diff --git a/tests/syntax-rust/syntax_test_generics.rs b/tests/syntax-rust/syntax_test_generics.rs index df94be98..27ce7cec 100644 --- a/tests/syntax-rust/syntax_test_generics.rs +++ b/tests/syntax-rust/syntax_test_generics.rs @@ -230,6 +230,17 @@ fn collect_vec() { // ^^^^^ storage.type // ^^^^^ storage.type // ^ punctuation.section.group.end +// ^ keyword.operator +// ^ punctuation.section.group.begin +// ^ constant.numeric.integer.decimal +// ^^ keyword.operator +// ^^ constant.numeric.integer.decimal +// ^ punctuation.section.group.end +// ^ punctuation.accessor.dot +// ^^^^^^^^^ support.function +// ^^ punctuation.section.group +// ^ punctuation.accessor.dot +// ^^ punctuation.accessor // ^^^^^^^^ meta.generic // ^^^^^^ meta.generic meta.generic // ^ keyword.operator From a5389341867424e9d86be89de1de93dafe4f6279 Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Wed, 28 Nov 2018 06:18:38 +0200 Subject: [PATCH 13/22] [Rust] support paths to constants for sizes in nested array types (#1748) --- RustEnhanced.sublime-syntax | 2 ++ tests/syntax-rust/syntax_test_expr.rs | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/RustEnhanced.sublime-syntax b/RustEnhanced.sublime-syntax index c5943a0c..6b27d068 100644 --- a/RustEnhanced.sublime-syntax +++ b/RustEnhanced.sublime-syntax @@ -562,6 +562,8 @@ contexts: - include: constant-integer-expression - match: '{{identifier}}' scope: variable.other.constant.rust + - match: '::' + scope: punctuation.accessor.double-colon.rust - match: '[-+%/*]' scope: keyword.operator.arithmetic.rust diff --git a/tests/syntax-rust/syntax_test_expr.rs b/tests/syntax-rust/syntax_test_expr.rs index fbe1d8de..e1a28db7 100644 --- a/tests/syntax-rust/syntax_test_expr.rs +++ b/tests/syntax-rust/syntax_test_expr.rs @@ -76,6 +76,23 @@ let _: Box<[[bool; (FOO + 1) / 2]; FOO * 3 % 12 - 1]>; // ^ punctuation.section.group.end // ^ punctuation.definition.generic.end // ^ punctuation.terminator +let _: Box<[[u8; aa::COUNT - 1]; 5]>; +// ^ punctuation.definition.generic.begin +// ^ punctuation.section.group.begin +// ^ punctuation.section.group.begin +// ^^ storage.type +// ^ punctuation.separator +// ^^ variable.other.constant +// ^^ punctuation.accessor.double-colon +// ^^^^^ variable.other.constant +// ^ keyword.operator.arithmetic +// ^ constant.numeric.integer.decimal +// ^ punctuation.section.group.end +// ^ punctuation.separator +// ^ constant.numeric.integer.decimal +// ^ punctuation.section.group.end +// ^ punctuation.definition.generic.end +// ^ punctuation.terminator // Borrow expression. let xsl = &xs; From 92e94c029ddc9542fa99a2d3a057e31106cea452 Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Mon, 7 Jan 2019 19:36:16 +0200 Subject: [PATCH 14/22] [Rust] scope support types in generics (#1820) --- RustEnhanced.sublime-syntax | 1 + tests/syntax-rust/syntax_test_generics.rs | 4 ++++ tests/syntax-rust/syntax_test_struct.rs | 1 + 3 files changed, 6 insertions(+) diff --git a/RustEnhanced.sublime-syntax b/RustEnhanced.sublime-syntax index 6b27d068..4c5c61bb 100644 --- a/RustEnhanced.sublime-syntax +++ b/RustEnhanced.sublime-syntax @@ -130,6 +130,7 @@ contexts: 1: keyword.control.rust 2: entity.name.label.rust + - include: support-type - include: type - match: '\b(macro_rules!)\s+({{identifier}})\b' diff --git a/tests/syntax-rust/syntax_test_generics.rs b/tests/syntax-rust/syntax_test_generics.rs index 27ce7cec..be109610 100644 --- a/tests/syntax-rust/syntax_test_generics.rs +++ b/tests/syntax-rust/syntax_test_generics.rs @@ -226,6 +226,7 @@ fn numbers() -> impl Iterator { fn collect_vec() { let _: Vec<(usize, usize)> = (0..10).enumerate().collect::>(); // ^^^^^^^^^^^^^^^^^^^ meta.generic +// ^^^ support.type // ^ punctuation.section.group.begin // ^^^^^ storage.type // ^^^^^ storage.type @@ -241,6 +242,7 @@ fn collect_vec() { // ^^ punctuation.section.group // ^ punctuation.accessor.dot // ^^ punctuation.accessor +// ^^^ support.type // ^^^^^^^^ meta.generic // ^^^^^^ meta.generic meta.generic // ^ keyword.operator @@ -250,6 +252,8 @@ fn collect_vec() { // ^^^^ support.macro let _: Vec<(usize, usize)> = vec![]; // ^^^^ support.macro + let _: Vec = vec![]; +// ^^^^^^ meta.generic support.type } diff --git a/tests/syntax-rust/syntax_test_struct.rs b/tests/syntax-rust/syntax_test_struct.rs index 77daded1..ea64388d 100644 --- a/tests/syntax-rust/syntax_test_struct.rs +++ b/tests/syntax-rust/syntax_test_struct.rs @@ -16,6 +16,7 @@ struct PrintableStruct(Box); // ^^^^^^^^^^^^^^^ entity.name.struct // ^ punctuation.section.group.begin // ^^^^^^^^ meta.generic +// ^^^ support.type // ^ punctuation.definition.generic.begin // ^^^ storage.type // ^ punctuation.definition.generic.end From 863667cd51c839e92f0bcc16566cb336d19704cb Mon Sep 17 00:00:00 2001 From: FichteFoll Date: Mon, 4 Feb 2019 16:50:51 +0100 Subject: [PATCH 15/22] [Rust] Refine operator matches (for ligatures) (#1846) Most operators were matched character-wise which breaks ligatures. Also add more refined scope names where applicable. --- RustEnhanced.sublime-syntax | 43 +++++----- tests/syntax-rust/syntax_test_attributes.rs | 10 +-- tests/syntax-rust/syntax_test_closures.rs | 2 +- tests/syntax-rust/syntax_test_control_flow.rs | 8 +- tests/syntax-rust/syntax_test_enum.rs | 2 +- tests/syntax-rust/syntax_test_expr.rs | 84 +++++++++---------- tests/syntax-rust/syntax_test_functions.rs | 2 +- tests/syntax-rust/syntax_test_literals.rs | 14 ++-- tests/syntax-rust/syntax_test_macros.rs | 6 +- tests/syntax-rust/syntax_test_match.rs | 8 +- tests/syntax-rust/syntax_test_punct.rs | 40 +++++++++ tests/syntax-rust/syntax_test_struct.rs | 2 +- tests/syntax-rust/syntax_test_types.rs | 8 +- 13 files changed, 136 insertions(+), 93 deletions(-) diff --git a/RustEnhanced.sublime-syntax b/RustEnhanced.sublime-syntax index 4c5c61bb..4f346944 100644 --- a/RustEnhanced.sublime-syntax +++ b/RustEnhanced.sublime-syntax @@ -58,7 +58,7 @@ contexts: - match: '\b({{identifier}})\s*(=)\s*(?=\|)' captures: 1: entity.name.function.rust - 2: keyword.operator.rust + 2: keyword.operator.assignment.rust push: closure - match: '\b(fn)\s+(?={{identifier}})' @@ -80,7 +80,7 @@ contexts: 2: entity.name.type.rust push: - match: '=(?!=)' - scope: keyword.operator.rust + scope: keyword.operator.assignment.rust push: after-operator - match: '(?=\S)' pop: true @@ -261,7 +261,7 @@ contexts: pop: true - include: attribute-call - match: '=' - scope: keyword.operator.rust + scope: keyword.operator.assignment.rust set: - meta_content_scope: meta.annotation.rust - include: strings @@ -292,7 +292,7 @@ contexts: - match: ',' scope: punctuation.separator.rust - match: '=' - scope: keyword.operator.rust + scope: keyword.operator.assignment.rust - include: strings - include: chars - include: numbers @@ -1461,33 +1461,36 @@ contexts: # match blocks containing just enums scope: keyword.operator.rust - - match: '=(?!=)' + - match: '<-|->' scope: keyword.operator.rust - - match: '[:;,]' - scope: punctuation.separator.rust + - match: '\.\.\.|\.\.=|\.\.' + scope: keyword.operator.range.rust - - match: '\.\.\.' - scope: keyword.operator.rust + - match: '[!<>=]=' + scope: keyword.operator.comparison.rust - - match: '\.\.' - scope: keyword.operator.rust + - match: '(?:[-+%/*^&|]|<<|>>)?=' + scope: keyword.operator.assignment.rust - - match: '<<=|>>=|<<|>>' - scope: keyword.operator.rust + - match: '&&|\|\||!' + scope: keyword.operator.logical.rust - - match: '>=|<=|==|!=|&&|\|\|' - scope: keyword.operator.rust + - match: '[&|^]|<<|>>' + scope: keyword.operator.bitwise.rust - - match: '\*=|/=|\+=|-=|%=|\^=|&=|\|=' - scope: keyword.operator.rust + - match: '[<>]' + scope: keyword.operator.comparison.rust - - match: '[-=<>&|!~@?+*/%^''#$]' - scope: keyword.operator.rust + - match: '[-+%/*]' + scope: keyword.operator.arithmetic.rust - - match: '<-|->' + - match: '[@~?$#'']' scope: keyword.operator.rust + - match: '[:;,]' + scope: punctuation.separator.rust + keywords: # All keywords. Note in `statements` some of these are superseded by more # specific rules. diff --git a/tests/syntax-rust/syntax_test_attributes.rs b/tests/syntax-rust/syntax_test_attributes.rs index 35421d61..0296f84d 100644 --- a/tests/syntax-rust/syntax_test_attributes.rs +++ b/tests/syntax-rust/syntax_test_attributes.rs @@ -28,7 +28,7 @@ // ^ punctuation.separator // ^^^ meta.function-call meta.function-call variable.function // ^ punctuation.section.group.begin -// ^ keyword.operator +// ^ keyword.operator.assignment // ^^^^^^^ string.quoted.double // ^ punctuation.section.group.end // ^ punctuation.section.group.end @@ -77,7 +77,7 @@ unsafe impl<#[may_dangle] T: ?Sized> Drop for Box { } //^ punctuation.definition.annotation // ^ punctuation.section.group.begin // ^^^^ variable.annotation -// ^ keyword.operator +// ^ keyword.operator.assignment // ^^^^^^^^^^^ string.quoted.double // ^ punctuation.section.group.end @@ -118,7 +118,7 @@ unsafe impl<#[may_dangle] T: ?Sized> Drop for Box { } // ^^^^^^ storage.type.struct 1 + 1, // ^ constant.numeric.integer.decimal -// ^ keyword.operator +// ^ keyword.operator.arithmetic // ^ constant.numeric.integer.decimal ) // ^ punctuation.section.group.end @@ -128,13 +128,13 @@ unsafe impl<#[may_dangle] T: ?Sized> Drop for Box { } // quote! uses #var syntax #[doc=#foo] //^^^^^^^^^ meta.annotation -// ^ keyword.operator +// ^ keyword.operator.assignment // Macros often use replacement. #[doc = $doc] //^^^^^^^^^^^ meta.annotation // ^ punctuation.section.group.end -// ^ keyword.operator +// ^ keyword.operator.assignment #[rustfmt::skip] //^^^^^^^^^^^^^^ meta.annotation diff --git a/tests/syntax-rust/syntax_test_closures.rs b/tests/syntax-rust/syntax_test_closures.rs index 54e0168f..e67e4468 100644 --- a/tests/syntax-rust/syntax_test_closures.rs +++ b/tests/syntax-rust/syntax_test_closures.rs @@ -26,7 +26,7 @@ let closure = || -> i32 { | | 1 + 2 }; // 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 diff --git a/tests/syntax-rust/syntax_test_control_flow.rs b/tests/syntax-rust/syntax_test_control_flow.rs index 5bfa2953..dd9b20ca 100644 --- a/tests/syntax-rust/syntax_test_control_flow.rs +++ b/tests/syntax-rust/syntax_test_control_flow.rs @@ -9,7 +9,7 @@ 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 @@ -23,7 +23,7 @@ for i in 1..10 { // ^ meta.block punctuation.section.block.begin n += 1; if n / 2 == 5 { -// ^ keyword.operator +// ^ keyword.operator.arithmetic continue; // ^^^^^^^^ keyword.control } @@ -72,7 +72,7 @@ if n < 0 { if let BasicStruct(i) = j { // ^^^ storage.type -// ^ keyword.operator +// ^ keyword.operator.assignment // ^ meta.block punctuation.section.block.begin println!("Basic value: {}", i); } @@ -81,7 +81,7 @@ if let BasicStruct(i) = j { while let BasicStruct(k) = j { //^^^ keyword.control // ^^^ storage.type -// ^ keyword.operator +// ^ keyword.operator.assignment // ^ meta.block punctuation.section.block.begin println!("Constructed example: {}", j) j = BasicStruct(j + 1); diff --git a/tests/syntax-rust/syntax_test_enum.rs b/tests/syntax-rust/syntax_test_enum.rs index d27fb9ec..e7356faf 100644 --- a/tests/syntax-rust/syntax_test_enum.rs +++ b/tests/syntax-rust/syntax_test_enum.rs @@ -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 diff --git a/tests/syntax-rust/syntax_test_expr.rs b/tests/syntax-rust/syntax_test_expr.rs index e1a28db7..a3c5d29e 100644 --- a/tests/syntax-rust/syntax_test_expr.rs +++ b/tests/syntax-rust/syntax_test_expr.rs @@ -3,21 +3,21 @@ // specific categories. let big_n = -// ^ keyword.operator +// ^ keyword.operator.assignment if n < 10 && n > -10 { -// ^ keyword.operator -// ^^ keyword.operator -// ^ keyword.operator -// ^ keyword.operator +// ^ keyword.operator.comparison +// ^^ keyword.operator.logical +// ^ keyword.operator.comparison +// ^ keyword.operator.arithmetic // ^^ constant.numeric.integer.decimal // ^ meta.block punctuation.section.block.begin 10 * n -// ^ meta.block keyword.operator +// ^ meta.block keyword.operator.arithmetic } else { // ^ meta.block punctuation.section.block.end // ^ meta.block punctuation.section.block.begin n / 2 -// ^ meta.block keyword.operator +// ^ meta.block keyword.operator.arithmetic }; // ^ meta.block punctuation.section.block.end @@ -98,72 +98,72 @@ let _: Box<[[u8; aa::COUNT - 1]; 5]>; let xsl = &xs; // ^ keyword.operator let a = && 10; -// ^^ keyword.operator +// ^^ keyword.operator.logical let a = & & 10; -// ^ keyword.operator -// ^ keyword.operator +// ^ keyword.operator.bitwise +// ^ keyword.operator.bitwise let y = &mut 9; // ^ keyword.operator // ^^^ storage.modifier // Dereference. assert_eq!(*x, 7); -// ^ meta.group keyword.operator +// ^ meta.group keyword.operator.arithmetic *y = 11; -// ^ keyword.operator +// ^ keyword.operator.arithmetic // Block expression. let z = { // ^ meta.block punctuation.section.block.begin 2 * 5 // ^ constant.numeric.integer.decimal -// ^ keyword.operator +// ^ keyword.operator.arithmetic // ^ constant.numeric.integer.decimal }; // <- meta.block punctuation.section.block.end // Various operators. let x = !6; -// ^ keyword.operator +// ^ keyword.operator.logical // ^ constant.numeric.integer.decimal let a = 1 + 2 - 3 * 4 / 6 % 7 & 8 | 9 ^ a << b >> c; -// ^ keyword.operator -// ^ keyword.operator -// ^ keyword.operator -// ^ keyword.operator -// ^ keyword.operator -// ^ keyword.operator -// ^ keyword.operator -// ^ keyword.operator -// ^^ keyword.operator -// ^^ keyword.operator +// ^ keyword.operator.arithmetic +// ^ keyword.operator.arithmetic +// ^ keyword.operator.arithmetic +// ^ keyword.operator.arithmetic +// ^ keyword.operator.arithmetic +// ^ keyword.operator.bitwise +// ^ keyword.operator.bitwise +// ^ keyword.operator.bitwise +// ^^ keyword.operator.bitwise +// ^^ keyword.operator.bitwise a == b != c > d < e >= f <= g -// ^^ keyword.operator -// ^^ keyword.operator -// ^ keyword.operator -// ^ keyword.operator -// ^^ keyword.operator -// ^^ keyword.operator +// ^^ keyword.operator.comparison +// ^^ keyword.operator.comparison +// ^ keyword.operator.comparison +// ^ keyword.operator.comparison +// ^^ keyword.operator.comparison +// ^^ keyword.operator.comparison a || b && c -// ^^ keyword.operator -// ^^ keyword.operator +// ^^ keyword.operator.logical +// ^^ keyword.operator.logical a += b; -//^^ keyword.operator +//^^ keyword.operator.assignment a -= b; -//^^ keyword.operator +//^^ keyword.operator.assignment a *= b; -//^^ keyword.operator +//^^ keyword.operator.assignment a /= b; -//^^ keyword.operator +//^^ keyword.operator.assignment a %= b; -//^^ keyword.operator +//^^ keyword.operator.assignment a &= b; -//^^ keyword.operator +//^^ keyword.operator.assignment a |= b; -//^^ keyword.operator +//^^ keyword.operator.assignment a ^= b; -//^^ keyword.operator +//^^ keyword.operator.assignment a <<= b; -//^^^ keyword.operator +//^^^ keyword.operator.assignment a >>= b; -//^^^ keyword.operator +//^^^ keyword.operator.assignment diff --git a/tests/syntax-rust/syntax_test_functions.rs b/tests/syntax-rust/syntax_test_functions.rs index 60aa9dd2..6518e46f 100644 --- a/tests/syntax-rust/syntax_test_functions.rs +++ b/tests/syntax-rust/syntax_test_functions.rs @@ -63,7 +63,7 @@ let f: extern "C" fn () = mem::transmute(0xffff0fa0u32); // ^^^ string.quoted.double // ^^ storage.type.function // ^^ meta.group -// ^ keyword.operator +// ^ keyword.operator.assignment // ^^^^^^^^^^ meta.group constant.numeric.integer.hexadecimal // ^^^ meta.group storage.type.numeric diff --git a/tests/syntax-rust/syntax_test_literals.rs b/tests/syntax-rust/syntax_test_literals.rs index 8c1ae361..9d92384e 100644 --- a/tests/syntax-rust/syntax_test_literals.rs +++ b/tests/syntax-rust/syntax_test_literals.rs @@ -2,11 +2,11 @@ let c = 'c'; // <- storage.type -// ^ keyword.operator +// ^ keyword.operator.assignment // ^^^ string.quoted.single let b = b'c'; // <- storage.type -// ^ keyword.operator +// ^ keyword.operator.assignment // ^ storage.type // ^^^ string.quoted.single let ch = '∞'; @@ -14,7 +14,7 @@ let ch = '∞'; let s = "This is a string \x01_\u{007F}_\"_\'_\\_\r_\n_\t_\0"; // <- storage.type -// ^ keyword.operator +// ^ keyword.operator.assignment // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.double // ^^^^ constant.character.escape // ^^^^^^^^ constant.character.escape @@ -27,7 +27,7 @@ let s = "This is a string \x01_\u{007F}_\"_\'_\\_\r_\n_\t_\0"; // ^^ constant.character.escape let r = r#"This is a raw string, no escapes! \x00 \0 \n"#; // <- storage.type -// ^ keyword.operator +// ^ keyword.operator.assignment // ^ storage.type // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.double - constant.character.escape @@ -45,7 +45,7 @@ println!("Continuation in format \ let bytes = b"This won't escape unicode \u{0123}, but will do \x01_\"_\'_\\_\r_\n_\t_\0"; // <- storage.type -// ^ keyword.operator +// ^ keyword.operator.assignment // ^ storage.type // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.double // ^^^^ constant.character.escape @@ -59,7 +59,7 @@ let bytes = b"This won't escape unicode \u{0123}, but will do \x01_\"_\'_\\_\r_\ let raw_bytes = br#"This won't escape anything either \x01 \""#; // <- storage.type -// ^ keyword.operator +// ^ keyword.operator.assignment // ^^ storage.type // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.double - constant.character.escape @@ -249,5 +249,5 @@ let s_uni_esc_extra = "\u{1234567}"; let logical: bool = true; // ^ punctuation.separator // ^^^^ storage.type -// ^ keyword.operator +// ^ keyword.operator.assignment // ^^^^ constant.language diff --git a/tests/syntax-rust/syntax_test_macros.rs b/tests/syntax-rust/syntax_test_macros.rs index 1c33bbe0..ebfb0153 100644 --- a/tests/syntax-rust/syntax_test_macros.rs +++ b/tests/syntax-rust/syntax_test_macros.rs @@ -2,7 +2,7 @@ String my_var = format!("Hello {0}", "World"); // ^^^ support.type -// ^ keyword.operator +// ^ keyword.operator.assignment // ^^^^^^^ support.macro // ^ punctuation.section.group.begin // ^^^^^^^^^^^^^^^^^^^^^^ meta.group @@ -44,7 +44,7 @@ pub fn macro_tests() { } my_var = format!("Hello {name}, how are you?", -// ^ keyword.operator +// ^ keyword.operator.assignment // ^^^^^^^ support.macro // ^ punctuation.section.group.begin // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group @@ -52,7 +52,7 @@ my_var = format!("Hello {name}, how are you?", // ^^^^^^ constant.other.placeholder name="John"); // ^^^^^^^^^^^^^ meta.group -// ^ keyword.operator +// ^ keyword.operator.assignment // ^^^^^^ string.quoted.double // ^ punctuation.section.group.end diff --git a/tests/syntax-rust/syntax_test_match.rs b/tests/syntax-rust/syntax_test_match.rs index 3ff5d106..e1f3b917 100644 --- a/tests/syntax-rust/syntax_test_match.rs +++ b/tests/syntax-rust/syntax_test_match.rs @@ -12,7 +12,7 @@ let o = match n { // ^^^^^ string.quoted.double 3...5 => "a few", // ^ constant.numeric.integer.decimal -// ^^^ keyword.operator +// ^^^ keyword.operator.range // ^ constant.numeric.integer.decimal // ^^ keyword.operator // ^^^^^^^ string.quoted.double @@ -26,12 +26,12 @@ match n { // <- keyword.control a if n > 5 => println!("Big: {}", a), // ^^ keyword.control -// ^ keyword.operator +// ^ keyword.operator.comparison // ^^ keyword.operator // ^^^^^^^^ support.macro b if n <= 5 => println!("Small: {}", b), // ^^ keyword.control -// ^^ keyword.operator +// ^^ keyword.operator.comparison // ^^ keyword.operator // ^^^^^^^^ support.macro // ^^ constant.other.placeholder @@ -48,7 +48,7 @@ match my_func() { // ^^^^^^^^ support.macro res @ 1...9 => println!("Digit: {}", res), // ^ keyword.operator -// ^^^ keyword.operator +// ^^^ keyword.operator.range // ^^ constant.other.placeholder _ => println!("Full number"), // ^ source diff --git a/tests/syntax-rust/syntax_test_punct.rs b/tests/syntax-rust/syntax_test_punct.rs index adadcadc..364a5162 100644 --- a/tests/syntax-rust/syntax_test_punct.rs +++ b/tests/syntax-rust/syntax_test_punct.rs @@ -140,3 +140,43 @@ match a { } use a::{a,b}; // ^ punctuation.separator + + +/************* ligatures *************/ +// This is mostly for visual inspection. +foo!{<- -> =>} // emplacement token (unused in language) +// ^^ keyword.operator +// ^^ punctuation.separator +// ^^ keyword.operator +fn f() -> i32 {1} +// ^^ punctuation.separator + a && b || c; +// ^^ keyword.operator.logical +// ^^ keyword.operator.logical + 1 << 2 >> 3; +// ^^ keyword.operator.bitwise +// ^^ keyword.operator.bitwise + a += 1; b -= 1; c *= 1; d /= 1; e %= 1; f ^= 1; g &= 1; h |= 1; +// ^^ keyword.operator.assignment +// ^^ keyword.operator.assignment +// ^^ keyword.operator.assignment +// ^^ keyword.operator.assignment +// ^^ keyword.operator.assignment +// ^^ keyword.operator.assignment +// ^^ keyword.operator.assignment +// ^^ keyword.operator.assignment + a <<= 1; b >>= 2; +// ^^^ keyword.operator.assignment +// ^^^ keyword.operator.assignment + x == y; x != y; +// ^^ keyword.operator.comparison +// ^^ keyword.operator.comparison + a >= b; a <= b; +// ^^ keyword.operator.comparison +// ^^ keyword.operator.comparison + 1..2; 1...2; 1..=2; +//^^ keyword.operator.range +// ^^^ keyword.operator.range +// ^^^ keyword.operator.range +match x { a => {}} +// ^^ meta.block keyword.operator diff --git a/tests/syntax-rust/syntax_test_struct.rs b/tests/syntax-rust/syntax_test_struct.rs index ea64388d..df73d68f 100644 --- a/tests/syntax-rust/syntax_test_struct.rs +++ b/tests/syntax-rust/syntax_test_struct.rs @@ -67,7 +67,7 @@ impl Point self.x *= 2; // ^^^^ variable.language // ^ punctuation.accessor.dot - // ^^ keyword.operator + // ^^ keyword.operator.assignment self.y *= 2; } } diff --git a/tests/syntax-rust/syntax_test_types.rs b/tests/syntax-rust/syntax_test_types.rs index 067f701b..ddd2b715 100644 --- a/tests/syntax-rust/syntax_test_types.rs +++ b/tests/syntax-rust/syntax_test_types.rs @@ -36,7 +36,7 @@ const ZERO: u64 = 0; // ^^^^ entity.name.constant // ^ punctuation.separator // ^^^ storage.type -// ^ keyword.operator +// ^ keyword.operator.assignment // ^ constant.numeric.integer.decimal static NAME: &'static str = "John"; // <- storage.type @@ -44,7 +44,7 @@ static NAME: &'static str = "John"; // ^ keyword.operator // ^^^^^^^ storage.modifier.lifetime // ^^^ storage.type -// ^ keyword.operator +// ^ keyword.operator.assignment // ^^^^^^ string.quoted.double static mut BRAVO: u32 = 0; // <- storage.type @@ -79,7 +79,7 @@ type Pair<'a> = (i32, &'a str); // ^ keyword.operator // ^^ storage.modifier.lifetime // ^ keyword.operator -// ^ keyword.operator +// ^ keyword.operator.assignment // ^^^^^^^^^^^^^^ meta.group // ^ punctuation.section.group.begin // ^^^ storage.type @@ -95,7 +95,7 @@ let p: Pair<'static> = (10, "ten"); // ^ punctuation.definition.generic.begin // ^^^^^^^ storage.modifier.lifetime // ^ punctuation.definition.generic.end -// ^ keyword.operator +// ^ keyword.operator.assignment // ^^^^^^^^^^^ meta.group // ^ punctuation.section.group.begin // ^^ constant.numeric.integer.decimal From 7aec4e3c7272a1dd0d3356cbbaa1c375872ff13a Mon Sep 17 00:00:00 2001 From: FichteFoll Date: Mon, 4 Feb 2019 16:51:12 +0100 Subject: [PATCH 16/22] [Rust] Fix raw string punctuation (#1847) --- RustEnhanced.sublime-syntax | 4 ++-- tests/syntax-rust/syntax_test_literals.rs | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/RustEnhanced.sublime-syntax b/RustEnhanced.sublime-syntax index 4f346944..9f5e745e 100644 --- a/RustEnhanced.sublime-syntax +++ b/RustEnhanced.sublime-syntax @@ -1321,14 +1321,14 @@ contexts: scope: punctuation.separator.continuation.line.rust raw-string: - - match: (r)(#*)" + - match: (r)((#*)") 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: '"\2' + - match: '"\3' scope: punctuation.definition.string.end.rust pop: true diff --git a/tests/syntax-rust/syntax_test_literals.rs b/tests/syntax-rust/syntax_test_literals.rs index 9d92384e..f61d4b24 100644 --- a/tests/syntax-rust/syntax_test_literals.rs +++ b/tests/syntax-rust/syntax_test_literals.rs @@ -25,12 +25,14 @@ let s = "This is a string \x01_\u{007F}_\"_\'_\\_\r_\n_\t_\0"; // ^^ constant.character.escape // ^^ constant.character.escape // ^^ constant.character.escape -let r = r#"This is a raw string, no escapes! \x00 \0 \n"#; +let r = r##"This is a raw string, no escapes! \x00 \0 \n"##; // <- storage.type // ^ keyword.operator.assignment // ^ storage.type -// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.double - constant.character.escape - +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.double.raw - constant.character.escape +// ^^^ punctuation.definition.string.begin.rust +// ^^^ punctuation.definition.string.end.rust +// ^ - string let s = "\ // ^ string.quoted.double punctuation.separator.continuation.line continued \ From 46d3851ef34aa7113e73159fb7036d9565c64f43 Mon Sep 17 00:00:00 2001 From: DavidWang1024 <51687325+DavidWang1024@users.noreply.github.com> Date: Wed, 31 Jul 2019 20:47:41 +1000 Subject: [PATCH 17/22] [Rust] Add scope to leading asterisk on each line in multiline comments (#1995) This will be utilized by the built-in word wrapping functionality --- RustEnhanced.sublime-syntax | 4 ++++ tests/syntax-rust/syntax_test_comments.rs | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/RustEnhanced.sublime-syntax b/RustEnhanced.sublime-syntax index 9f5e745e..b1b93c11 100644 --- a/RustEnhanced.sublime-syntax +++ b/RustEnhanced.sublime-syntax @@ -1193,6 +1193,10 @@ contexts: - match: \*/ scope: punctuation.definition.comment.rust pop: true + # Javadoc style comment with leading * on each line. Helps with word-wrapping. + - match: ^\s*(\*)(?!/) + captures: + 1: punctuation.definition.comment.rust - include: block-comments - match: /\* scope: punctuation.definition.comment.rust diff --git a/tests/syntax-rust/syntax_test_comments.rs b/tests/syntax-rust/syntax_test_comments.rs index 0de2a4bf..e1a5025b 100644 --- a/tests/syntax-rust/syntax_test_comments.rs +++ b/tests/syntax-rust/syntax_test_comments.rs @@ -20,6 +20,11 @@ Block doc comments // ^^^^^^^^^^^^^^^^^^ comment.block.documentation comment.block */ +/** + * +// ^ comment.block.documentation punctuation.definition.comment +*/ + // Verify comment is cleared. mod a {} // ^^^^^ -comment From b8e33929a302a08265909a77bf68cf40804352e6 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Sun, 1 Mar 2020 10:12:20 -0800 Subject: [PATCH 18/22] Add missing meta.block for tuple types. --- RustEnhanced.sublime-syntax | 1 + tests/syntax-rust/syntax_test_types.rs | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/RustEnhanced.sublime-syntax b/RustEnhanced.sublime-syntax index b1b93c11..c7770f6c 100644 --- a/RustEnhanced.sublime-syntax +++ b/RustEnhanced.sublime-syntax @@ -610,6 +610,7 @@ contexts: - match: '\(' scope: punctuation.section.group.begin.rust push: + - meta_scope: meta.group.rust - match: '\)' scope: punctuation.section.group.end.rust pop: true diff --git a/tests/syntax-rust/syntax_test_types.rs b/tests/syntax-rust/syntax_test_types.rs index ddd2b715..bd144a0b 100644 --- a/tests/syntax-rust/syntax_test_types.rs +++ b/tests/syntax-rust/syntax_test_types.rs @@ -102,6 +102,13 @@ let p: Pair<'static> = (10, "ten"); // ^^^^^ string.quoted.double // ^ punctuation.section.group.end // ^ punctuation.terminator +fn tuple(x: (u32, u32)) {} +// ^^^^^^^^^^ meta.group +// ^ meta.group punctuation.section.group.begin +// ^^^ storage.type +// ^ punctuation.separator +// ^^^ storage.type +// ^ meta.group punctuation.section.group.end // Array types. let xs: [i32; 5] = [1, 2, 3, 4, 5]; From d73c919e5638d4cb9d5fb0cc4febcfa01cca2ae2 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Sun, 1 Mar 2020 10:13:01 -0800 Subject: [PATCH 19/22] Add missing meta.block for enum body. --- RustEnhanced.sublime-syntax | 2 +- tests/syntax-rust/syntax_test_enum.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/RustEnhanced.sublime-syntax b/RustEnhanced.sublime-syntax index c7770f6c..5fd6a101 100644 --- a/RustEnhanced.sublime-syntax +++ b/RustEnhanced.sublime-syntax @@ -808,7 +808,7 @@ contexts: pop: true enum-body: - - meta_scope: meta.enum.rust + - meta_scope: meta.block.rust meta.enum.rust - include: comments - include: attribute - match: '\}' diff --git a/tests/syntax-rust/syntax_test_enum.rs b/tests/syntax-rust/syntax_test_enum.rs index e7356faf..763ed1f6 100644 --- a/tests/syntax-rust/syntax_test_enum.rs +++ b/tests/syntax-rust/syntax_test_enum.rs @@ -5,7 +5,7 @@ enum OperatingSystem // ^^^^^^^^^^^^^^^^^ meta.enum // ^^^^^^^^^^^^^^^ entity.name.enum { -// <- meta.enum punctuation.section.block.begin +// <- meta.block meta.enum punctuation.section.block.begin Osx, // ^^^ meta.enum storage.type.source Windows, @@ -18,7 +18,7 @@ enum OperatingSystem // ^^^ storage.type // ^ meta.block punctuation.section.block.end } -// <- meta.enum punctuation.section.block.end +// <- meta.block meta.enum punctuation.section.block.end let q = Message::Quit; // ^^^^^^^ storage.type.source From 42e25e377ad61218254941a650ee05b949305484 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Sun, 1 Mar 2020 10:20:40 -0800 Subject: [PATCH 20/22] Add some clarifying comments to syntax definition. --- RustEnhanced.sublime-syntax | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/RustEnhanced.sublime-syntax b/RustEnhanced.sublime-syntax index 5fd6a101..d0e25339 100644 --- a/RustEnhanced.sublime-syntax +++ b/RustEnhanced.sublime-syntax @@ -31,6 +31,8 @@ contexts: scope: variable.other.rust statements: + # This isn't really just "statements", it also includes all types, + # expressions, items, etc. - include: visibility @@ -338,6 +340,8 @@ contexts: - include: statements after-operator: + # after-operator tries to handle ambiguous < and | symbols which can be + # either binary operators, or the start of a generic or closure. - match: '(?=<)' set: generic-angles - include: try-closure @@ -383,6 +387,7 @@ contexts: pop: true pattern-param: + # A pattern used in a function or closure parameter. - include: comments - match: '&' scope: keyword.operator.rust @@ -494,6 +499,8 @@ contexts: - include: block type: + # A low-level type. Typically you want type-any-identifier for the full + # type grammar. - match: '{{identifier}}(?=<)' push: generic-angles - match: \b(Self|{{int_suffixes}}|{{float_suffixes}}|bool|char|str)\b From c6a52fddc809cd96dc15fbb8cb76b3fe5ab0af6a Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Sat, 9 May 2020 18:06:49 -0700 Subject: [PATCH 21/22] Syntax: Fix `+` in where clause, and `;` in trait functions. --- RustEnhanced.sublime-syntax | 7 +++++-- tests/syntax-rust/syntax_test_traits.rs | 12 ++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/RustEnhanced.sublime-syntax b/RustEnhanced.sublime-syntax index d0e25339..9c5ab0cf 100644 --- a/RustEnhanced.sublime-syntax +++ b/RustEnhanced.sublime-syntax @@ -624,6 +624,8 @@ contexts: - match: ',' scope: punctuation.separator.rust - include: type-any-identifier + - match: '\+' + scope: keyword.operator.rust - match: \bextern\b scope: keyword.other.rust push: @@ -1139,7 +1141,7 @@ contexts: - match: '(?=\bwhere\b)' set: fn-where - include: return-type - # Escape for incomplete expression + # Escape for incomplete expression, or ';' - match: '(?=\S)' pop: true @@ -1153,7 +1155,8 @@ contexts: - include: type-any-identifier - match: '[:,]' scope: punctuation.separator.rust - - match: ';' + # Escape for incomplete expression, or ';' + - match: '(?=\S)' pop: true fn-body: diff --git a/tests/syntax-rust/syntax_test_traits.rs b/tests/syntax-rust/syntax_test_traits.rs index 07e63402..54228f60 100644 --- a/tests/syntax-rust/syntax_test_traits.rs +++ b/tests/syntax-rust/syntax_test_traits.rs @@ -7,6 +7,18 @@ pub trait Animal { fn noise(quiet: bool) { // Comment } + + // Some tests for no-body functions. + fn bare_semi(); +// ^^^^^^^^^^^^^^ meta.function +// ^ punctuation.terminator + fn where_semi() where X: Ord + PartialOrd; +// ^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function meta.where +// ^ keyword.operator.rust +// ^ punctuation.terminator + fn return_semi() -> bool; +// ^^^^^^^ meta.function meta.function.return-type +// ^ punctuation.terminator } // <- meta.trait meta.block punctuation.section.block.end From 1aff33a153d0162157c76cf8b43fd304fe83ed01 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 18 May 2020 11:01:19 -0700 Subject: [PATCH 22/22] Syntax: Fix issues from code review. --- RustEnhanced.sublime-syntax | 7 +------ tests/syntax-rust/syntax_test_generics.rs | 6 +++++- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/RustEnhanced.sublime-syntax b/RustEnhanced.sublime-syntax index 9c5ab0cf..199e3af6 100644 --- a/RustEnhanced.sublime-syntax +++ b/RustEnhanced.sublime-syntax @@ -522,17 +522,13 @@ contexts: generic-angles: - meta_scope: meta.generic.rust - # -> to cover https://doc.rust-lang.org/std/boxed/trait.FnBox.html - - include: support-type - match: '>' scope: punctuation.definition.generic.end.rust pop: true - match: '<' scope: punctuation.definition.generic.begin.rust push: generic-angles-contents - # Alert the user of a broken generic construct - match: '(?=\S)' - scope: invalid.illegal.rust pop: true generic-angles-contents: @@ -545,7 +541,7 @@ contexts: scope: punctuation.definition.generic.begin.rust push: - match: '>' - scope: punctuation.definition.generic.begin.rust + scope: punctuation.definition.generic.end.rust pop: true - include: generic-angles-contents - include: type-any-identifier @@ -555,7 +551,6 @@ contexts: - match: '\+|=' scope: keyword.operator.rust - match: '(?=\S)' - scope: invalid.illegal.rust pop: true constant-integer-expression: diff --git a/tests/syntax-rust/syntax_test_generics.rs b/tests/syntax-rust/syntax_test_generics.rs index be109610..d9e07b9f 100644 --- a/tests/syntax-rust/syntax_test_generics.rs +++ b/tests/syntax-rust/syntax_test_generics.rs @@ -79,10 +79,14 @@ fn f>(lhs: L) {} // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.generic // ^ punctuation.definition.generic.begin // ^ punctuation.definition.generic.begin +// ^ keyword.operator +// ^^^^^^^^^^^^^^^^^^ meta.group // ^ punctuation.section.group.begin // ^^ storage.modifier.lifetime // ^^^ storage.type -// ^ punctuation.definition.generic.begin +// ^ punctuation.separator +// ^ punctuation.section.group.end +// ^ punctuation.definition.generic.end // ^ punctuation.definition.generic.end // ^ meta.function meta.function.parameters punctuation.section.parameters.begin