Skip to content

Commit b1aa6b8

Browse files
committed
adopt new syntax nodes for catch items
1 parent 5c2c4a7 commit b1aa6b8

File tree

3 files changed

+25
-12
lines changed

3 files changed

+25
-12
lines changed

lib/Parse/ParseStmt.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1972,12 +1972,10 @@ ParserResult<CaseStmt> Parser::parseStmtCatch() {
19721972
SmallVector<CaseLabelItem, 1> caseLabelItems;
19731973

19741974
{
1975-
SyntaxParsingContext ListContext(SyntaxContext, SyntaxKind::CaseItemList);
1975+
SyntaxParsingContext ListContext(SyntaxContext, SyntaxKind::CatchItemList);
19761976
bool isFirst = true;
19771977
while (true) {
1978-
SyntaxParsingContext ItemContext(SyntaxContext, SyntaxKind::CaseItem);
1979-
//if (Tok.is(tok::l_brace))
1980-
//ItemContext.setDiscard()
1978+
SyntaxParsingContext ItemContext(SyntaxContext, SyntaxKind::CatchItem);
19811979
GuardedPattern PatternResult;
19821980
parseGuardedPattern(*this, PatternResult, status, boundDecls,
19831981
GuardedPatternContext::Catch, isFirst);

test/Syntax/Outputs/round_trip_parse_gen.swift.withkinds

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -328,11 +328,11 @@ do <CodeBlock>{<SwitchStmt>
328328

329329
func statementTests<FunctionSignature><ParameterClause>() </ParameterClause></FunctionSignature><CodeBlock>{<DoStmt>
330330
do <CodeBlock>{
331-
} </CodeBlock><CatchClause>catch <CaseItem><ExpressionPattern><TupleExpr>(<TupleExprElement><UnresolvedPatternExpr><ValueBindingPattern>var <IdentifierPattern>x</IdentifierPattern></ValueBindingPattern></UnresolvedPatternExpr>, </TupleExprElement><TupleExprElement><UnresolvedPatternExpr><ValueBindingPattern>let <IdentifierPattern>y</IdentifierPattern></ValueBindingPattern></UnresolvedPatternExpr></TupleExprElement>) </TupleExpr></ExpressionPattern></CaseItem><CodeBlock>{
332-
} </CodeBlock></CatchClause><CatchClause>catch <CaseItem><WhereClause>where <BooleanLiteralExpr>false </BooleanLiteralExpr></WhereClause></CaseItem><CodeBlock>{
333-
} </CodeBlock></CatchClause><CatchClause>catch <CaseItem><ValueBindingPattern>let <IdentifierPattern>e </IdentifierPattern></ValueBindingPattern><WhereClause>where <SequenceExpr><MemberAccessExpr><IdentifierExpr>e</IdentifierExpr>.foo </MemberAccessExpr><BinaryOperatorExpr>== </BinaryOperatorExpr><IdentifierExpr>bar </IdentifierExpr></SequenceExpr></WhereClause></CaseItem><CodeBlock>{
334-
} </CodeBlock></CatchClause><CatchClause>catch <CaseItem><ExpressionPattern><FunctionCallExpr><MemberAccessExpr>.a</MemberAccessExpr>(<TupleExprElement><UnresolvedPatternExpr><ValueBindingPattern>let <IdentifierPattern>a</IdentifierPattern></ValueBindingPattern></UnresolvedPatternExpr></TupleExprElement>)</FunctionCallExpr></ExpressionPattern>, </CaseItem><CaseItem><ExpressionPattern><FunctionCallExpr><MemberAccessExpr>.b</MemberAccessExpr>(<TupleExprElement><UnresolvedPatternExpr><ValueBindingPattern>let <IdentifierPattern>b</IdentifierPattern></ValueBindingPattern></UnresolvedPatternExpr></TupleExprElement>) </FunctionCallExpr></ExpressionPattern><WhereClause>where <SequenceExpr><IdentifierExpr>b </IdentifierExpr><BinaryOperatorExpr>== </BinaryOperatorExpr><StringLiteralExpr>"<StringSegment></StringSegment>" </StringLiteralExpr></SequenceExpr></WhereClause></CaseItem><CodeBlock>{
335-
} </CodeBlock></CatchClause><CatchClause>catch <CaseItem></CaseItem><CodeBlock>{
331+
} </CodeBlock><CatchClause>catch <CatchItem><ExpressionPattern><TupleExpr>(<TupleExprElement><UnresolvedPatternExpr><ValueBindingPattern>var <IdentifierPattern>x</IdentifierPattern></ValueBindingPattern></UnresolvedPatternExpr>, </TupleExprElement><TupleExprElement><UnresolvedPatternExpr><ValueBindingPattern>let <IdentifierPattern>y</IdentifierPattern></ValueBindingPattern></UnresolvedPatternExpr></TupleExprElement>) </TupleExpr></ExpressionPattern></CatchItem><CodeBlock>{
332+
} </CodeBlock></CatchClause><CatchClause>catch <CatchItem><WhereClause>where <BooleanLiteralExpr>false </BooleanLiteralExpr></WhereClause></CatchItem><CodeBlock>{
333+
} </CodeBlock></CatchClause><CatchClause>catch <CatchItem><ValueBindingPattern>let <IdentifierPattern>e </IdentifierPattern></ValueBindingPattern><WhereClause>where <SequenceExpr><MemberAccessExpr><IdentifierExpr>e</IdentifierExpr>.foo </MemberAccessExpr><BinaryOperatorExpr>== </BinaryOperatorExpr><IdentifierExpr>bar </IdentifierExpr></SequenceExpr></WhereClause></CatchItem><CodeBlock>{
334+
} </CodeBlock></CatchClause><CatchClause>catch <CatchItem><ExpressionPattern><FunctionCallExpr><MemberAccessExpr>.a</MemberAccessExpr>(<TupleExprElement><UnresolvedPatternExpr><ValueBindingPattern>let <IdentifierPattern>a</IdentifierPattern></ValueBindingPattern></UnresolvedPatternExpr></TupleExprElement>)</FunctionCallExpr></ExpressionPattern>, </CatchItem><CatchItem><ExpressionPattern><FunctionCallExpr><MemberAccessExpr>.b</MemberAccessExpr>(<TupleExprElement><UnresolvedPatternExpr><ValueBindingPattern>let <IdentifierPattern>b</IdentifierPattern></ValueBindingPattern></UnresolvedPatternExpr></TupleExprElement>) </FunctionCallExpr></ExpressionPattern><WhereClause>where <SequenceExpr><IdentifierExpr>b </IdentifierExpr><BinaryOperatorExpr>== </BinaryOperatorExpr><StringLiteralExpr>"<StringSegment></StringSegment>" </StringLiteralExpr></SequenceExpr></WhereClause></CatchItem><CodeBlock>{
335+
} </CodeBlock></CatchClause><CatchClause>catch <CatchItem></CatchItem><CodeBlock>{
336336
}</CodeBlock></CatchClause></DoStmt><RepeatWhileStmt>
337337
repeat <CodeBlock>{ } </CodeBlock>while <BooleanLiteralExpr>true</BooleanLiteralExpr></RepeatWhileStmt><RepeatWhileStmt>
338338
LABEL: repeat <CodeBlock>{ } </CodeBlock>while <BooleanLiteralExpr>false</BooleanLiteralExpr></RepeatWhileStmt><WhileStmt>

utils/gyb_syntax_support/StmtNodes.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,10 @@
176176
# case-item-list -> case-item case-item-list?
177177
Node('CaseItemList', kind='SyntaxCollection',
178178
element='CaseItem'),
179+
180+
# catch-item-list -> catch-item catch-item-list?
181+
Node('CatchItemList', kind='SyntaxCollection',
182+
element='CatchItem'),
179183

180184
# condition -> expression
181185
# | availability-condition
@@ -304,8 +308,19 @@
304308
Child('Colon', kind='ColonToken'),
305309
]),
306310

307-
# case-item -> pattern? where-clause? ','?
311+
# case-item -> pattern where-clause? ','?
308312
Node('CaseItem', kind='Syntax',
313+
traits=['WithTrailingComma'],
314+
children=[
315+
Child('Pattern', kind='Pattern'),
316+
Child('WhereClause', kind='WhereClause',
317+
is_optional=True),
318+
Child('TrailingComma', kind='CommaToken',
319+
is_optional=True),
320+
]),
321+
322+
# catch-item -> pattern? where-clause? ','?
323+
Node('CatchItem', kind='Syntax',
309324
traits=['WithTrailingComma'],
310325
children=[
311326
Child('Pattern', kind='Pattern', is_optional=True),
@@ -329,8 +344,8 @@
329344
traits=['WithCodeBlock'],
330345
children=[
331346
Child('CatchKeyword', kind='CatchToken'),
332-
Child('CaseItems', kind='CaseItemList',
333-
collection_element_name='CaseItem', is_optional=True),
347+
Child('CatchItems', kind='CatchItemList',
348+
collection_element_name='CatchItem', is_optional=True),
334349
Child('Body', kind='CodeBlock'),
335350
]),
336351

0 commit comments

Comments
 (0)