Skip to content

Commit 463d8a7

Browse files
committed
Unified: Handle additionalTrailingClosures for more expression kinds
1 parent 781d2b9 commit 463d8a7

3 files changed

Lines changed: 65 additions & 8 deletions

File tree

‎unified/extractor/src/languages/swift/swift.rs‎

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,8 @@ fn translation_rules() -> Vec<Rule<SwiftContext>> {
671671
calledExpression: (arrayExpr
672672
elements: (arrayElement expression: (genericSpecializationExpr) @element)) @@array
673673
arguments: _* @args
674-
trailingClosure: @tc)
674+
trailingClosure: @tc
675+
additionalTrailingClosures: _* @additional)
675676
=>
676677
call_expr {
677678
let callee = tree_at!(
@@ -683,7 +684,8 @@ fn translation_rules() -> Vec<Rule<SwiftContext>> {
683684
tree!((call_expr
684685
callee: {callee}
685686
argument: {args}
686-
argument: (argument value: {tc})))
687+
argument: (argument value: {tc})
688+
argument: {additional}))
687689
}
688690
),
689691
rule!(
@@ -705,12 +707,14 @@ fn translation_rules() -> Vec<Rule<SwiftContext>> {
705707
// A function/method call (`foo(1, 2)`). `calledExpression` is the callee
706708
// and `arguments` is an (elided) list of `labeledExpr`, each translated
707709
// to an `argument` below. A trailing closure (`xs.map { … }`) becomes
708-
// a final unlabelled argument.
710+
// a final unlabelled argument, followed by any additional labeled
711+
// trailing closures.
709712
rule!(
710713
(functionCallExpr
711714
calledExpression: @@rawCallee
712715
arguments: _* @args
713-
trailingClosure: _? @trailing)
716+
trailingClosure: _? @trailing
717+
additionalTrailingClosures: _* @additional)
714718
=>
715719
expr {
716720
// Always translate the callee in non-pattern context.
@@ -722,6 +726,7 @@ fn translation_rules() -> Vec<Rule<SwiftContext>> {
722726
callee: {callee}
723727
argument: {args}
724728
argument: {trailing.map(|trailing| tree!((argument value: {trailing})))}
729+
argument: {additional}
725730
))
726731
}
727732
),
@@ -1021,9 +1026,17 @@ fn translation_rules() -> Vec<Rule<SwiftContext>> {
10211026
// subscripts their own shape needs only a `subscript_expr` node in
10221027
// ast_types.yml and a remap here.
10231028
rule!(
1024-
(subscriptCallExpr calledExpression: @callee arguments: _* @args)
1029+
(subscriptCallExpr
1030+
calledExpression: @callee
1031+
arguments: _* @args
1032+
trailingClosure: _? @trailing
1033+
additionalTrailingClosures: _* @additional)
10251034
=>
1026-
(call_expr callee: {callee} argument: {args})
1035+
(call_expr
1036+
callee: {callee}
1037+
argument: {args}
1038+
argument: {trailing.map(|trailing| tree!((argument value: {trailing})))}
1039+
argument: {additional})
10271040
),
10281041
// ---- Optionals and errors ----
10291042
// Optional chaining — unwrap the marker

‎unified/extractor/tests/corpus/swift/expressions/subscript-call.output‎

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,34 @@ top_level source="⟨body⟩"
104104
argument:
105105
argument source="⟨value⟩"
106106
value: int_literal "0" source="0"
107-
call_expr source="⟨callee⟩[⟨argument⟩] {\n first()\n} completion: {\n second()\n} failure: {\n third()\n}"
107+
call_expr source="⟨callee⟩[⟨argument⟩] ⟨argument⟩ ⟨argument⟩ ⟨argument⟩"
108108
callee: identifier "handlers" source="handlers"
109109
argument:
110110
argument source="⟨value⟩"
111111
value: int_literal "0" source="0"
112+
argument source="⟨value⟩"
113+
value:
114+
function_expr source="{\n ⟨body⟩\n}"
115+
body:
116+
block source="⟨stmt⟩"
117+
stmt:
118+
call_expr source="⟨callee⟩()"
119+
callee: identifier "first" source="first"
120+
argument source="⟨name_node⟩: ⟨value⟩"
121+
name_node: identifier "completion" source="completion"
122+
value:
123+
function_expr source="{\n ⟨body⟩\n}"
124+
body:
125+
block source="⟨stmt⟩"
126+
stmt:
127+
call_expr source="⟨callee⟩()"
128+
callee: identifier "second" source="second"
129+
argument source="⟨name_node⟩: ⟨value⟩"
130+
name_node: identifier "failure" source="failure"
131+
value:
132+
function_expr source="{\n ⟨body⟩\n}"
133+
body:
134+
block source="⟨stmt⟩"
135+
stmt:
136+
call_expr source="⟨callee⟩()"
137+
callee: identifier "third" source="third"

‎unified/extractor/tests/corpus/swift/functions/function-call.output‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ top_level source="⟨body⟩"
105105
value: int_literal "1" source="1"
106106
argument source="⟨value⟩"
107107
value: int_literal "2" source="2"
108-
call_expr source="⟨callee⟩ ⟨argument⟩ completion: {\n second()\n} failure: {\n third()\n}"
108+
call_expr source="⟨callee⟩ ⟨argument⟩ ⟨argument⟩ ⟨argument⟩"
109109
callee: identifier "handle" source="handle"
110110
argument:
111111
argument source="⟨value⟩"
@@ -116,3 +116,21 @@ top_level source="⟨body⟩"
116116
stmt:
117117
call_expr source="⟨callee⟩()"
118118
callee: identifier "first" source="first"
119+
argument source="⟨name_node⟩: ⟨value⟩"
120+
name_node: identifier "completion" source="completion"
121+
value:
122+
function_expr source="{\n ⟨body⟩\n}"
123+
body:
124+
block source="⟨stmt⟩"
125+
stmt:
126+
call_expr source="⟨callee⟩()"
127+
callee: identifier "second" source="second"
128+
argument source="⟨name_node⟩: ⟨value⟩"
129+
name_node: identifier "failure" source="failure"
130+
value:
131+
function_expr source="{\n ⟨body⟩\n}"
132+
body:
133+
block source="⟨stmt⟩"
134+
stmt:
135+
call_expr source="⟨callee⟩()"
136+
callee: identifier "third" source="third"

0 commit comments

Comments
 (0)