Skip to content

Commit 24e4a1c

Browse files
committed
Add support for inline classes
See dart-lang/sdk#49734 and https://github.com/dart-lang/language/blob/master/accepted/future-releases/inline-classes/feature-specification.md. Inline is only detected as part of class, the spec says: > The token `inline` is not made a built-in identifier: the reserved word `class` that occurs right after `inline` serves to disambiguate the inline class declaration with a fixed lookahead.
1 parent 92b4bc3 commit 24e4a1c

File tree

3 files changed

+72
-1
lines changed

3 files changed

+72
-1
lines changed

grammars/dart.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@
336336
},
337337
{
338338
"name": "keyword.declaration.dart",
339-
"match": "(?<!\\$)\\b(abstract|sealed|base|interface|class|enum|extends|extension|external|factory|implements|get(?!\\()|mixin|native|operator|set(?!\\()|typedef|with|covariant)\\b(?!\\$)"
339+
"match": "(?<!\\$)\\b(abstract|sealed|base|interface|inline class|class|enum|extends|extension|external|factory|implements|get(?!\\()|mixin|native|operator|set(?!\\()|typedef|with|covariant)\\b(?!\\$)"
340340
},
341341
{
342342
"name": "storage.modifier.dart",

test/goldens/inline.dart.golden

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
>// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
2+
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.line.double-slash.dart
3+
>// for details. All rights reserved. Use of this source code is governed by a
4+
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.line.double-slash.dart
5+
>// BSD-style license that can be found in the LICENSE file.
6+
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.line.double-slash.dart
7+
>
8+
>inline class MyInt {
9+
#^^^^^^^^^^^^ keyword.declaration.dart
10+
# ^^^^^ support.class.dart
11+
> final int it;
12+
# ^^^^^ storage.modifier.dart
13+
# ^^^ support.class.dart
14+
# ^ punctuation.terminator.dart
15+
> MyInt(this.it);
16+
# ^^^^^ support.class.dart
17+
# ^^^^ variable.language.dart
18+
# ^ punctuation.dot.dart
19+
# ^ punctuation.terminator.dart
20+
> void foo() { print('MyInt.foo'); }
21+
# ^^^^ storage.type.primitive.dart
22+
# ^^^ entity.name.function.dart
23+
# ^^^^^ entity.name.function.dart
24+
# ^^^^^^^^^^^ string.interpolated.single.dart
25+
# ^ punctuation.terminator.dart
26+
>}
27+
>
28+
>final inline = 1;
29+
#^^^^^ storage.modifier.dart
30+
# ^ keyword.operator.assignment.dart
31+
# ^ constant.numeric.dart
32+
# ^ punctuation.terminator.dart
33+
>
34+
>int get inline = 1;
35+
#^^^ support.class.dart
36+
# ^^^ keyword.declaration.dart
37+
# ^ keyword.operator.assignment.dart
38+
# ^ constant.numeric.dart
39+
# ^ punctuation.terminator.dart
40+
>set inline(int value) {}
41+
#^^^ keyword.declaration.dart
42+
# ^^^^^^ entity.name.function.dart
43+
# ^^^ support.class.dart
44+
>
45+
>void inline() {
46+
#^^^^ storage.type.primitive.dart
47+
# ^^^^^^ entity.name.function.dart
48+
> var inline = 1;
49+
# ^^^ storage.type.primitive.dart
50+
# ^ keyword.operator.assignment.dart
51+
# ^ constant.numeric.dart
52+
# ^ punctuation.terminator.dart
53+
>}

test/test_files/inline.dart

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
inline class MyInt {
6+
final int it;
7+
MyInt(this.it);
8+
void foo() { print('MyInt.foo'); }
9+
}
10+
11+
final inline = 1;
12+
13+
int get inline = 1;
14+
set inline(int value) {}
15+
16+
void inline() {
17+
var inline = 1;
18+
}

0 commit comments

Comments
 (0)