Skip to content

Commit e30bd89

Browse files
bors[bot]ehuss
andcommitted
Merge #322 #323 #324
322: Syntax: Unreserve reserved keywords. r=ehuss a=ehuss <img width="573" alt="image" src="https://user-images.githubusercontent.com/43198/43735841-8daddd7a-9970-11e8-8cc7-7e085abd0ac5.png"> 323: Syntax: Rework enums. r=ehuss a=ehuss Enums weren't supporting type parameters, among other things. <img width="515" alt="image" src="https://user-images.githubusercontent.com/43198/43736027-1e6cd550-9971-11e8-8369-d50c61927922.png"> 324: Syntax: Support comments near struct/union. r=ehuss a=ehuss <img width="555" alt="image" src="https://user-images.githubusercontent.com/43198/43736116-5f5e8306-9971-11e8-87f3-663f8ca9950b.png"> Co-authored-by: Eric Huss <[email protected]>
4 parents ac2b3da + 4774769 + 3f819f7 + 1b2a404 commit e30bd89

6 files changed

+153
-21
lines changed

RustEnhanced.sublime-syntax

Lines changed: 68 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ file_extensions:
77
scope: source.rust
88
variables:
99
identifier: '(?:[[:alpha:]][_[:alnum:]]*|_[_[:alnum:]]+)'
10+
camel_ident: '\b_*[A-Z][a-zA-Z0-9_]*[a-z][a-zA-Z0-9_]*\b'
1011
escaped_byte: '\\([nrt0\"''\\]|x\h{2})'
1112
escaped_char: '\\([nrt0\"''\\]|x[0-7]\h|u\{(?:\h_*){1,6}\})'
1213
int_suffixes: '[iu](?:8|16|32|64|128|size)'
@@ -90,13 +91,9 @@ contexts:
9091
scope: storage.type.impl.rust
9192
push: impl-definition
9293

93-
- match: '\b(enum)\s+({{identifier}})\b'
94-
captures:
95-
1: storage.type.enum.rust
96-
2: entity.name.enum.rust
97-
push:
98-
- meta_scope: meta.enum.rust
99-
- include: statements-block
94+
- match: '\benum\b'
95+
scope: storage.type.enum.rust
96+
push: enum-identifier
10097

10198
- match: \b(let|const|static)\b
10299
scope: storage.type.rust
@@ -107,15 +104,6 @@ contexts:
107104
- match: \bmod\b
108105
scope: storage.type.module.rust
109106

110-
- match: \bstruct\b
111-
scope: storage.type.struct.rust
112-
113-
- match: \bimpl\b
114-
scope: storage.type.impl.rust
115-
116-
- match: \benum\b
117-
scope: storage.type.enum.rust
118-
119107
- match: \btype\b
120108
scope: storage.type.type.rust
121109

@@ -142,7 +130,7 @@ contexts:
142130
- match: \b(as|in|box)\b
143131
scope: keyword.operator.rust
144132

145-
- match: \b(virtual|proc|alignof|become|offsetof|priv|pure|sizeof|typeof|unsized|yield|do|abstract|final|override|macro)\b
133+
- match: \b(virtual|become|priv|typeof|unsized|do|abstract|final|override|macro)\b
146134
scope: invalid.illegal.rust
147135

148136
- match: \b(true|false)\b
@@ -540,6 +528,7 @@ contexts:
540528

541529
struct-identifier:
542530
- meta_scope: meta.struct.rust
531+
- include: comments
543532
- match: '{{identifier}}(?=<)'
544533
scope: entity.name.struct.rust
545534
set:
@@ -608,6 +597,7 @@ contexts:
608597

609598
union-identifier:
610599
- meta_scope: meta.union.rust
600+
- include: comments
611601
- match: '{{identifier}}(?=<)'
612602
scope: entity.name.union.rust
613603
set:
@@ -634,6 +624,67 @@ contexts:
634624
- match: '(?=;)'
635625
pop: true
636626

