Skip to content

Commit 56ffe48

Browse files
dtenJayflux
authored andcommitted
replace after-operator with check for type declaration syntax (#221)
* handle comments around parameters and types in general * replace after-operator with check for type declaration syntax the after-operator was to deal with type declarations of the style used in `forward_ref_binop` which contains `type Output = <$t as $imp<$u>>::Output;` there is a more precise way to deal with this and it fixes other macro syntax highlighting such as in mdo (although it uses a custom operator so all bets are off)
1 parent c4139f7 commit 56ffe48

File tree

2 files changed

+43
-6
lines changed

2 files changed

+43
-6
lines changed

RustEnhanced.sublime-syntax

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ contexts:
7171
1: storage.modifier.rust
7272
2: storage.type.type.rust
7373
3: entity.name.type.rust
74+
push:
75+
- match: '=(?!=)'
76+
scope: keyword.operator.rust
77+
push: after-operator
78+
- match: '(?=\S)'
79+
pop: true
7480

7581
- match: '\b(?:(pub)\s+)?(trait)\s+({{identifier}})\b'
7682
captures:
@@ -129,7 +135,6 @@ contexts:
129135

130136
- match: \breturn\b
131137
scope: keyword.control.rust
132-
push: after-operator
133138

134139
- match: \b(as|in|box)\b
135140
scope: keyword.operator.rust
@@ -213,18 +218,14 @@ contexts:
213218
# match blocks containing just enums
214219
- match: '=>'
215220
scope: keyword.operator.rust
216-
push: after-operator
217221

218222
- match: '=(?!=)'
219223
scope: keyword.operator.rust
220-
push: after-operator
221224

222225
- match: '[;,]'
223-
push: after-operator
224226

225227
- match: ':'
226228
scope: punctuation.separator.rust
227-
push: after-operator
228229

229230
- match: '\.\.\.'
230231
scope: keyword.operator.rust
@@ -446,6 +447,7 @@ contexts:
446447
pop: true
447448

448449
type-any-identifier:
450+
- include: comments
449451
- include: support-type
450452
- include: return-type
451453
- match: '&'

syntax_test_rust.rs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1097,4 +1097,39 @@ where
10971097
T: AsRef<str>;
10981098
//^^^^^^^^^^^^^^^ meta.struct
10991099
// ^^^ meta.struct meta.where storage.type
1100-
// ^ punctuation.terminator
1100+
// ^ punctuation.terminator
1101+
1102+
fn foo<F: FnMut(i32, i32 /*asd*/) -> i32>(f: F) {
1103+
// ^^^^^^^ meta.generic comment
1104+
let lam = |time: i32 /* comment */, other: i32| {
1105+
// ^^^^^^^^^^^^^ meta.function.parameters comment
1106+
};
1107+
}
1108+
1109+
// mdo example
1110+
fn main() {
1111+
// exporting the monadic functions for the Iterator monad (similar
1112+
// to list comprehension)
1113+
use mdo::iter::{bind, ret, mzero};
1114+
1115+
let l = bind(1i32..11, move |z|
1116+
bind(1..z, move |x|
1117+
bind(x..z, move |y|
1118+
bind(if x * x + y * y == z * z { ret(()) }
1119+
else { mzero() },
1120+
move |_|
1121+
ret((x, y, z))
1122+
)))).collect::<Vec<_>>();
1123+
println!("{:?}", l);
1124+
1125+
// the same thing, using the mdo! macro
1126+
let l = mdo! {
1127+
z =<< 1i32..11;
1128+
x =<< 1..z;
1129+
// ^^^ keyword.operator
1130+
y =<< x..z;
1131+
when x * x + y * y == z * z;
1132+
ret ret((x, y, z))
1133+
}.collect::<Vec<_>>();
1134+
println!("{:?}", l);
1135+
}

0 commit comments

Comments
 (0)