Skip to content

Commit c8f7c3d

Browse files
committed
unified: Group more paired items
Same as in the preceding commit, these items do not make sense as separate fields on the parent node, so we materialise (or create new) intermediate nodes to group them together.
1 parent ea6f3a9 commit c8f7c3d

2 files changed

Lines changed: 27 additions & 19 deletions

File tree

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

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ module.exports = grammar({
105105
// { (foo, bar) ...
106106
[$.expression, $.lambda_parameter],
107107
[$._primary_expression, $.lambda_parameter],
108-
// (start: start, end: end)
109-
[$._tuple_type_item_identifier, $.tuple_expression],
108+
// (foo) where foo could be a binding pattern or a tuple expression item.
109+
[$._binding_pattern_with_expr, $.tuple_expression_item],
110110
// After a `{` in a function or switch context, it's ambigous whether we're starting a set of local statements or
111111
// applying some modifiers to a capture or pattern.
112112
[$.modifiers],
@@ -931,26 +931,25 @@ module.exports = grammar({
931931
PRECS.tuple,
932932
seq(
933933
"(",
934-
sep1Opt(
935-
seq(
936-
optional(seq(field("name", $.simple_identifier), ":")),
937-
field("value", $.expression)
938-
),
939-
","
940-
),
934+
sep1Opt(field("element", $.tuple_expression_item), ","),
941935
")"
942936
)
943937
),
938+
tuple_expression_item: ($) =>
939+
seq(
940+
optional(seq(field("name", $.simple_identifier), ":")),
941+
field("value", $.expression)
942+
),
944943
array_literal: ($) =>
945944
seq("[", optional(sep1Opt(field("element", $.expression), ",")), "]"),
946945
dictionary_literal: ($) =>
947946
seq(
948947
"[",
949-
choice(":", sep1Opt($._dictionary_literal_item, ",")),
948+
choice(":", sep1Opt(field("element", $.dictionary_literal_item), ",")),
950949
optional(","),
951950
"]"
952951
),
953-
_dictionary_literal_item: ($) =>
952+
dictionary_literal_item: ($) =>
954953
seq(field("key", $.expression), ":", field("value", $.expression)),
955954
special_literal: ($) =>
956955
seq(
@@ -968,11 +967,13 @@ module.exports = grammar({
968967
playground_literal: ($) =>
969968
seq(
970969
$._hash_symbol,
971-
choice("colorLiteral", "fileLiteral", "imageLiteral"),
970+
field("kind", choice("colorLiteral", "fileLiteral", "imageLiteral")),
972971
"(",
973-
sep1Opt(seq(field("name", $.simple_identifier), ":", field("value", $.expression)), ","),
972+
sep1Opt(field("argument", $.playground_literal_argument), ","),
974973
")"
975974
),
975+
playground_literal_argument: ($) =>
976+
seq(field("name", $.simple_identifier), ":", field("value", $.expression)),
976977
lambda_literal: ($) =>
977978
prec.left(
978979
PRECS.lambda,

unified/extractor/tree-sitter-swift/node-types.yml

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,10 @@ named:
248248
entry*: [bin_literal, boolean_literal, hex_literal, integer_literal, line_string_literal, multi_line_string_literal, "nil", oct_literal, raw_string_literal, real_literal, regex_literal, simple_identifier]
249249
diagnostic:
250250
dictionary_literal:
251-
key*: expression
252-
value*: expression
251+
element*: dictionary_literal_item
252+
dictionary_literal_item:
253+
key: expression
254+
value: expression
253255
dictionary_type:
254256
key: type
255257
value: type
@@ -483,8 +485,11 @@ named:
483485
bound_identifier?: simple_identifier
484486
kind: [binding_pattern, case_pattern, expression, tuple_pattern, type_casting_pattern, wildcard_pattern]
485487
playground_literal:
486-
name+: simple_identifier
487-
value+: expression
488+
argument+: playground_literal_argument
489+
kind: ["colorLiteral", "fileLiteral", "imageLiteral"]
490+
playground_literal_argument:
491+
name: simple_identifier
492+
value: expression
488493
postfix_expression:
489494
operation: ["++", "--", bang]
490495
target: expression
@@ -613,8 +618,10 @@ named:
613618
operator: try_operator
614619
try_operator:
615620
tuple_expression:
616-
name*: simple_identifier
617-
value+: expression
621+
element+: tuple_expression_item
622+
tuple_expression_item:
623+
name?: simple_identifier
624+
value: expression
618625
tuple_pattern:
619626
item+: tuple_pattern_item
620627
tuple_pattern_item:

0 commit comments

Comments
 (0)