627+
enum-identifier:
628+
- meta_scope: meta.enum.rust
629+
- include: comments
630+
- match: '{{identifier}}(?=<)'
631+
scope: entity.name.enum.rust
632+
set:
633+
- meta_scope: meta.enum.rust meta.generic.rust
634+
- match: '(?=<)'
635+
push: generic-angles
636+
- match: ''
637+
set: enum-maybe-where
638+
- match: '{{identifier}}'
639+
scope: entity.name.enum.rust
640+
set: enum-maybe-where
641+
642+
enum-maybe-where:
643+
- meta_scope: meta.enum.rust
644+
- include: comments
645+
- match: '(?=\bwhere\b)'
646+
push: impl-where
647+
- match: '\{'
648+
scope: punctuation.definition.block.begin.rust
649+
set: enum-body
650+
651+
enum-body:
652+
- meta_scope: meta.enum.rust
653+
- include: comments
654+
- include: attribute
655+
- match: '\}'
656+
scope: punctuation.definition.block.end.rust
657+
pop: true
658+
- match: '\b[[:upper:]_][[:upper:][:digit:]_]*\b'
659+
scope: constant.other.rust
660+
push: enum-variant-type
661+
- match: '{{camel_ident}}'
662+
scope: storage.type.source.rust
663+
push: enum-variant-type
664+
- match: '{{identifier}}'
665+
push: enum-variant-type
666+
667+
enum-variant-type:
668+
- include: comments
669+
- match: '(?=\})'
670+
pop: true
671+
- match: ','
672+
pop: true
673+
- match: '='
674+
set: enum-discriminant
675+
- match: '(?=\()'
676+
push: struct-tuple
677+
- match: '(?=\{)'
678+
push: struct-classic
679+
680+
enum-discriminant:
681+
- match: ','
682+
pop: true
683+
- match: '(?=\})'
684+
pop: true
685+
# This is just constant-expression, but we don't have that defined.
686+
- include: statements
687+
637688
macro-block:
638689
- meta_scope: meta.macro.rust
639690
- match: '\}'

tests/syntax-rust/syntax_test_attributes.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,13 @@ pub struct Claim {
4747
pub date: String,
4848
}
4949

50+
enum E {
51+
#[allow(dead_code)]
52+
// ^^^^^^^^^^^^^^^^^^^ meta.enum meta.annotation
53+
// ^^^^^ support.function
54+
A(i32),
55+
// ^^^ meta.enum meta.struct meta.group storage.type
56+
}
57+
5058
// TODO: FIXME - Generic parameters.
5159
// unsafe impl<#[may_dangle] T: ?Sized> Drop for Box<T> { }

tests/syntax-rust/syntax_test_enum.rs

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,20 @@ enum OperatingSystem
55
// ^^^^^^^^^^^^^^^^^ meta.enum
66
// ^^^^^^^^^^^^^^^ entity.name.enum
77
{
8-
// <- meta.enum meta.block punctuation.definition.block.begin
8+
// <- meta.enum punctuation.definition.block.begin
99
Osx,
10+
// ^^^ meta.enum storage.type.source
1011
Windows,
1112
Linux,
1213
Bsd(String),
1314
// ^^^^^^ support.type
1415
Info { field: i32, value: str }
15-
// ^ meta.block meta.block punctuation.definition.block.begin
16+
// ^ punctuation.definition.block.begin
1617
// ^^^ storage.type
1718
// ^^^ storage.type
18-
// ^ meta.block meta.block punctuation.definition.block.end
19+
// ^ meta.block punctuation.definition.block.end
1920
}
20-
// <- meta.enum meta.block punctuation.definition.block.end
21+
// <- meta.enum punctuation.definition.block.end
2122

