Skip to content

Commit 5e5d953

Browse files
committed
fixes and tests
1 parent f95876f commit 5e5d953

14 files changed

+113033
-84324
lines changed

assets/playground.js

Lines changed: 461 additions & 0 deletions
Large diffs are not rendered by default.

assets/tree-sitter.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

grammar.js

Lines changed: 79 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,14 @@ module.exports = grammar({
6363
$._template_chars_single,
6464
$._template_chars_double_single,
6565
$._template_chars_single_single,
66-
$._template_chars_raw_slash
66+
$._template_chars_raw_slash,
67+
$._block_comment,
68+
$._documentation_block_comment,
6769
],
6870

6971
extras: $ => [
7072
$.comment,
7173
$.documentation_comment,
72-
// $.multiline_comment,
7374
/\s/
7475
],
7576

@@ -155,6 +156,7 @@ module.exports = grammar({
155156
[$._type_not_void_not_function, $._function_type_tail],
156157
[$._type_not_void],
157158
[$._type_not_void_not_function],
159+
[$.super_formal_parameter, $.unconditional_assignable_selector],
158160
[$.function_signature]
159161
],
160162

@@ -237,7 +239,7 @@ module.exports = grammar({
237239
),
238240
seq(
239241
optional($._late_builtin),
240-
choice($._type, $.inferred_type),
242+
choice($._type, seq($.inferred_type, optional($._type))),
241243
$.initialized_identifier_list,
242244
$._semicolon
243245
)
@@ -1188,7 +1190,7 @@ module.exports = grammar({
11881190
$.yield_each_statement,
11891191
$.expression_statement,
11901192
$.assert_statement,
1191-
$.labeled_statement,
1193+
// $.labeled_statement,
11921194
$.lambda_expression
11931195
),
11941196

@@ -1207,11 +1209,15 @@ module.exports = grammar({
12071209

12081210
assert_statement: $ => seq($.assertion, ';'),
12091211

1210-
assertion: $ => seq($._assert_builtin, '(', $._expression, optional(seq(
1211-
',',
1212-
$._expression,
1213-
optional(',')
1214-
)), ')'),
1212+
assertion: $ => seq($._assert_builtin, '(', $._expression,
1213+
optional(
1214+
seq(
1215+
',',
1216+
$._expression
1217+
)
1218+
),
1219+
optional(','),
1220+
')'),
12151221

12161222
switch_statement: $ => seq(
12171223
'switch',
@@ -1225,10 +1231,20 @@ module.exports = grammar({
12251231
'}'
12261232
),
12271233

1228-
switch_label: $ => choice(
1234+
switch_case: $ => choice(
1235+
seq(repeat($.label), $.case_builtin, $._expression, ':', repeat1($._statement)),
1236+
),
1237+
1238+
default_case: $ => choice(
1239+
seq(repeat($.label), 'default', ':', repeat1($._statement)),
1240+
),
1241+
1242+
switch_label: $ => seq(
1243+
repeat($.label),
1244+
choice(
12291245
seq($.case_builtin, $._expression, ':'),
12301246
seq('default', ':')
1231-
),
1247+
)),
12321248

12331249
do_statement: $ => seq(
12341250
'do',
@@ -1593,6 +1609,12 @@ module.exports = grammar({
15931609
alias(
15941610
$.identifier,
15951611
$.type_identifier),
1612+
// This is a comment
1613+
// comment with a link made in https://github.com/flutter/flutter/pull/48547
1614+
// Changes made in https://github.com/flutter/flutter/pull/48547
1615+
/* This is also a comment */
1616+
/* this comment /* // /** ends here: */
1617+
15961618
optional($._nullable_type),
15971619
optional($.type_bound)
15981620
),
@@ -1844,10 +1866,6 @@ module.exports = grammar({
18441866
//$.arguements
18451867
$.arguments
18461868
),
1847-
seq('super',
1848-
//$.arguements
1849-
$.arguments
1850-
),
18511869
$.field_initializer,
18521870
$.assertion
18531871
),
@@ -1985,8 +2003,8 @@ module.exports = grammar({
19852003
)),
19862004
seq(optional($._late_builtin),
19872005
choice(
2006+
$._type,
19882007
$.inferred_type,
1989-
$._type
19902008
))
19912009
),
19922010

@@ -2053,9 +2071,12 @@ module.exports = grammar({
20532071
')'
20542072
),
20552073

2056-
normal_parameter_type: $ => choice(
2057-
$.typed_identifier,
2058-
$._type
2074+
normal_parameter_type: $ => seq(
2075+
optional($._metadata),
2076+
choice(
2077+
$.typed_identifier,
2078+
$._type
2079+
)
20592080
),
20602081

20612082
optional_parameter_types: $ => choice(
@@ -2070,10 +2091,16 @@ module.exports = grammar({
20702091
),
20712092
named_parameter_types: $ => seq(
20722093
'{',
2073-
commaSep1TrailingComma($.typed_identifier),
2094+
commaSep1TrailingComma($._named_parameter_type),
20742095
'}'
20752096
),
20762097

2098+
_named_parameter_type: $ => seq(
2099+
optional($._metadata),
2100+
optional($._required),
2101+
$.typed_identifier
2102+
),
2103+
20772104
_type_not_void: $ => choice(
20782105
seq(
20792106
$.function_type,
@@ -2126,7 +2153,6 @@ module.exports = grammar({
21262153
),
21272154

21282155
typed_identifier: $ => seq(
2129-
optional($._metadata),
21302156
$._type,
21312157
$.identifier
21322158
),
@@ -2300,7 +2326,7 @@ module.exports = grammar({
23002326
_default_named_parameter: $ => choice(
23012327
seq(
23022328
optional(
2303-
'required'
2329+
$._required
23042330
),
23052331
$.formal_parameter,
23062332
optional(
@@ -2312,7 +2338,7 @@ module.exports = grammar({
23122338
),
23132339
seq(
23142340
optional(
2315-
'required'
2341+
$._required
23162342
),
23172343
$.formal_parameter,
23182344
optional(
@@ -2331,8 +2357,8 @@ module.exports = grammar({
23312357
choice(
23322358
$._function_formal_parameter,
23332359
$._simple_formal_parameter,
2334-
$.constructor_param
2335-
// $.field_formal_parameter
2360+
$.constructor_param,
2361+
$.super_formal_parameter
23362362
)
23372363
),
23382364

@@ -2357,6 +2383,16 @@ module.exports = grammar({
23572383
$.identifier
23582384
)
23592385
),
2386+
2387+
// see https://github.com/dart-lang/language/blob/31f3d2bd6fd83b2e5f5019adb276c23fd2900941/working/1855%20-%20super%20parameters/proposal.md
2388+
super_formal_parameter: $ => seq(
2389+
optional($._final_const_var_or_type),
2390+
$.super,
2391+
'.',
2392+
$.identifier,
2393+
optional($._formal_parameter_part)
2394+
),
2395+
23602396
//constructor param = field formal parameter
23612397
constructor_param: $ => seq(
23622398
optional($._final_const_var_or_type),
@@ -2501,6 +2537,10 @@ module.exports = grammar({
25012537
DART_PREC.BUILTIN,
25022538
'part',
25032539
),
2540+
_required: $ => prec(
2541+
DART_PREC.BUILTIN,
2542+
'required',
2543+
),
25042544
_set: $ => prec(
25052545
DART_PREC.BUILTIN,
25062546
'set',
@@ -2564,83 +2604,35 @@ module.exports = grammar({
25642604

25652605
label: $ => seq($.identifier, ':'),
25662606

2567-
_semicolon: $ => seq(';', optional($._automatic_semicolon)),
2607+
_semicolon: $ => seq(';'),
25682608

25692609
identifier: $ => /[a-zA-Z_$][\w$]*/,
25702610
identifier_dollar_escaped: $ => /([a-zA-Z_]|(\\\$))([\w]|(\\\$))*/,
25712611
//TODO: add support for triple-slash comments as a special category.
25722612
// Trying to add support for nested multiline comments.
25732613
// http://stackoverflow.com/questions/13014947/regex-to-match-a-c-style-multiline-comment/36328890#36328890
2574-
comment: $ => token(choice(
2575-
seq('//', /[^/].*/),
2614+
2615+
// _line_comment: $ => token(seq(
2616+
// '//', /[^\/].*/
2617+
// )),
2618+
// _documentation_line_comment: $ => token(seq('///', /.*/)),
2619+
2620+
comment: $ => choice(
2621+
$._block_comment,
2622+
seq('//', /([^/\n].*)?/),
25762623
seq(
25772624
'/*',
25782625
/[^*]*\*+([^/*][^*]*\*+)*/,
25792626
'/'
25802627
)
2581-
)),
2628+
),
25822629
//added nesting comments.
2583-
documentation_comment: $ => token(
2630+
documentation_comment: $ =>
25842631
choice(
2632+
$._documentation_block_comment,
25852633
seq('///', /.*/),
2586-
// seq(
2587-
// '/**',
2588-
// repeat(
2589-
// choice(
2590-
// /[^*]*\*+([^/*][^*]*\*+)*/,
2591-
// // $.comment
2592-
// // ,
2593-
// /.*/,
2594-
// $._multiline_comment,
2595-
// $.documentation_comment
2596-
// )
2597-
// ),
2598-
// '*/'
2599-
// )
26002634
)
2601-
),
2602-
// multiline_comment: $ => seq(
2603-
// $._multiline_comment_begin,
2604-
// $._multiline_comment_core,
2605-
// // repeat(
2606-
// // choice(
2607-
// // $._multiline_comment_core,
2608-
// // $.multiline_comment
2609-
// // )
2610-
// // ),
2611-
// $._multiline_comment_end
2612-
// ),
2613-
// _multiline_comment_end: $ => token('*/'),
2614-
// _multiline_comment_begin: $ => token('/*'),
2615-
//
2616-
// _nested_multiline_comment: $ => seq(
2617-
// $._multiline_comment_begin,
2618-
// repeat(
2619-
// choice(
2620-
// /([^\/*]*|\/[^*]|\*[^\/])+/,
2621-
// $._nested_multiline_comment
2622-
// // seq(
2623-
// // $._multiline_comment_begin,
2624-
// // $._multiline_comment_core,
2625-
// // )
2626-
// )
2627-
// ),
2628-
// $._multiline_comment_end
2629-
// ),
2630-
//
2631-
// _multiline_comment_core: $ => seq(
2632-
// repeat1(
2633-
// choice(
2634-
// /([^\/*]*|\/[^*]|\*[^\/])+/,
2635-
// $._nested_multiline_comment
2636-
// // seq(
2637-
// // $._multiline_comment_begin,
2638-
// // $._multiline_comment_core,
2639-
// // )
2640-
// )
2641-
// ),
2642-
// // $._multiline_comment_end
2643-
// ),
2635+
,
26442636
}
26452637
});
26462638

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
"author": "Benjamin Sobel",
1212
"license": "ISC",
1313
"dependencies": {
14-
"nan": "^2.14.2"
14+
"nan": "^2.15.0"
1515
},
1616
"devDependencies": {
1717
"node-gyp": "^7.1.2",
1818
"npm-watch": "^0.7.0",
19-
"tree-sitter-cli": "^0.19.2"
19+
"tree-sitter-cli": "^0.19.5"
2020
},
2121
"watch": {
2222
"test": {
@@ -51,7 +51,8 @@
5151
"scope": "source.dart",
5252
"file-types": [
5353
"dart"
54-
]
54+
],
55+
"injection-regex": "dart"
5556
}
5657
]
5758
}

queries/highlights.scm

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,6 @@
118118
; distinguish method call from variable access
119119
(unconditional_assignable_selector
120120
(identifier) @property)
121-
(assignable_selector
122-
(identifier) @property)
123121

124122
; assignments
125123
(assignment_expression

0 commit comments

Comments
 (0)