Skip to content

Commit 84cb031

Browse files
committed
unified: convert _type into a named rule
Because `_type` was anonymous, its body was inlined in all of the places it appeared. Because this body contained a `name` field, this field was _also_ inlined. This caused a bunch of nodes to have spurious `name` fields, and for some of them (that already had such a field) it caused that field have multiplicity greater than one. To fix this, we make the `_type` node named, which prevents the errant field from escaping.
1 parent 1ddeb56 commit 84cb031

1 file changed

Lines changed: 19 additions & 19 deletions

File tree

unified/extractor/tree-sitter-swift/grammar.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -401,13 +401,13 @@ module.exports = grammar({
401401
type_annotation: ($) =>
402402
seq(":", field("type", $._possibly_implicitly_unwrapped_type)),
403403
_possibly_implicitly_unwrapped_type: ($) =>
404-
choice($._type, $.implicitly_unwrapped_type),
404+
choice($.type, $.implicitly_unwrapped_type),
405405
implicitly_unwrapped_type: ($) =>
406-
seq($._type, token.immediate("!")),
407-
_type: ($) =>
406+
seq($.type, token.immediate("!")),
407+
type: ($) =>
408408
prec.right(
409409
PRECS.ty,
410-
seq(optional($.type_modifiers), field("name", $.unannotated_type))
410+
seq(field("modifiers", optional($.type_modifiers)), field("name", $.unannotated_type))
411411
),
412412
unannotated_type: ($) =>
413413
prec.right(
@@ -453,7 +453,7 @@ module.exports = grammar({
453453
seq(
454454
optional($._tuple_type_item_identifier),
455455
optional($.parameter_modifiers),
456-
field("type", $._type)
456+
field("type", $.type)
457457
)
458458
),
459459
_tuple_type_item_identifier: ($) =>
@@ -471,11 +471,11 @@ module.exports = grammar({
471471
optional($._async_keyword),
472472
optional(choice($.throws_clause, $.throws)),
473473
$._arrow_operator,
474-
field("return_type", $._type)
474+
field("return_type", $.type)
475475
),
476-
array_type: ($) => seq("[", field("element", $._type), "]"),
476+
array_type: ($) => seq("[", field("element", $.type), "]"),
477477
dictionary_type: ($) =>
478-
seq("[", field("key", $._type), ":", field("value", $._type), "]"),
478+
seq("[", field("key", $.type), ":", field("value", $.type), "]"),
479479
optional_type: ($) =>
480480
prec.left(
481481
seq(
@@ -622,7 +622,7 @@ module.exports = grammar({
622622
as_expression: ($) =>
623623
prec.left(
624624
PRECS.as,
625-
seq(field("expr", $.expression), $.as_operator, field("type", $._type))
625+
seq(field("expr", $.expression), $.as_operator, field("type", $.type))
626626
),
627627
selector_expression: ($) =>
628628
seq(
@@ -699,7 +699,7 @@ module.exports = grammar({
699699
seq(
700700
field("target", $.expression),
701701
field("op", $._is_operator),
702-
field("type", $._type)
702+
field("type", $.type)
703703
)
704704
),
705705
comparison_expression: ($) =>
@@ -777,7 +777,7 @@ module.exports = grammar({
777777
seq("(", optional(sep1Opt($.value_argument, ",")), ")"),
778778
_fn_call_lambda_arguments: ($) =>
779779
sep1($.lambda_literal, seq(field("name", $.simple_identifier), ":")),
780-
type_arguments: ($) => prec.left(seq("<", sep1Opt($._type, ","), ">")),
780+
type_arguments: ($) => prec.left(seq("<", sep1Opt($.type, ","), ">")),
781781
value_arguments: ($) =>
782782
seq(
783783
choice(
@@ -1450,7 +1450,7 @@ module.exports = grammar({
14501450
field("name", alias($.simple_identifier, $.type_identifier)),
14511451
optional($.type_parameters),
14521452
$._equal_sign,
1453-
field("value", $._type)
1453+
field("value", $.type)
14541454
),
14551455
function_declaration: ($) =>
14561456
prec.right(
@@ -1566,7 +1566,7 @@ module.exports = grammar({
15661566
seq(
15671567
optional($.type_parameter_modifiers),
15681568
$._type_parameter_possibly_packed,
1569-
optional(seq(":", $._type))
1569+
optional(seq(":", $.type))
15701570
),
15711571
_type_parameter_possibly_packed: ($) =>
15721572
choice(
@@ -1590,7 +1590,7 @@ module.exports = grammar({
15901590
repeat($.attribute),
15911591
field("constrained_type", $._constrained_type),
15921592
choice($._equal_sign, $._eq_eq),
1593-
field("must_equal", $._type)
1593+
field("must_equal", $.type)
15941594
),
15951595
_constrained_type: ($) => choice($.identifier, $.nested_type_identifier),
15961596
nested_type_identifier: ($) =>
@@ -1698,7 +1698,7 @@ module.exports = grammar({
16981698
optional(
16991699
seq(optional($.wildcard_pattern), $.simple_identifier, ":")
17001700
),
1701-
$._type,
1701+
$.type,
17021702
optional(seq($._equal_sign, $.expression))
17031703
),
17041704
","
@@ -1833,9 +1833,9 @@ module.exports = grammar({
18331833
optional($.modifiers),
18341834
"associatedtype",
18351835
field("name", alias($.simple_identifier, $.type_identifier)),
1836-
optional(seq(":", field("must_inherit", $._type))),
1836+
optional(seq(":", field("must_inherit", $.type))),
18371837
optional($.type_constraints),
1838-
optional(seq($._equal_sign, field("default_value", $._type)))
1838+
optional(seq($._equal_sign, field("default_value", $.type)))
18391839
),
18401840
////////////////////////////////
18411841
// Attributes - https://docs.swift.org/swift-book/ReferenceManual/Attributes.html
@@ -1934,8 +1934,8 @@ module.exports = grammar({
19341934
),
19351935
_type_casting_pattern: ($) =>
19361936
choice(
1937-
seq("is", $._type),
1938-
seq(alias($._binding_pattern_no_expr, $.pattern), $._as, $._type)
1937+
seq("is", $.type),
1938+
seq(alias($._binding_pattern_no_expr, $.pattern), $._as, $.type)
19391939
),
19401940
_binding_pattern: ($) =>
19411941
seq(

0 commit comments

Comments
 (0)