Skip to content

Commit b4cd9fd

Browse files
authored
Update dart_syntax grammar for latest fixes (#8861)
1 parent ae0a811 commit b4cd9fd

File tree

9 files changed

+137
-85
lines changed

9 files changed

+137
-85
lines changed

packages/devtools_app/assets/dart_syntax.json

Lines changed: 65 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "Dart",
3-
"version": "1.2.5",
3+
"version": "1.4.1",
44
"fileTypes": [
55
"dart"
66
],
@@ -16,7 +16,7 @@
1616
},
1717
{
1818
"name": "meta.declaration.dart",
19-
"begin": "^\\w*\\b(library|import|part of|part|export)\\b",
19+
"begin": "^\\w*\\b(augment\\s+library|library|import\\s+augment|import|part\\s+of|part|export)\\b",
2020
"beginCaptures": {
2121
"0": {
2222
"name": "keyword.other.import.dart"
@@ -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"
@@ -211,11 +222,11 @@
211222
},
212223
{
213224
"name": "variable.language.dart",
214-
"match": "(?<!\\$)\\b(this|super)\\b(?!\\$)"
225+
"match": "(?<!\\$)\\b(this|super|augmented)\\b(?!\\$)"
215226
},
216227
{
217228
"name": "constant.numeric.dart",
218-
"match": "(?<!\\$)\\b((0(x|X)[0-9a-fA-F]*)|(([0-9]+\\.?[0-9]*)|(\\.[0-9]+))((e|E)(\\+|-)?[0-9]+)?)\\b(?!\\$)"
229+
"match": "(?<!\\$)\\b((0(x|X)[0-9a-fA-F][0-9a-fA-F_]*)|(([0-9][0-9_]*\\.?[0-9_]*)|(\\.[0-9][0-9_]*))((e|E)(\\+|-)?[0-9][0-9_]*)?)\\b(?!\\$)"
219230
},
220231
{
221232
"include": "#class-identifier"
@@ -312,7 +323,7 @@
312323
},
313324
{
314325
"name": "keyword.control.dart",
315-
"match": "(?<!\\$)\\b(break|case|continue|default|do|else|for|if|in|return|switch|while|when)\\b(?!\\$)"
326+
"match": "(?<!\\$)\\b(break|case|continue|default|do|else|for|if|in|switch|while|when)\\b(?!\\$)"
316327
},
317328
{
318329
"name": "keyword.control.dart",
@@ -326,13 +337,17 @@
326337
"name": "keyword.control.new.dart",
327338
"match": "(?<!\\$)\\b(new)\\b(?!\\$)"
328339
},
340+
{
341+
"name": "keyword.control.return.dart",
342+
"match": "(?<!\\$)\\b(return)\\b(?!\\$)"
343+
},
329344
{
330345
"name": "keyword.declaration.dart",
331-
"match": "(?<!\\$)\\b(abstract|sealed|base|interface|class|enum|extends|extension type|extension|external|factory|implements|get(?!\\()|mixin|native|operator|set(?!\\()|typedef|with|covariant)\\b(?!\\$)"
346+
"match": "(?<!\\$)\\b(abstract|sealed|base|interface|class|enum|extends|extension\\s+type|extension|external|factory|implements|get(?![(<])|mixin|native|operator|set(?![(<])|typedef|with|covariant)\\b(?!\\$)"
332347
},
333348
{
334349
"name": "storage.modifier.dart",
335-
"match": "(?<!\\$)\\b(static|final|const|required|late)\\b(?!\\$)"
350+
"match": "(?<!\\$)\\b(macro|augment|static|final|const|required|late)\\b(?!\\$)"
336351
},
337352
{
338353
"name": "storage.type.primitive.dart",
@@ -388,10 +403,33 @@
388403
}
389404
]
390405
},
406+
"expression": {
407+
"patterns": [
408+
{
409+
"include": "#constants-and-special-vars"
410+
},
411+
{
412+
"include": "#strings"
413+
},
414+
{
415+
"name": "variable.parameter.dart",
416+
"match": "[a-zA-Z0-9_]+"
417+
},
418+
{
419+
"begin": "\\{",
420+
"end": "\\}",
421+
"patterns": [
422+
{
423+
"include": "#expression"
424+
}
425+
]
426+
}
427+
]
428+
},
391429
"string-interp": {
392430
"patterns": [
393431
{
394-
"name": "string.interpolated.expression.dart",
432+
"name": "meta.embedded.expression.dart",
395433
"match": "\\$([a-zA-Z0-9_]+)",
396434
"captures": {
397435
"1": {
@@ -400,19 +438,12 @@
400438
}
401439
},
402440
{
403-
"name": "string.interpolated.expression.dart",
441+
"name": "meta.embedded.expression.dart",
404442
"begin": "\\$\\{",
405443
"end": "\\}",
406444
"patterns": [
407445
{
408-
"include": "#constants-and-special-vars"
409-
},
410-
{
411-
"include": "#strings"
412-
},
413-
{
414-
"name": "variable.parameter.dart",
415-
"match": "[a-zA-Z0-9_]+"
446+
"include": "#expression"
416447
}
417448
]
418449
},

packages/devtools_app/lib/src/screens/debugger/syntax_highlighter.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ class SyntaxHighlighter {
245245
const controlFlowScopes = <String>[
246246
'keyword.control.catch-exception.dart',
247247
'keyword.control.dart',
248+
'keyword.control.return.dart',
248249
// While 'new' is not a control flow keyword, it uses the control flow
249250
// color scheme so we include it here.
250251
'keyword.control.new.dart',

packages/devtools_app/release_notes/NEXT_RELEASE_NOTES.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ TODO: Remove this section if there are not any general updates.
3636
## Debugger updates
3737

3838
* Added a tooltip to describe the exception mode drop-down. -
39-
[#8849](https://github.com/flutter/devtools/pull/8849)
39+
[#8849](https://github.com/flutter/devtools/pull/8849)
40+
* Updated syntax highlighting with support for digit separators,
41+
and improved comment and string interpolation handling. -
42+
[#8861](https://github.com/flutter/devtools/pull/8861)
4043

4144
## Network profiler updates
4245

packages/devtools_app/test/test_infra/goldens/syntax_highlighting/comments.dart.golden

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,10 @@
1212
>/// ```
1313
#^^^^^^^ comment.block.documentation.dart
1414
>/// doc
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
>/// ...

packages/devtools_app/test/test_infra/goldens/syntax_highlighting/keywords.dart.golden

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
# ^ punctuation.dot.dart
7575
# ^^^^^^ entity.name.function.dart
7676
> return _b;
77-
# ^^^^^^ keyword.control.dart
77+
# ^^^^^^ keyword.control.return.dart
7878
# ^ punctuation.terminator.dart
7979
> }
8080
>
@@ -97,7 +97,7 @@
9797
# ^^ keyword.operator.comparison.dart
9898
# ^^^^^^ support.class.dart
9999
> return false;
100-
# ^^^^^^ keyword.control.dart
100+
# ^^^^^^ keyword.control.return.dart
101101
# ^^^^^ constant.language.dart
102102
# ^ punctuation.terminator.dart
103103
> }
@@ -193,7 +193,7 @@
193193
#^^^^ storage.type.primitive.dart
194194
# ^^^^^^^ entity.name.function.dart
195195
> return;
196-
# ^^^^^^ keyword.control.dart
196+
# ^^^^^^ keyword.control.return.dart
197197
# ^ punctuation.terminator.dart
198198
>}
199199
>
@@ -322,7 +322,7 @@
322322
# ^ punctuation.terminator.dart
323323
> }
324324
> return;
325-
# ^^^^^^ keyword.control.dart
325+
# ^^^^^^ keyword.control.return.dart
326326
# ^ punctuation.terminator.dart
327327
> }
328328
>
@@ -364,7 +364,7 @@
364364
# ^^^^^^^ keyword.control.dart
365365
# ^ keyword.operator.ternary.dart
366366
> return;
367-
# ^^^^^^ keyword.control.dart
367+
# ^^^^^^ keyword.control.return.dart
368368
# ^ punctuation.terminator.dart
369369
> }
370370
>}

packages/devtools_app/test/test_infra/goldens/syntax_highlighting/literals.dart.golden

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
# ^^ string.interpolated.single.dart
2929
# ^ punctuation.comma.dart
3030
# ^ string.interpolated.single.dart
31-
# ^ string.interpolated.single.dart string.interpolated.expression.dart
32-
# ^ string.interpolated.single.dart string.interpolated.expression.dart variable.parameter.dart
31+
# ^ string.interpolated.single.dart meta.embedded.expression.dart
32+
# ^ string.interpolated.single.dart meta.embedded.expression.dart variable.parameter.dart
3333
# ^ string.interpolated.single.dart
3434
# ^ punctuation.terminator.dart
3535
>const list4 = <String>['', '$a'];
@@ -41,8 +41,8 @@
4141
# ^^ string.interpolated.single.dart
4242
# ^ punctuation.comma.dart
4343
# ^ string.interpolated.single.dart
44-
# ^ string.interpolated.single.dart string.interpolated.expression.dart
45-
# ^ string.interpolated.single.dart string.interpolated.expression.dart variable.parameter.dart
44+
# ^ string.interpolated.single.dart meta.embedded.expression.dart
45+
# ^ string.interpolated.single.dart meta.embedded.expression.dart variable.parameter.dart
4646
# ^ string.interpolated.single.dart
4747
# ^ punctuation.terminator.dart
4848
>
@@ -63,8 +63,8 @@
6363
# ^^ string.interpolated.single.dart
6464
# ^ punctuation.comma.dart
6565
# ^ string.interpolated.single.dart
66-
# ^ string.interpolated.single.dart string.interpolated.expression.dart
67-
# ^ string.interpolated.single.dart string.interpolated.expression.dart variable.parameter.dart
66+
# ^ string.interpolated.single.dart meta.embedded.expression.dart
67+
# ^ string.interpolated.single.dart meta.embedded.expression.dart variable.parameter.dart
6868
# ^ string.interpolated.single.dart
6969
# ^ punctuation.terminator.dart
7070
>const set4 = <String>{'', '$a'};
@@ -76,8 +76,8 @@
7676
# ^^ string.interpolated.single.dart
7777
# ^ punctuation.comma.dart
7878
# ^ string.interpolated.single.dart
79-
# ^ string.interpolated.single.dart string.interpolated.expression.dart
80-
# ^ string.interpolated.single.dart string.interpolated.expression.dart variable.parameter.dart
79+
# ^ string.interpolated.single.dart meta.embedded.expression.dart
80+
# ^ string.interpolated.single.dart meta.embedded.expression.dart variable.parameter.dart
8181
# ^ string.interpolated.single.dart
8282
# ^ punctuation.terminator.dart
8383
>
@@ -96,8 +96,8 @@
9696
# ^^ string.interpolated.single.dart
9797
# ^ keyword.operator.ternary.dart
9898
# ^ string.interpolated.single.dart
99-
# ^ string.interpolated.single.dart string.interpolated.expression.dart
100-
# ^ string.interpolated.single.dart string.interpolated.expression.dart variable.parameter.dart
99+
# ^ string.interpolated.single.dart meta.embedded.expression.dart
100+
# ^ string.interpolated.single.dart meta.embedded.expression.dart variable.parameter.dart
101101
# ^ string.interpolated.single.dart
102102
# ^ punctuation.terminator.dart
103103
>const map3 = <String, String>{'': '$a'};
@@ -111,7 +111,23 @@
111111
# ^^ string.interpolated.single.dart
112112
# ^ keyword.operator.ternary.dart
113113
# ^ string.interpolated.single.dart
114-
# ^ string.interpolated.single.dart string.interpolated.expression.dart
115-
# ^ string.interpolated.single.dart string.interpolated.expression.dart variable.parameter.dart
114+
# ^ string.interpolated.single.dart meta.embedded.expression.dart
115+
# ^ string.interpolated.single.dart meta.embedded.expression.dart variable.parameter.dart
116116
# ^ string.interpolated.single.dart
117117
# ^ punctuation.terminator.dart
118+
>
119+
>const num1 = 12345;
120+
#^^^^^ storage.modifier.dart
121+
# ^ keyword.operator.assignment.dart
122+
# ^^^^^ constant.numeric.dart
123+
# ^ punctuation.terminator.dart
124+
>const num2 = 12345.678;
125+
#^^^^^ storage.modifier.dart
126+
# ^ keyword.operator.assignment.dart
127+
# ^^^^^^^^^ constant.numeric.dart
128+
# ^ punctuation.terminator.dart
129+
>const num3 = 888_888_888;
130+
#^^^^^ storage.modifier.dart
131+
# ^ keyword.operator.assignment.dart
132+
# ^^^^^^^^^^^ constant.numeric.dart
133+
# ^ punctuation.terminator.dart

packages/devtools_app/test/test_infra/goldens/syntax_highlighting/open_code_block.golden

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
>///
66
#^^^ comment.block.documentation.dart
77
>/// This should not cause parsing to fail.
8-
#^^^ comment.block.documentation.dart
9-
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.block.documentation.dart variable.other.source.dart
8+
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.block.documentation.dart variable.other.source.dart
109
>
1110
>void main() {
1211
#^^^^ storage.type.primitive.dart

0 commit comments

Comments
 (0)