@willbooster/tree-sitter-dart 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -12,20 +12,20 @@ Dart grammar for [tree-sitter](https://github.com/tree-sitter/tree-sitter), fork
12
12
  [nielsenko/tree-sitter-dart](https://github.com/nielsenko/tree-sitter-dart). We are grateful
13
13
  to its authors and contributors. This is not an official release of that project.
14
14
 
15
- This fork keeps the grammar and the external scanner of upstream's version 0.2.0 and generates the parser with the
15
+ This fork extends upstream's version 0.2.0 grammar, retains its external scanner, and generates the parser with the
16
16
  [WillBooster/tree-sitter](https://github.com/WillBooster/tree-sitter) generator. The parser carries that fork's own ABI number (`0x57420001`), so it loads only with the fork's runtime,
17
17
  version 2.0.0 or later; upstream's runtime rejects it, and the fork's runtime rejects parsers generated by upstream's CLI.
18
18
 
19
19
  ## Differences from upstream's parser
20
20
 
21
- Valid Dart parses to the same trees as with upstream's 0.2.0 parser. Two differences are known:
21
+ Known differences from upstream's 0.2.0 parser include:
22
22
 
23
- - Error recovery on invalid input can differ, because the WillBooster/tree-sitter generator extracts keywords per
24
- lexer state. Of 13,595 real-world files (flutter/flutter, dart-lang/core, rrousselGit/riverpod, and part of the Dart
25
- SDK), 3 files that are invalid on purpose recover into a different tree, as do 2 of 10,197 truncated files; the error
26
- flag is the same in every case. Their minimal inputs are `void main() {\n print(\n "foo" !==\n null);`,
27
- `test_nullAssert_insideCast(x) {\n switch (x) {\n case _! as num?:`, and
28
- ` final v3 = (buffer.(p) {\n return p == buffer;`.
23
+ - Arrow function bodies include trailing selectors. For `(x) => a.b(x)`, the call belongs inside the
24
+ `function_expression_body`; upstream attaches it to the arrow function instead. Nested arrow functions follow the
25
+ same rule. Block-bodied function literals still support immediate calls and member access. Public node names and
26
+ the `parameters:` and `body:` fields are preserved.
27
+ - Error recovery on invalid input can differ from upstream.
28
+ [Issue #4](https://github.com/WillBooster/tree-sitter-dart/issues/4) tracks these differences.
29
29
  - A NUL character in a line comment or between tokens parses as ordinary text, where upstream's lexer reports an error.
30
30
 
31
31
  ## Usage
package/grammar.js CHANGED
@@ -145,9 +145,6 @@ module.exports = grammar({
145
145
  [$._primary, $.assignable_expression],
146
146
  [$._primary, $.labeled_statement],
147
147
  // Assignable-vs-wrapper: same chain reduces under either name; lookahead picks
148
- [$.assignable_expression, $.member_expression, $._unary_expression],
149
- [$.assignable_expression, $.index_expression, $._unary_expression],
150
- [$.assignable_expression, $.null_aware_member_expression, $._unary_expression],
151
148
  [$.assignable_expression, $.null_aware_index_expression, $._unary_expression],
152
149
  // Type name ambiguities
153
150
  [$._type_name],
@@ -200,7 +197,6 @@ module.exports = grammar({
200
197
  [$.type_arguments, $.relational_operator, $.type_parameters],
201
198
  // Generic call/instantiation vs comparisons (TS-style GLR fork on `<`)
202
199
  [$._unary_expression, $.instantiation_expression],
203
- [$._unary_expression, $.call_expression],
204
200
  // Record literal vs record field / record type
205
201
  [$._record_literal_no_const, $.record_field],
206
202
  [$.record_type, $._record_literal_no_const],
@@ -1149,7 +1145,7 @@ module.exports = grammar({
1149
1145
  _unary_expression: ($) =>
1150
1146
  prec(
1151
1147
  PREC.UNARY_PREFIX,
1152
- choice($._postfix_expression, $.unary_expression),
1148
+ choice($._postfix_expression, $.unary_expression, $.function_expression),
1153
1149
  ),
1154
1150
 
1155
1151
  unary_expression: ($) =>
@@ -1274,7 +1270,7 @@ module.exports = grammar({
1274
1270
  choice(
1275
1271
  $._literal,
1276
1272
  $.identifier,
1277
- $.function_expression,
1273
+ alias($._function_primary, $.function_expression),
1278
1274
  $._instantiation,
1279
1275
  $.parenthesized_expression,
1280
1276
  "this",
@@ -1293,11 +1289,17 @@ module.exports = grammar({
1293
1289
  ),
1294
1290
 
1295
1291
  function_expression_body: ($) =>
1296
- choice(
1297
- seq(optional("async"), "=>", $._expression),
1298
- seq(optional(choice("async", "async*", "sync*")), $.block),
1292
+ seq(optional("async"), "=>", $._expression),
1293
+
1294
+ _function_primary: ($) =>
1295
+ seq(
1296
+ field("parameters", $._formal_parameter_part),
1297
+ field("body", alias($._function_primary_body, $.function_expression_body)),
1299
1298
  ),
1300
1299
 
1300
+ _function_primary_body: ($) =>
1301
+ seq(optional(choice("async", "async*", "sync*")), $.block),
1302
+
1301
1303
  // Hidden supertype: any expression that constructs an instance. Lets
1302
1304
  // queries address the three forms (new/const/implicit) uniformly via
1303
1305
  // (_instantiation) without alternation. Does not add an AST layer.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-dart",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Dart grammar for tree-sitter",
5
5
  "keywords": [
6
6
  "incremental",
Binary file
package/tree-sitter.json CHANGED
@@ -18,7 +18,7 @@
18
18
  }
19
19
  ],
20
20
  "metadata": {
21
- "version": "1.0.0",
21
+ "version": "1.0.1",
22
22
  "license": "MIT",
23
23
  "description": "Dart grammar for tree-sitter",
24
24
  "authors": [