Skip to content

Commit 72b683d

Browse files
asgerfCopilot
andcommitted
Unified: Add Swift corpus tests
Add corpus test cases for Swift covering closures, collections, control flow, functions, literals, loops, operators, optionals/errors, types, and variables. Update existing desugar.txt with raw parse sections. Note: operator nodes currently render their node ID instead of the actual operator text (e.g. operator "3" instead of operator "+"). This will be fixed in the next commit. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 8a2a48d commit 72b683d

11 files changed

Lines changed: 2582 additions & 2 deletions

File tree

Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
===
2+
Closure with explicit parameters
3+
===
4+
5+
let f = { (x: Int) -> Int in x * 2 }
6+
7+
---
8+
9+
source_file
10+
property_declaration
11+
name:
12+
pattern
13+
bound_identifier: simple_identifier "f"
14+
value:
15+
lambda_literal
16+
type:
17+
lambda_function_type
18+
name:
19+
user_type
20+
type_identifier "Int"
21+
lambda_function_type_parameters
22+
lambda_parameter
23+
name:
24+
simple_identifier "x"
25+
user_type
26+
type_identifier "Int"
27+
statements
28+
multiplicative_expression
29+
lhs: simple_identifier "x"
30+
op: *
31+
rhs: integer_literal "2"
32+
value_binding_pattern
33+
mutability: let
34+
35+
---
36+
37+
top_level
38+
body: unsupported_node "let f = { (x: Int) -> Int in x * 2 }"
39+
40+
===
41+
Closure with shorthand parameters
42+
===
43+
44+
let f = { $0 + $1 }
45+
46+
---
47+
48+
source_file
49+
property_declaration
50+
name:
51+
pattern
52+
bound_identifier: simple_identifier "f"
53+
value:
54+
lambda_literal
55+
statements
56+
additive_expression
57+
lhs: simple_identifier "$0"
58+
op: +
59+
rhs: simple_identifier "$1"
60+
value_binding_pattern
61+
mutability: let
62+
63+
---
64+
65+
top_level
66+
body: unsupported_node "let f = { $0 + $1 }"
67+
68+
===
69+
Trailing closure
70+
===
71+
72+
xs.map { $0 * 2 }
73+
74+
---
75+
76+
source_file
77+
call_expression
78+
navigation_expression
79+
suffix:
80+
navigation_suffix
81+
suffix: simple_identifier "map"
82+
target: simple_identifier "xs"
83+
call_suffix
84+
lambda_literal
85+
statements
86+
multiplicative_expression
87+
lhs: simple_identifier "$0"
88+
op: *
89+
rhs: integer_literal "2"
90+
91+
---
92+
93+
top_level
94+
body: unsupported_node "xs.map { $0 * 2 }"
95+
96+
===
97+
Closure with capture list
98+
===
99+
100+
let f = { [weak self] in self?.doThing() }
101+
102+
---
103+
104+
source_file
105+
property_declaration
106+
name:
107+
pattern
108+
bound_identifier: simple_identifier "f"
109+
value:
110+
lambda_literal
111+
captures:
112+
capture_list
113+
capture_list_item
114+
name: simple_identifier "self"
115+
ownership_modifier
116+
statements
117+
call_expression
118+
navigation_expression
119+
suffix:
120+
navigation_suffix
121+
suffix: simple_identifier "doThing"
122+
target:
123+
self_expression
124+
?
125+
call_suffix
126+
value_arguments
127+
value_binding_pattern
128+
mutability: let
129+
130+
---
131+
132+
top_level
133+
body: unsupported_node "let f = { [weak self] in self?.doThing() }"
134+
135+
===
136+
Multi-statement closure
137+
===
138+
139+
let f = { (x: Int) -> Int in
140+
let y = x + 1
141+
return y * 2
142+
}
143+
144+
---
145+
146+
source_file
147+
property_declaration
148+
name:
149+
pattern
150+
bound_identifier: simple_identifier "f"
151+
value:
152+
lambda_literal
153+
type:
154+
lambda_function_type
155+
name:
156+
user_type
157+
type_identifier "Int"
158+
lambda_function_type_parameters
159+
lambda_parameter
160+
name:
161+
simple_identifier "x"
162+
user_type
163+
type_identifier "Int"
164+
statements
165+
property_declaration
166+
name:
167+
pattern
168+
bound_identifier: simple_identifier "y"
169+
value:
170+
additive_expression
171+
lhs: simple_identifier "x"
172+
op: +
173+
rhs: integer_literal "1"
174+
value_binding_pattern
175+
mutability: let
176+
control_transfer_statement
177+
result:
178+
multiplicative_expression
179+
lhs: simple_identifier "y"
180+
op: *
181+
rhs: integer_literal "2"
182+
value_binding_pattern
183+
mutability: let
184+
185+
---
186+
187+
top_level
188+
body: unsupported_node "let f = { (x: Int) -> Int in\n let y = x + 1\n return y * 2\n}"

0 commit comments

Comments
 (0)