Skip to content

Commit f28ef80

Browse files
committed
Fix tag for private property identifiers in Dart
1 parent b25584d commit f28ef80

File tree

6 files changed

+114
-2
lines changed

6 files changed

+114
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.2.1
2+
3+
- Mark private property identifiers as private instead of special in Dart.
4+
15
## 0.2.0
26

37
- Add basic, initial support for `c` and `cpp` (C++).

lib/src/language/dart.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ final class DartGrammar extends MatcherGrammar {
320320
]);
321321

322322
Matcher _identifiers() => Matcher.options([
323-
Matcher.regex(r'\b_[a-zA-Z0-9_]*\b', tag: Tags.specialIdentifier),
323+
Matcher.regex(r'\b_[a-zA-Z0-9_]*\b', tag: Tags.privateIdentifier),
324324
Matcher.regex(r'\b[a-z][a-zA-Z0-9_]*\b', tag: Tags.identifier),
325325
]);
326326
}

lib/src/tag.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ abstract final class Tags {
8484
/// [Tags.function], [Tags.variable], and [Tags.type].
8585
static const Tag identifier = Tag('identifier');
8686

87+
/// A tag for identifiers that are private.
88+
///
89+
/// An example is the name of a private instance variable (field) in Dart,
90+
/// which starts with an underscore, such as `int _fieldName`.
91+
static const Tag privateIdentifier = Tag('private', parent: identifier);
92+
8793
/// A tag for special identifiers with a reserved meaning
8894
/// in the current context, such as `this` in Dart.
8995
static const Tag specialIdentifier = Tag('special', parent: identifier);

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: opal
22
description: >-
33
Tokenization and syntax highlighting support for
44
various programming languages and data formats.
5-
version: 0.2.0
5+
version: 0.2.1
66
repository: https://github.com/dart-community/opal
77

88
topics:

test/goldens/dart/properties.in

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class Test {
2+
static const String _sharedName = 'test';
3+
4+
String get name => 'test';
5+
final int _age = 10;
6+
}

test/goldens/dart/properties.out

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
class Test {
2+
^^^^^
3+
source-code-dart-keyword-class
4+
^
5+
source-code-dart-whitespace
6+
^^^^
7+
source-code-dart-identifier-type
8+
^
9+
source-code-dart-whitespace
10+
^
11+
source-code-dart-punctuation
12+
static const String _sharedName = 'test';
13+
^^
14+
source-code-dart-whitespace
15+
^^^^^^
16+
source-code-dart-keyword-static
17+
^
18+
source-code-dart-whitespace
19+
^^^^^
20+
source-code-dart-keyword-const
21+
^
22+
source-code-dart-whitespace
23+
^^^^^^
24+
source-code-dart-identifier-type-built-in
25+
^
26+
source-code-dart-whitespace
27+
^^^^^^^^^^^
28+
source-code-dart-identifier-private
29+
^
30+
source-code-dart-whitespace
31+
^
32+
source-code-dart-keyword-operator
33+
^
34+
source-code-dart-whitespace
35+
^
36+
source-code-dart-literal-string-literal-string-begin
37+
^^^^
38+
source-code-dart-literal-string-literal-string-unquoted
39+
^
40+
source-code-dart-literal-string-literal-string-end
41+
^
42+
source-code-dart-punctuation
43+
44+
String get name => 'test';
45+
^^
46+
source-code-dart-whitespace
47+
^^^^^^
48+
source-code-dart-identifier-type-built-in
49+
^
50+
source-code-dart-whitespace
51+
^^^
52+
source-code-dart-keyword-get
53+
^
54+
source-code-dart-whitespace
55+
^^^^
56+
source-code-dart-identifier
57+
^
58+
source-code-dart-whitespace
59+
^^
60+
source-code-dart-keyword-operator
61+
^
62+
source-code-dart-whitespace
63+
^
64+
source-code-dart-literal-string-literal-string-begin
65+
^^^^
66+
source-code-dart-literal-string-literal-string-unquoted
67+
^
68+
source-code-dart-literal-string-literal-string-end
69+
^
70+
source-code-dart-punctuation
71+
final int _age = 10;
72+
^^
73+
source-code-dart-whitespace
74+
^^^^^
75+
source-code-dart-keyword-final
76+
^
77+
source-code-dart-whitespace
78+
^^^
79+
source-code-dart-identifier-type-built-in
80+
^
81+
source-code-dart-whitespace
82+
^^^^
83+
source-code-dart-identifier-private
84+
^
85+
source-code-dart-whitespace
86+
^
87+
source-code-dart-keyword-operator
88+
^
89+
source-code-dart-whitespace
90+
^^
91+
source-code-dart-literal-number
92+
^
93+
source-code-dart-punctuation
94+
}
95+
^
96+
source-code-dart-punctuation

0 commit comments

Comments
 (0)