Skip to content

Commit 02661b3

Browse files
committed
SwiftSyntax: Add LabeledSyntax trait. NFC
This commit also adds several "WithTrailingComma" I've missed in the previous commit.
1 parent bdebd8a commit 02661b3

File tree

5 files changed

+20
-9
lines changed

5 files changed

+20
-9
lines changed

utils/gyb_syntax_support/GenericNodes.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
# same-type-requirement -> type-identifier == type
1717
Node('SameTypeRequirement', kind='Syntax',
18+
traits=['WithTrailingComma'],
1819
children=[
1920
Child('LeftTypeIdentifier', kind='Type'),
2021
Child('EqualityToken', kind='Token',
@@ -34,6 +35,7 @@
3435
# | type-name : type-identifier
3536
# | type-name : protocol-composition-type
3637
Node('GenericParameter', kind='Syntax',
38+
traits=['WithTrailingComma'],
3739
children=[
3840
Child('Attributes', kind='AttributeList',
3941
is_optional=True),
@@ -56,6 +58,7 @@
5658

5759
# conformance-requirement -> type-identifier : type-identifier
5860
Node('ConformanceRequirement', kind='Syntax',
61+
traits=['WithTrailingComma'],
5962
children=[
6063
Child('LeftTypeIdentifier', kind='Type'),
6164
Child('Colon', kind='ColonToken'),

utils/gyb_syntax_support/PatternNodes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,11 @@
6868

6969
# tuple-pattern-element -> identifier? ':' pattern ','?
7070
Node('TuplePatternElement', kind='Syntax',
71-
traits=['WithTrailingComma'],
71+
traits=['WithTrailingComma', 'Labeled'],
7272
children=[
7373
Child('LabelName', kind='IdentifierToken',
7474
is_optional=True),
75-
Child('Colon', kind='ColonToken',
75+
Child('LabelColon', kind='ColonToken',
7676
is_optional=True),
7777
Child('Pattern', kind='Pattern'),
7878
Child('TrailingComma', kind='CommaToken',

utils/gyb_syntax_support/StmtNodes.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
# while-stmt -> label? ':'? 'while' condition-list code-block ';'?
1414
Node('WhileStmt', kind='Stmt',
15-
traits=['WithCodeBlock'],
15+
traits=['WithCodeBlock', 'Labeled'],
1616
children=[
1717
Child('LabelName', kind='IdentifierToken',
1818
is_optional=True),
@@ -43,7 +43,7 @@
4343

4444
# repeat-while-stmt -> label? ':'? 'repeat' code-block 'while' expr ';'?
4545
Node('RepeatWhileStmt', kind='Stmt',
46-
traits=['WithCodeBlock'],
46+
traits=['WithCodeBlock', 'Labeled'],
4747
children=[
4848
Child('LabelName', kind='IdentifierToken',
4949
is_optional=True),
@@ -74,7 +74,7 @@
7474
# for-in-stmt -> label? ':'? 'for' 'case'? pattern 'in' expr 'where'?
7575
# expr code-block ';'?
7676
Node('ForInStmt', kind='Stmt',
77-
traits=['WithCodeBlock'],
77+
traits=['WithCodeBlock', 'Labeled'],
7878
children=[
7979
Child('LabelName', kind='IdentifierToken',
8080
is_optional=True),
@@ -96,7 +96,7 @@
9696
# switch-stmt -> identifier? ':'? 'switch' expr '{'
9797
# switch-case-list '}' ';'?
9898
Node('SwitchStmt', kind='Stmt',
99-
traits=['Braced'],
99+
traits=['Braced', 'Labeled'],
100100
children=[
101101
Child('LabelName', kind='IdentifierToken',
102102
is_optional=True),
@@ -115,7 +115,7 @@
115115

116116
# do-stmt -> identifier? ':'? 'do' code-block catch-clause-list ';'?
117117
Node('DoStmt', kind='Stmt',
118-
traits=['WithCodeBlock'],
118+
traits=['WithCodeBlock', 'Labeled'],
119119
children=[
120120
Child('LabelName', kind='IdentifierToken',
121121
is_optional=True),
@@ -219,7 +219,7 @@
219219
# if-stmt -> identifier? ':'? 'if' condition-list code-block
220220
# else-clause ';'?
221221
Node('IfStmt', kind='Stmt',
222-
traits=['WithCodeBlock'],
222+
traits=['WithCodeBlock', 'Labeled'],
223223
children=[
224224
Child('LabelName', kind='IdentifierToken',
225225
is_optional=True),

utils/gyb_syntax_support/Traits.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,11 @@ def __init__(self, trait_name, children):
4141
Trait('WithTrailingComma',
4242
children=[
4343
Child('TrailingComma', kind='CommaToken', is_optional=True),
44-
])
44+
]),
45+
46+
Trait('Labeled',
47+
children=[
48+
Child('LabelName', kind='IdentifierToken', is_optional=True),
49+
Child('LabelColon', kind='ColonToken', is_optional=True),
50+
]),
4551
]

utils/gyb_syntax_support/TypeNodes.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101

102102
# tuple-type-element -> identifier? ':'? type-annotation ','?
103103
Node('TupleTypeElement', kind='Syntax',
104+
traits=['WithTrailingComma'],
104105
children=[
105106
Child('InOut', kind='InOutToken',
106107
is_optional=True),
@@ -180,6 +181,7 @@
180181
# Dictionary<Int, String>
181182
# ^~~~ ^~~~~~
182183
Node('GenericArgument', kind='Syntax',
184+
traits=['WithTrailingComma'],
183185
children=[
184186
Child('ArgumentType', kind='Type'),
185187
Child('TrailingComma', kind='CommaToken',

0 commit comments

Comments
 (0)