@willbooster/tree-sitter-rust 1.2.0 → 1.3.0

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/grammar.js CHANGED
@@ -121,9 +121,11 @@ module.exports = grammar({
121
121
  $._line_doc_content,
122
122
  $._range_unary_endpoint_start,
123
123
  $._error_sentinel,
124
+ $._foreign_declaration_context,
125
+ $._foreign_declaration_start,
124
126
  ],
125
127
 
126
- supertypes: ($) => [$._expression, $._type, $._literal, $._literal_pattern, $._pattern],
128
+ supertypes: ($) => [$._declaration_statement, $._expression, $._type, $._literal, $._literal_pattern, $._pattern],
127
129
 
128
130
  inline: ($) => [
129
131
  $._path,
@@ -131,7 +133,6 @@ module.exports = grammar({
131
133
  $._tokens,
132
134
  $._field_identifier,
133
135
  $._non_special_token,
134
- $._declaration_statement,
135
136
  $._reserved_identifier,
136
137
  $._expression_ending_with_block,
137
138
  ],
@@ -185,7 +186,9 @@ module.exports = grammar({
185
186
  $.let_declaration,
186
187
  $.use_declaration,
187
188
  $.extern_crate_declaration,
188
- $.static_item
189
+ $.static_item,
190
+ alias($._safe_function_signature_item, $.function_signature_item),
191
+ alias($._qualified_static_item, $.static_item)
189
192
  ),
190
193
 
191
194
  macro_definition: ($) => {
@@ -326,31 +329,31 @@ module.exports = grammar({
326
329
 
327
330
  declaration_list: ($) => seq('{', repeat($._declaration_statement), '}'),
328
331
 
329
- // Items in `extern` blocks may be `safe` functions and `safe` or `unsafe` statics. `safe` is a keyword only where
330
- // such an item starts: accepting it on every item would make it one wherever an item can start, breaking its uses as
331
- // an identifier (`let safe = …; safe = …;`).
332
+ // The scanner never emits `_foreign_declaration_context`: its validity enables the zero-width
333
+ // `_foreign_declaration_start` required by qualified extern items. Keep this context marker so `safe` remains
334
+ // an identifier outside extern blocks while qualified items still participate in declaration supertype queries.
332
335
  _foreign_declaration_list: ($) =>
333
- seq(
334
- '{',
335
- repeat(
336
- choice(
337
- $._declaration_statement,
338
- alias($._safe_function_signature_item, $.function_signature_item),
339
- alias($._qualified_static_item, $.static_item)
340
- )
341
- ),
342
- '}'
343
- ),
336
+ seq('{', repeat(seq(optional($._foreign_declaration_context), $._declaration_statement)), '}'),
344
337
 
345
338
  _safe_function_signature_item: ($) =>
346
- seq(optional($.visibility_modifier), alias($._safe_modifier, $.function_modifiers), $._function_signature),
339
+ seq(
340
+ $._foreign_declaration_start,
341
+ optional($.visibility_modifier),
342
+ alias($._safe_modifier, $.function_modifiers),
343
+ $._function_signature
344
+ ),
347
345
 
348
346
  // Aliasing the bare token instead would make `function_modifiers` a leaf without the `safe` child that other
349
347
  // modifiers have.
350
348
  _safe_modifier: () => 'safe',
351
349
 
352
350
  _qualified_static_item: ($) =>
353
- seq(optional($.visibility_modifier), choice('safe', 'unsafe'), $._static_declaration),
351
+ seq(
352
+ $._foreign_declaration_start,
353
+ optional($.visibility_modifier),
354
+ choice('safe', 'unsafe'),
355
+ $._static_declaration
356
+ ),
354
357
 
355
358
  struct_item: ($) =>
356
359
  seq(
@@ -1201,15 +1204,26 @@ module.exports = grammar({
1201
1204
 
1202
1205
  struct_pattern: ($) =>
1203
1206
  seq(
1204
- field('type', choice($._type_identifier, $.scoped_type_identifier)),
1207
+ field(
1208
+ 'type',
1209
+ choice($._type_identifier, $.scoped_type_identifier, alias($._generic_struct_pattern_type, $.generic_type))
1210
+ ),
1205
1211
  '{',
1206
1212
  sepBy(',', choice($.field_pattern, $.remaining_field_pattern)),
1207
1213
  optional(','),
1208
1214
  '}'
1209
1215
  ),
1210
1216
 
1217
+ _generic_struct_pattern_type: ($) =>
1218
+ seq(
1219
+ field('type', choice($._type_identifier, $.scoped_type_identifier)),
1220
+ '::',
1221
+ field('type_arguments', $.type_arguments)
1222
+ ),
1223
+
1211
1224
  field_pattern: ($) =>
1212
1225
  seq(
1226
+ repeat($.attribute_item),
1213
1227
  optional('ref'),
1214
1228
  optional($.mutable_specifier),
1215
1229
  choice(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-rust",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "Rust grammar for tree-sitter",
5
5
  "keywords": [
6
6
  "incremental",
@@ -1,20 +1,14 @@
1
- ; Identifiers
2
-
3
1
  (type_identifier) @type
4
2
  (primitive_type) @type.builtin
5
3
  (field_identifier) @property
6
4
 
7
- ; Identifier conventions
8
5
 
9
- ; Assume all-caps names are constants
10
6
  ((identifier) @constant
11
7
  (#match? @constant "^[A-Z][A-Z\\d_]+$'"))
12
8
 
13
- ; Assume uppercase names are enum constructors
14
9
  ((identifier) @constructor
15
10
  (#match? @constructor "^[A-Z]"))
16
11
 
17
- ; Assume that uppercase names in paths are types
18
12
  ((scoped_identifier
19
13
  path: (identifier) @type)
20
14
  (#match? @type "^[A-Z]"))
@@ -36,8 +30,11 @@
36
30
  (struct_pattern
37
31
  type: (scoped_type_identifier
38
32
  name: (type_identifier) @constructor))
33
+ (struct_pattern
34
+ type: (generic_type
35
+ type: (scoped_type_identifier
36
+ name: (type_identifier) @constructor)))
39
37
 
40
- ; Function calls
41
38
 
42
39
  (call_expression
43
40
  function: (identifier) @function)
@@ -64,7 +61,6 @@
64
61
 
65
62
  (decl_macro name: (identifier) @function.macro)
66
63
 
67
- ; Function definitions
68
64
 
69
65
  (function_item (identifier) @function)
70
66
  (function_signature_item (identifier) @function)
@@ -1,4 +1,102 @@
1
1
  [
2
+ {
3
+ "type": "_declaration_statement",
4
+ "named": true,
5
+ "subtypes": [
6
+ {
7
+ "type": "associated_type",
8
+ "named": true
9
+ },
10
+ {
11
+ "type": "attribute_item",
12
+ "named": true
13
+ },
14
+ {
15
+ "type": "const_item",
16
+ "named": true
17
+ },
18
+ {
19
+ "type": "decl_macro",
20
+ "named": true
21
+ },
22
+ {
23
+ "type": "empty_statement",
24
+ "named": true
25
+ },
26
+ {
27
+ "type": "enum_item",
28
+ "named": true
29
+ },
30
+ {
31
+ "type": "extern_crate_declaration",
32
+ "named": true
33
+ },
34
+ {
35
+ "type": "foreign_mod_item",
36
+ "named": true
37
+ },
38
+ {
39
+ "type": "function_item",
40
+ "named": true
41
+ },
42
+ {
43
+ "type": "function_signature_item",
44
+ "named": true
45
+ },
46
+ {
47
+ "type": "impl_item",
48
+ "named": true
49
+ },
50
+ {
51
+ "type": "inner_attribute_item",
52
+ "named": true
53
+ },
54
+ {
55
+ "type": "let_declaration",
56
+ "named": true
57
+ },
58
+ {
59
+ "type": "macro_definition",
60
+ "named": true
61
+ },
62
+ {
63
+ "type": "macro_invocation",
64
+ "named": true
65
+ },
66
+ {
67
+ "type": "mod_item",
68
+ "named": true
69
+ },
70
+ {
71
+ "type": "static_item",
72
+ "named": true
73
+ },
74
+ {
75
+ "type": "struct_item",
76
+ "named": true
77
+ },
78
+ {
79
+ "type": "trait_alias",
80
+ "named": true
81
+ },
82
+ {
83
+ "type": "trait_item",
84
+ "named": true
85
+ },
86
+ {
87
+ "type": "type_item",
88
+ "named": true
89
+ },
90
+ {
91
+ "type": "union_item",
92
+ "named": true
93
+ },
94
+ {
95
+ "type": "use_declaration",
96
+ "named": true
97
+ }
98
+ ]
99
+ },
2
100
  {
3
101
  "type": "_expression",
4
102
  "named": true,
@@ -807,104 +905,20 @@
807
905
  "required": false,
808
906
  "types": [
809
907
  {
810
- "type": "_expression",
811
- "named": true
812
- },
813
- {
814
- "type": "associated_type",
815
- "named": true
816
- },
817
- {
818
- "type": "attribute_item",
819
- "named": true
820
- },
821
- {
822
- "type": "const_item",
823
- "named": true
824
- },
825
- {
826
- "type": "decl_macro",
827
- "named": true
828
- },
829
- {
830
- "type": "empty_statement",
908
+ "type": "_declaration_statement",
831
909
  "named": true
832
910
  },
833
911
  {
834
- "type": "enum_item",
912
+ "type": "_expression",
835
913
  "named": true
836
914
  },
837
915
  {
838
916
  "type": "expression_statement",
839
917
  "named": true
840
918
  },
841
- {
842
- "type": "extern_crate_declaration",
843
- "named": true
844
- },
845
- {
846
- "type": "foreign_mod_item",
847
- "named": true
848
- },
849
- {
850
- "type": "function_item",
851
- "named": true
852
- },
853
- {
854
- "type": "function_signature_item",
855
- "named": true
856
- },
857
- {
858
- "type": "impl_item",
859
- "named": true
860
- },
861
- {
862
- "type": "inner_attribute_item",
863
- "named": true
864
- },
865
919
  {
866
920
  "type": "label",
867
921
  "named": true
868
- },
869
- {
870
- "type": "let_declaration",
871
- "named": true
872
- },
873
- {
874
- "type": "macro_definition",
875
- "named": true
876
- },
877
- {
878
- "type": "mod_item",
879
- "named": true
880
- },
881
- {
882
- "type": "static_item",
883
- "named": true
884
- },
885
- {
886
- "type": "struct_item",
887
- "named": true
888
- },
889
- {
890
- "type": "trait_alias",
891
- "named": true
892
- },
893
- {
894
- "type": "trait_item",
895
- "named": true
896
- },
897
- {
898
- "type": "type_item",
899
- "named": true
900
- },
901
- {
902
- "type": "union_item",
903
- "named": true
904
- },
905
- {
906
- "type": "use_declaration",
907
- "named": true
908
922
  }
909
923
  ]
910
924
  }
@@ -1516,95 +1530,7 @@
1516
1530
  "required": false,
1517
1531
  "types": [
1518
1532
  {
1519
- "type": "associated_type",
1520
- "named": true
1521
- },
1522
- {
1523
- "type": "attribute_item",
1524
- "named": true
1525
- },
1526
- {
1527
- "type": "const_item",
1528
- "named": true
1529
- },
1530
- {
1531
- "type": "decl_macro",
1532
- "named": true
1533
- },
1534
- {
1535
- "type": "empty_statement",
1536
- "named": true
1537
- },
1538
- {
1539
- "type": "enum_item",
1540
- "named": true
1541
- },
1542
- {
1543
- "type": "extern_crate_declaration",
1544
- "named": true
1545
- },
1546
- {
1547
- "type": "foreign_mod_item",
1548
- "named": true
1549
- },
1550
- {
1551
- "type": "function_item",
1552
- "named": true
1553
- },
1554
- {
1555
- "type": "function_signature_item",
1556
- "named": true
1557
- },
1558
- {
1559
- "type": "impl_item",
1560
- "named": true
1561
- },
1562
- {
1563
- "type": "inner_attribute_item",
1564
- "named": true
1565
- },
1566
- {
1567
- "type": "let_declaration",
1568
- "named": true
1569
- },
1570
- {
1571
- "type": "macro_definition",
1572
- "named": true
1573
- },
1574
- {
1575
- "type": "macro_invocation",
1576
- "named": true
1577
- },
1578
- {
1579
- "type": "mod_item",
1580
- "named": true
1581
- },
1582
- {
1583
- "type": "static_item",
1584
- "named": true
1585
- },
1586
- {
1587
- "type": "struct_item",
1588
- "named": true
1589
- },
1590
- {
1591
- "type": "trait_alias",
1592
- "named": true
1593
- },
1594
- {
1595
- "type": "trait_item",
1596
- "named": true
1597
- },
1598
- {
1599
- "type": "type_item",
1600
- "named": true
1601
- },
1602
- {
1603
- "type": "union_item",
1604
- "named": true
1605
- },
1606
- {
1607
- "type": "use_declaration",
1533
+ "type": "_declaration_statement",
1608
1534
  "named": true
1609
1535
  }
1610
1536
  ]
@@ -2037,9 +1963,13 @@
2037
1963
  }
2038
1964
  },
2039
1965
  "children": {
2040
- "multiple": false,
1966
+ "multiple": true,
2041
1967
  "required": false,
2042
1968
  "types": [
1969
+ {
1970
+ "type": "attribute_item",
1971
+ "named": true
1972
+ },
2043
1973
  {
2044
1974
  "type": "mutable_specifier",
2045
1975
  "named": true
@@ -3813,104 +3743,16 @@
3813
3743
  "required": false,
3814
3744
  "types": [
3815
3745
  {
3816
- "type": "associated_type",
3817
- "named": true
3818
- },
3819
- {
3820
- "type": "attribute_item",
3821
- "named": true
3822
- },
3823
- {
3824
- "type": "const_item",
3825
- "named": true
3826
- },
3827
- {
3828
- "type": "decl_macro",
3829
- "named": true
3830
- },
3831
- {
3832
- "type": "empty_statement",
3833
- "named": true
3834
- },
3835
- {
3836
- "type": "enum_item",
3746
+ "type": "_declaration_statement",
3837
3747
  "named": true
3838
3748
  },
3839
3749
  {
3840
3750
  "type": "expression_statement",
3841
3751
  "named": true
3842
3752
  },
3843
- {
3844
- "type": "extern_crate_declaration",
3845
- "named": true
3846
- },
3847
- {
3848
- "type": "foreign_mod_item",
3849
- "named": true
3850
- },
3851
- {
3852
- "type": "function_item",
3853
- "named": true
3854
- },
3855
- {
3856
- "type": "function_signature_item",
3857
- "named": true
3858
- },
3859
- {
3860
- "type": "impl_item",
3861
- "named": true
3862
- },
3863
- {
3864
- "type": "inner_attribute_item",
3865
- "named": true
3866
- },
3867
- {
3868
- "type": "let_declaration",
3869
- "named": true
3870
- },
3871
- {
3872
- "type": "macro_definition",
3873
- "named": true
3874
- },
3875
- {
3876
- "type": "macro_invocation",
3877
- "named": true
3878
- },
3879
- {
3880
- "type": "mod_item",
3881
- "named": true
3882
- },
3883
3753
  {
3884
3754
  "type": "shebang",
3885
3755
  "named": true
3886
- },
3887
- {
3888
- "type": "static_item",
3889
- "named": true
3890
- },
3891
- {
3892
- "type": "struct_item",
3893
- "named": true
3894
- },
3895
- {
3896
- "type": "trait_alias",
3897
- "named": true
3898
- },
3899
- {
3900
- "type": "trait_item",
3901
- "named": true
3902
- },
3903
- {
3904
- "type": "type_item",
3905
- "named": true
3906
- },
3907
- {
3908
- "type": "union_item",
3909
- "named": true
3910
- },
3911
- {
3912
- "type": "use_declaration",
3913
- "named": true
3914
3756
  }
3915
3757
  ]
3916
3758
  }
@@ -4080,6 +3922,10 @@
4080
3922
  "multiple": false,
4081
3923
  "required": true,
4082
3924
  "types": [
3925
+ {
3926
+ "type": "generic_type",
3927
+ "named": true
3928
+ },
4083
3929
  {
4084
3930
  "type": "scoped_type_identifier",
4085
3931
  "named": true
Binary file
package/tree-sitter.json CHANGED
@@ -22,7 +22,7 @@
22
22
  }
23
23
  ],
24
24
  "metadata": {
25
- "version": "1.2.0",
25
+ "version": "1.3.0",
26
26
  "license": "MIT",
27
27
  "description": "Rust grammar for tree-sitter",
28
28
  "authors": [