Skip to content

Commit bdebd8a

Browse files
committed
SwiftSyntax: add WithTrailingCommanSyntax trait and fix inconsistent naming. NFC
1 parent 4d9e1b0 commit bdebd8a

File tree

5 files changed

+19
-2
lines changed

5 files changed

+19
-2
lines changed

utils/gyb_syntax_support/DeclNodes.py

+3
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@
138138
]),
139139

140140
Node('InheritedType', kind='Syntax',
141+
traits=['WithTrailingComma'],
141142
children=[
142143
Child('TypeName', kind='Type'),
143144
Child('TrailingComma', kind='CommaToken', is_optional=True),
@@ -269,6 +270,7 @@
269270
# external-parameter-name? local-parameter-name ':'
270271
# type '...'? '='? expression? ','?
271272
Node('FunctionParameter', kind='Syntax',
273+
traits=['WithTrailingComma'],
272274
children=[
273275
Child('Attributes', kind='AttributeList',
274276
is_optional=True),
@@ -483,6 +485,7 @@
483485

484486
# Pattern: Type = Value { get {} },
485487
Node('PatternBinding', kind="Syntax",
488+
traits=['WithTrailingComma'],
486489
children=[
487490
Child('Pattern', kind='Pattern'),
488491
Child('TypeAnnotation', kind='TypeAnnotation', is_optional=True),

utils/gyb_syntax_support/ExprNodes.py

+6
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@
220220

221221
# function-call-argument -> label? ':'? expression ','?
222222
Node('FunctionCallArgument', kind='Syntax',
223+
traits=['WithTrailingComma'],
223224
children=[
224225
Child('Label', kind='IdentifierToken',
225226
is_optional=True),
@@ -232,6 +233,7 @@
232233

233234
# An element inside a tuple element list
234235
Node('TupleElement', kind='Syntax',
236+
traits=['WithTrailingComma'],
235237
children=[
236238
Child('Label', kind='IdentifierToken',
237239
is_optional=True),
@@ -244,13 +246,15 @@
244246

245247
# element inside an array expression: expression ','?
246248
Node('ArrayElement', kind='Syntax',
249+
traits=['WithTrailingComma'],
247250
children=[
248251
Child('Expression', kind='Expr'),
249252
Child('TrailingComma', kind='CommaToken', is_optional=True),
250253
]),
251254

252255
# element inside an array expression: expression ','?
253256
Node('DictionaryElement', kind='Syntax',
257+
traits=['WithTrailingComma'],
254258
children=[
255259
Child('KeyExpression', kind='Expr'),
256260
Child('Colon', kind='ColonToken'),
@@ -340,6 +344,7 @@
340344
]),
341345

342346
Node('ClosureCaptureItem', kind='Syntax',
347+
traits=['WithTrailingComma'],
343348
children=[
344349
Child("Specifier", kind='TokenList', is_optional=True),
345350
Child("Name", kind='IdentifierToken', is_optional=True),
@@ -359,6 +364,7 @@
359364
]),
360365

361366
Node('ClosureParam', kind='Syntax',
367+
traits=['WithTrailingComma'],
362368
children=[
363369
Child('Name', kind='Token',
364370
token_choices=[

utils/gyb_syntax_support/PatternNodes.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,14 @@
6868

6969
# tuple-pattern-element -> identifier? ':' pattern ','?
7070
Node('TuplePatternElement', kind='Syntax',
71+
traits=['WithTrailingComma'],
7172
children=[
7273
Child('LabelName', kind='IdentifierToken',
7374
is_optional=True),
7475
Child('Colon', kind='ColonToken',
7576
is_optional=True),
7677
Child('Pattern', kind='Pattern'),
77-
Child('Comma', kind='CommaToken',
78+
Child('TrailingComma', kind='CommaToken',
7879
is_optional=True),
7980
]),
8081

utils/gyb_syntax_support/StmtNodes.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@
158158
# | case-condition
159159
# | optional-binding-condition
160160
Node('ConditionElement', kind='Syntax',
161+
traits=['WithTrailingComma'],
161162
children=[
162163
Child('Condition', kind='Syntax',
163164
node_choices=[
@@ -268,11 +269,12 @@
268269

269270
# case-item -> pattern where-clause? ','?
270271
Node('CaseItem', kind='Syntax',
272+
traits=['WithTrailingComma'],
271273
children=[
272274
Child('Pattern', kind='Pattern'),
273275
Child('WhereClause', kind='WhereClause',
274276
is_optional=True),
275-
Child('Comma', kind='CommaToken',
277+
Child('TrailingComma', kind='CommaToken',
276278
is_optional=True),
277279
]),
278280

utils/gyb_syntax_support/Traits.py

+5
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,9 @@ def __init__(self, trait_name, children):
3737
Child('LeftParen', kind='LeftParenToken'),
3838
Child('RightParen', kind='RightParenToken'),
3939
]),
40+
41+
Trait('WithTrailingComma',
42+
children=[
43+
Child('TrailingComma', kind='CommaToken', is_optional=True),
44+
])
4045
]

0 commit comments

Comments
 (0)