2223
let q = Message::Quit;
2324
// ^^^^^^^ storage.type.source
@@ -33,3 +34,35 @@ let m = Message::Move { x: 50, y: 200 };
3334
// ^^^^^^^^^^^^^^^^^ meta.block
3435
// ^^ constant.numeric.integer.decimal
3536
// ^^^ constant.numeric.integer.decimal
37+
38+
enum Discriminant {
39+
A = 1,
40+
// ^ meta.enum constant.other
41+
// ^ meta.enum constant.numeric.integer.decimal
42+
V1 = 0xABC,
43+
// ^^ meta.enum constant.other
44+
// ^^^^^ meta.enum constant.numeric.integer.hexadecimal
45+
V2,
46+
// ^^ meta.enum constant.other
47+
SomeValue = 123,
48+
// ^^^^^^^^^ meta.enum storage.type.source
49+
// ^^^ meta.enum constant.numeric.integer.decimal
50+
V3 = (1<<4),
51+
// ^^ meta.enum constant.other
52+
// ^^^^^^ meta.enum meta.group
53+
// ^ constant.numeric.integer.decimal
54+
// ^^ keyword.operator
55+
// ^ constant.numeric.integer.decimal
56+
lowercase,
57+
// ^^^^^^^^^^^ meta.enum
58+
}
59+
60+
// Enum type parameters.
61+
enum E<'asdf> {}
62+
// ^^^^^^^ meta.enum meta.generic
63+
// ^^^^^storage.modifier.lifetime
64+
enum C<T> where T: Copy {}
65+
// ^^^ meta.enum meta.generic
66+
// ^^^^^^^^^^^^^ meta.enum meta.where
67+
// ^^^^^ keyword.other
68+
// ^^^^ support.type

tests/syntax-rust/syntax_test_misc.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,37 @@ unsafe impl<T> Send for Interned<T> {}
99
//^^^^ storage.modifier
1010
pub unsafe trait Alloc { }
1111
// ^^^^^^ storage.modifier
12+
13+
// Previously reserved keywords now unreserved.
14+
let pure = 1;
15+
// ^^^^ -invalid.illegal.rust
16+
let sizeof = 1;
17+
// ^^^^^^ -invalid.illegal.rust
18+
let alignof = 1;
19+
// ^^^^^^^ -invalid.illegal.rust
20+
let offsetof = 1;
21+
// ^^^^^^^^ -invalid.illegal.rust
22+
let proc = 1;
23+
// ^^^^ -invalid.illegal.rust
24+
25+
// Reserved keywords.
26+
let virtual = 1;
27+
// ^^^^^^^ invalid.illegal.rust
28+
let become = 1;
29+
// ^^^^^^ invalid.illegal.rust
30+
let priv = 1;
31+
// ^^^^ invalid.illegal.rust
32+
let typeof = 1;
33+
// ^^^^^^ invalid.illegal.rust
34+
let unsized = 1;
35+
// ^^^^^^^ invalid.illegal.rust
36+
let do = 1;
37+
// ^^ invalid.illegal.rust
38+
let abstract = 1;
39+
// ^^^^^^^^ invalid.illegal.rust
40+
let final = 1;
41+
// ^^^^^ invalid.illegal.rust
42+
let override = 1;
43+
// ^^^^^^^^ invalid.illegal.rust
44+
let macro = 1;
45+
// ^^^^^ invalid.illegal.rust

tests/syntax-rust/syntax_test_struct.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ struct Pair(i32, i32);
3131
// ^^^ storage.type
3232
// ^ - meta.struct
3333

34+
struct /*comment*/ Comments {}
35+
// ^^^^^^^^^^^ meta.struct comment.block
36+
3437
struct Point
3538
// ^^^^^^^^^ meta.struct
3639
{

tests/syntax-rust/syntax_test_union.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,6 @@ pub union Foo<'a, Y: Baz>
3535
// that we don't accidentally interpret it as a keyword.
3636
fn union() {}
3737
// ^^^^^ meta.function entity.name.function
38+
39+
union /*comment*/ U {}
40+
// ^^^^^^^^^^^ meta.union comment.block

0 commit comments

Comments
 (0)