Skip to content

Commit 6a40337

Browse files
committed
Switch from using "while" to "end" and adjust nested rules accordingly
1 parent 4d827c8 commit 6a40337

File tree

4 files changed

+146
-92
lines changed

4 files changed

+146
-92
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 1.4.0 (2024-10-10)
2+
3+
- Removed use of 'while' in the grammar to avoid some differences in implementations between GitHub and VS Code
4+
- Improved handling of unclosed code blocks in dartdoc comments
5+
16
## 1.3.0 (2024-07-31)
27

38
- Added support for digit separators (`_`).

grammars/dart.json

+29-18
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "Dart",
3-
"version": "1.3.0",
3+
"version": "1.4.0",
44
"fileTypes": [
55
"dart"
66
],
@@ -69,6 +69,16 @@
6969
],
7070

7171
"repository": {
72+
"dartdoc-codeblock-triple": {
73+
"begin": "^\\s*///\\s*(?!\\s*```)",
74+
"end": "\n",
75+
"contentName": "variable.other.source.dart"
76+
},
77+
"dartdoc-codeblock-block": {
78+
"begin": "^\\s*\\*\\s*(?!(\\s*```|\/))",
79+
"end": "\n",
80+
"contentName": "variable.other.source.dart"
81+
},
7282
"dartdoc": {
7383
"patterns": [
7484
{
@@ -80,30 +90,31 @@
8090
}
8191
},
8292
{
83-
"match": "^ {4,}(?![ \\*]).*",
84-
"captures": {
85-
"0": {
86-
"name": "variable.name.source.dart"
93+
"begin": "^\\s*///\\s*(```)",
94+
"end": "^\\s*///\\s*(```)|^(?!\\s*///)",
95+
"patterns": [
96+
{
97+
"include": "#dartdoc-codeblock-triple"
8798
}
88-
}
99+
]
89100
},
90101
{
91-
"contentName": "variable.other.source.dart",
92-
"begin": "```.*?$",
93-
"end": "```"
102+
"begin": "^\\s*\\*\\s*(```)",
103+
"end": "^\\s*\\*\\s*(```)|^(?=\\s*\\*\/)",
104+
"patterns": [
105+
{
106+
"include": "#dartdoc-codeblock-block"
107+
}
108+
]
94109
},
95110
{
96-
"match": "(`[^`]+?`)",
97-
"captures": {
98-
"0": {
99-
"name": "variable.other.source.dart"
100-
}
101-
}
111+
"match": "`[^`\n]+`",
112+
"name": "variable.other.source.dart"
102113
},
103114
{
104-
"match": "(\\* (( ).*))$",
115+
"match": "\\s{4,}(.*)$",
105116
"captures": {
106-
"2": {
117+
"1": {
107118
"name": "variable.other.source.dart"
108119
}
109120
}
@@ -157,7 +168,7 @@
157168
{
158169
"name": "comment.block.documentation.dart",
159170
"begin": "///",
160-
"while": "^\\s*///",
171+
"end": "^(?!\\s*///)",
161172
"patterns": [
162173
{
163174
"include": "#dartdoc"

pubspec.yaml

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ environment:
44
sdk: ^3.2.0
55

66
dev_dependencies:
7-
collection: ^1.18.0
8-
dart_flutter_team_lints: ^2.1.1
7+
collection: ^1.19.0
8+
dart_flutter_team_lints: ^3.2.1
99
path: ^1.9.0
10-
string_scanner: ^1.2.0
11-
test: ^1.25.2
10+
string_scanner: ^1.4.0
11+
test: ^1.25.8

test/goldens/comments.dart.golden

+108-70
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,10 @@
1212
>/// ```
1313
#^^^^^^^ comment.block.documentation.dart
1414
>/// code
15-
#^^^ comment.block.documentation.dart
16-
# ^^^^^ comment.block.documentation.dart variable.other.source.dart
15+
#^^^^ comment.block.documentation.dart
16+
# ^^^^ comment.block.documentation.dart variable.other.source.dart
1717
>/// ```
18-
#^^^ comment.block.documentation.dart
19-
# ^ comment.block.documentation.dart variable.other.source.dart
20-
# ^^^ comment.block.documentation.dart
18+
#^^^^^^^ comment.block.documentation.dart
2119
>///
2220
#^^^ comment.block.documentation.dart
2321
>/// ...
@@ -33,8 +31,8 @@
3331
>/// ```
3432
#^^^^^^^ comment.block.documentation.dart
3533
>/// code
36-
#^^^ comment.block.documentation.dart
37-
# ^^^^^ comment.block.documentation.dart variable.other.source.dart
34+
#^^^^ comment.block.documentation.dart
35+
# ^^^^ comment.block.documentation.dart variable.other.source.dart
3836
>var doc2;
3937
#^^^ storage.type.primitive.dart
4038
# ^ punctuation.terminator.dart
@@ -54,13 +52,16 @@
5452
>///
5553
#^^^ comment.block.documentation.dart
5654
>/// code1
57-
#^^^^^^^^^^^^^ comment.block.documentation.dart
55+
#^^^^^^^^ comment.block.documentation.dart
56+
# ^^^^^ comment.block.documentation.dart variable.other.source.dart
5857
>/// code2
59-
#^^^^^^^^^^^^^ comment.block.documentation.dart
58+
#^^^^^^^^ comment.block.documentation.dart
59+
# ^^^^^ comment.block.documentation.dart variable.other.source.dart
6060
>///
6161
#^^^ comment.block.documentation.dart
6262
>/// code3
63-
#^^^^^^^^^^^^^ comment.block.documentation.dart
63+
#^^^^^^^^ comment.block.documentation.dart
64+
# ^^^^^ comment.block.documentation.dart variable.other.source.dart
6465
>///
6566
#^^^ comment.block.documentation.dart
6667
>/// ...
@@ -76,10 +77,10 @@
7677
> * ```
7778
#^^^^^^ comment.block.documentation.dart
7879
> * code
79-
#^^^^^^^ comment.block.documentation.dart variable.other.source.dart
80+
#^^^ comment.block.documentation.dart
81+
# ^^^^ comment.block.documentation.dart variable.other.source.dart
8082
> * ```
81-
#^^^ comment.block.documentation.dart variable.other.source.dart
82-
# ^^^ comment.block.documentation.dart
83+
#^^^^^^ comment.block.documentation.dart
8384
> *
8485
#^^ comment.block.documentation.dart
8586
> * ...
@@ -97,129 +98,166 @@
9798
> * ```
9899
#^^^^^^ comment.block.documentation.dart
99100
> * code
100-
#^^^^^^^ comment.block.documentation.dart variable.other.source.dart
101+
#^^^ comment.block.documentation.dart
102+
# ^^^^ comment.block.documentation.dart variable.other.source.dart
101103
> */
102-
#^^^ comment.block.documentation.dart variable.other.source.dart
104+
#^^^ comment.block.documentation.dart
103105
>var blockDoc2;
104-
#^^^^^^^^^^^^^^ comment.block.documentation.dart variable.other.source.dart
106+
#^^^ storage.type.primitive.dart
107+
# ^ punctuation.terminator.dart
105108
>
106109
>/** Block dartdoc comment with unclosed backticks.
107-
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.block.documentation.dart variable.other.source.dart
110+
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.block.documentation.dart
108111
> *
109-
#^^ comment.block.documentation.dart variable.other.source.dart
112+
#^^ comment.block.documentation.dart
110113
> * `code
111-
#^^^^^^^^ comment.block.documentation.dart variable.other.source.dart
114+
#^^^^^^^^ comment.block.documentation.dart
112115
> */
113-
#^^^ comment.block.documentation.dart variable.other.source.dart
116+
#^^^ comment.block.documentation.dart
114117
>var blockDoc3;
115-
#^^^^^^^^^^^^^^ comment.block.documentation.dart variable.other.source.dart
118+
#^^^ storage.type.primitive.dart
119+
# ^ punctuation.terminator.dart
116120
>
117121
>/** Block dartdoc comment with indented code.
118-
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.block.documentation.dart variable.other.source.dart
122+
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.block.documentation.dart
119123
> *
120-
#^^ comment.block.documentation.dart variable.other.source.dart
124+
#^^ comment.block.documentation.dart
121125
> * code1
122-
#^^^^^^^^^^^^ comment.block.documentation.dart variable.other.source.dart
126+
#^^^^^^^ comment.block.documentation.dart
127+
# ^^^^^ comment.block.documentation.dart variable.other.source.dart
123128
> * code2
124-
#^^^^^^^^^^^^ comment.block.documentation.dart variable.other.source.dart
129+
#^^^^^^^ comment.block.documentation.dart
130+
# ^^^^^ comment.block.documentation.dart variable.other.source.dart
125131
> *
126-
#^^ comment.block.documentation.dart variable.other.source.dart
132+
#^^ comment.block.documentation.dart
127133
> * code3
128-
#^^^^^^^^^^^^ comment.block.documentation.dart variable.other.source.dart
134+
#^^^^^^^ comment.block.documentation.dart
135+
# ^^^^^ comment.block.documentation.dart variable.other.source.dart
129136
> *
130-
#^^ comment.block.documentation.dart variable.other.source.dart
137+
#^^ comment.block.documentation.dart
131138
> * ...
132-
#^^^^^^ comment.block.documentation.dart variable.other.source.dart
139+
#^^^^^^ comment.block.documentation.dart
133140
> */
134-
#^^^ comment.block.documentation.dart variable.other.source.dart
141+
#^^^ comment.block.documentation.dart
135142
>var blockDoc4;
136-
#^^^^^^^^^^^^^^ comment.block.documentation.dart variable.other.source.dart
143+
#^^^ storage.type.primitive.dart
144+
# ^ punctuation.terminator.dart
137145
>
138146
>/// ``
139-
#^^^^^^ comment.block.documentation.dart variable.other.source.dart
147+
#^^^^^^ comment.block.documentation.dart
140148
>var noInlineCode;
141-
#^^^^^^^^^^^^^^^^^ comment.block.documentation.dart variable.other.source.dart
149+
#^^^ storage.type.primitive.dart
150+
# ^ punctuation.terminator.dart
142151
>
143152
>/// `Stream<int>`
144-
#^^^^^^^^^^^^^^^^^ comment.block.documentation.dart variable.other.source.dart
153+
#^^^^ comment.block.documentation.dart
154+
# ^^^^^^^^^^^^^ comment.block.documentation.dart variable.other.source.dart
145155
>var inlineCode;
146-
#^^^^^^^^^^^^^^^ comment.block.documentation.dart variable.other.source.dart
156+
#^^^ storage.type.primitive.dart
157+
# ^ punctuation.terminator.dart
147158
>
148159
>/// ` `
149-
#^^^^^^^ comment.block.documentation.dart variable.other.source.dart
160+
#^^^^ comment.block.documentation.dart
161+
# ^^^ comment.block.documentation.dart variable.other.source.dart
150162
>var inlineCodeJustWhitespace;
151-
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.block.documentation.dart variable.other.source.dart
163+
#^^^ storage.type.primitive.dart
164+
# ^ punctuation.terminator.dart
152165
>
153166
>/*
154-
#^^ comment.block.documentation.dart variable.other.source.dart
167+
#^^ comment.block.dart
155168
> * Old-style dartdoc
156-
#^^^^^^^^^^^^^^^^^^^^ comment.block.documentation.dart variable.other.source.dart
169+
#^^^^^^^^^^^^^^^^^^^^ comment.block.dart
157170
> *
158-
#^^ comment.block.documentation.dart variable.other.source.dart
171+
#^^ comment.block.dart
159172
> * ...
160-
#^^^^^^ comment.block.documentation.dart variable.other.source.dart
173+
#^^^^^^ comment.block.dart
161174
> */
162-
#^^^ comment.block.documentation.dart variable.other.source.dart
175+
#^^^ comment.block.dart
163176
>var b;
164-
#^^^^^^ comment.block.documentation.dart variable.other.source.dart
177+
#^^^ storage.type.primitive.dart
178+
# ^ punctuation.terminator.dart
165179
>
166180
>/* Inline block comment */
167-
#^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.block.documentation.dart variable.other.source.dart
181+
#^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.block.dart
168182
>var c;
169-
#^^^^^^ comment.block.documentation.dart variable.other.source.dart
183+
#^^^ storage.type.primitive.dart
184+
# ^ punctuation.terminator.dart
170185
>
171186
>/**
172-
#^^^ comment.block.documentation.dart variable.other.source.dart
187+
#^^^ comment.block.documentation.dart
173188
> * Nested block
174-
#^^^^^^^^^^^^^^^ comment.block.documentation.dart variable.other.source.dart
189+
#^^^^^^^^^^^^^^^ comment.block.documentation.dart
175190
> *
176-
#^^ comment.block.documentation.dart variable.other.source.dart
191+
#^^ comment.block.documentation.dart
177192
> * /**
178-
#^^^^^^ comment.block.documentation.dart variable.other.source.dart
193+
#^^^^^^ comment.block.documentation.dart
179194
> * * Nested block
180-
#^^^^^^^^^^^^^^^^^^ comment.block.documentation.dart variable.other.source.dart
195+
#^^^^^^^^^^^^^^^^^^ comment.block.documentation.dart
181196
> * */
182-
#^^^^^^ comment.block.documentation.dart variable.other.source.dart
197+
#^^^^^^ comment.block.documentation.dart
183198
> */
184-
#^^^ comment.block.documentation.dart variable.other.source.dart
199+
#^^^ comment.block.documentation.dart
185200
>var d;
186-
#^^^^^^ comment.block.documentation.dart variable.other.source.dart
201+
#^^^ storage.type.primitive.dart
202+
# ^ punctuation.terminator.dart
187203
>
188204
>/**
189-
#^^^ comment.block.documentation.dart variable.other.source.dart
205+
#^^^ comment.block.documentation.dart
190206
> * Nested
191-
#^^^^^^^^^ comment.block.documentation.dart variable.other.source.dart
207+
#^^^^^^^^^ comment.block.documentation.dart
192208
> *
193-
#^^ comment.block.documentation.dart variable.other.source.dart
209+
#^^ comment.block.documentation.dart
194210
> * /* Inline */
195-
#^^^^^^^^^^^^^^^ comment.block.documentation.dart variable.other.source.dart
211+
#^^^ comment.block.documentation.dart
212+
# ^^^^^^^^^^^^ comment.block.documentation.dart comment.block.dart
196213
> */
197-
#^^^ comment.block.documentation.dart variable.other.source.dart
214+
#^^^ comment.block.documentation.dart
198215
>var e;
199-
#^^^^^^ comment.block.documentation.dart variable.other.source.dart
216+
#^^^ storage.type.primitive.dart
217+
# ^ punctuation.terminator.dart
200218
>
201219
>/* Nested /* Inline */ */
202-
#^^^^^^^^^^^^^^^^^^^^^^^^^ comment.block.documentation.dart variable.other.source.dart
220+
#^^^^^^^^^^^^^^^^^^^^^^^^^ comment.block.dart
203221
>var f;
204-
#^^^^^^ comment.block.documentation.dart variable.other.source.dart
222+
#^^^ storage.type.primitive.dart
223+
# ^ punctuation.terminator.dart
205224
>
206225
>// Simple comment
207-
#^^^^^^^^^^^^^^^^^ comment.block.documentation.dart variable.other.source.dart
226+
#^^^^^^^^^^^^^^^^^ comment.line.double-slash.dart
208227
>var g;
209-
#^^^^^^ comment.block.documentation.dart variable.other.source.dart
228+
#^^^ storage.type.primitive.dart
229+
# ^ punctuation.terminator.dart
210230
>
211231
>/// Dartdoc with reference to [a].
212-
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.block.documentation.dart variable.other.source.dart
232+
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.block.documentation.dart
233+
# ^^^ comment.block.documentation.dart variable.name.source.dart
234+
# ^ comment.block.documentation.dart
213235
>/// And a link to [example.org](http://example.org/).
214-
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.block.documentation.dart variable.other.source.dart
236+
#^^^^^^^^^^^^^^^^^^ comment.block.documentation.dart
237+
# ^^^^^^^^^^^^^ comment.block.documentation.dart variable.name.source.dart
238+
# ^^^^^^^^^^^^^^^^^^^^^^ comment.block.documentation.dart
215239
>var h;
216-
#^^^^^^ comment.block.documentation.dart variable.other.source.dart
240+
#^^^ storage.type.primitive.dart
241+
# ^ punctuation.terminator.dart
217242
>
218243
>class A<T /* comment */ > {
219-
#^^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.block.documentation.dart variable.other.source.dart
244+
#^^^^^ keyword.declaration.dart
245+
# ^ support.class.dart
246+
# ^ other.source.dart
247+
# ^ support.class.dart
248+
# ^^^^^^^^^^^^^ comment.block.dart
249+
# ^ other.source.dart
220250
> void b<T /* comment */ >() {}
221-
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.block.documentation.dart variable.other.source.dart
251+
# ^^^^ storage.type.primitive.dart
252+
# ^ keyword.operator.comparison.dart
253+
# ^ support.class.dart
254+
# ^^^^^^^^^^^^^ comment.block.dart
255+
# ^ keyword.operator.comparison.dart
222256
> Future<T /* comment */ > c() {}
223-
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.block.documentation.dart variable.other.source.dart
257+
# ^^^^^^ support.class.dart
258+
# ^ other.source.dart
259+
# ^ support.class.dart
260+
# ^^^^^^^^^^^^^ comment.block.dart
261+
# ^ other.source.dart
262+
# ^ entity.name.function.dart
224263
>}
225-
#^ comment.block.documentation.dart variable.other.source.dart

0 commit comments

Comments
 (0)