Skip to content

Commit 5cc3bee

Browse files
committed
[Parse] Parser update for UnresolvedTernaryExprSyntax
1 parent 755617b commit 5cc3bee

File tree

2 files changed

+5
-14
lines changed

2 files changed

+5
-14
lines changed

lib/Parse/ParseExpr.cpp

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,6 @@ ParserResult<Expr> Parser::parseExprSequence(Diag<> Message,
182182
SmallVector<Expr*, 8> SequencedExprs;
183183
SourceLoc startLoc = Tok.getLoc();
184184
ParserStatus SequenceStatus;
185-
bool PendingTernary = false;
186185

187186
while (true) {
188187
if (isForConditionalDirective && Tok.isAtStartOfLine())
@@ -205,12 +204,6 @@ ParserResult<Expr> Parser::parseExprSequence(Diag<> Message,
205204
}
206205
SequencedExprs.push_back(Primary.get());
207206

208-
// We know we can make a syntax node for ternary expression.
209-
if (PendingTernary) {
210-
SyntaxContext->createNodeInPlace(SyntaxKind::TernaryExpr);
211-
PendingTernary = false;
212-
}
213-
214207
if (SequenceStatus.isError() && !SequenceStatus.hasCodeCompletion())
215208
break;
216209

@@ -245,6 +238,8 @@ ParserResult<Expr> Parser::parseExprSequence(Diag<> Message,
245238
}
246239

247240
case tok::question_infix: {
241+
SyntaxParsingContext TernaryCtx(SyntaxContext,
242+
SyntaxKind::UnresolvedTernaryExpr);
248243
// Save the '?'.
249244
SourceLoc questionLoc = consumeToken();
250245

@@ -280,10 +275,6 @@ ParserResult<Expr> Parser::parseExprSequence(Diag<> Message,
280275
colonLoc);
281276
SequencedExprs.push_back(unresolvedIf);
282277
Message = diag::expected_expr_after_if_colon;
283-
284-
// Wait for the next expression to make a syntax node for ternary
285-
// expression.
286-
PendingTernary = true;
287278
break;
288279
}
289280

test/Syntax/Outputs/round_trip_parse_gen.swift.withkinds

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ class C <MemberDeclBlock>{<MemberDeclListItem><FunctionDecl>
6060
func boolOr<FunctionSignature><ParameterClause>() </ParameterClause><ReturnClause>-> <SimpleTypeIdentifier>Bool </SimpleTypeIdentifier></ReturnClause></FunctionSignature><CodeBlock>{ <ReturnStmt>return <SequenceExpr><BooleanLiteralExpr>true </BooleanLiteralExpr><BinaryOperatorExpr>|| </BinaryOperatorExpr><BooleanLiteralExpr>false </BooleanLiteralExpr></SequenceExpr></ReturnStmt>}</CodeBlock></FunctionDecl></MemberDeclListItem><MemberDeclListItem><FunctionDecl>
6161

6262
func foo2<FunctionSignature><ParameterClause>() </ParameterClause></FunctionSignature><CodeBlock>{<SequenceExpr><DiscardAssignmentExpr>
63-
_ </DiscardAssignmentExpr><AssignmentExpr>= </AssignmentExpr><TernaryExpr><BooleanLiteralExpr>true </BooleanLiteralExpr>? <IntegerLiteralExpr>1 </IntegerLiteralExpr>: <IntegerLiteralExpr>0</IntegerLiteralExpr></TernaryExpr></SequenceExpr><SequenceExpr><DiscardAssignmentExpr>
64-
_ </DiscardAssignmentExpr><AssignmentExpr>= </AssignmentExpr><TernaryExpr><TupleExpr>(<TupleExprElement><SequenceExpr><TernaryExpr><BooleanLiteralExpr>true </BooleanLiteralExpr>? <IntegerLiteralExpr>1 </IntegerLiteralExpr>: <IntegerLiteralExpr>0</IntegerLiteralExpr></TernaryExpr></SequenceExpr></TupleExprElement>) </TupleExpr>? <TupleExpr>(<TupleExprElement><SequenceExpr><TernaryExpr><BooleanLiteralExpr>true </BooleanLiteralExpr>? <IntegerLiteralExpr>1 </IntegerLiteralExpr>: <IntegerLiteralExpr>0</IntegerLiteralExpr></TernaryExpr></SequenceExpr></TupleExprElement>) </TupleExpr>: <TupleExpr>(<TupleExprElement><SequenceExpr><TernaryExpr><BooleanLiteralExpr>true </BooleanLiteralExpr>? <IntegerLiteralExpr>1 </IntegerLiteralExpr>: <IntegerLiteralExpr>0</IntegerLiteralExpr></TernaryExpr></SequenceExpr></TupleExprElement>)</TupleExpr></TernaryExpr></SequenceExpr><SequenceExpr><DiscardAssignmentExpr>
63+
_ </DiscardAssignmentExpr><AssignmentExpr>= </AssignmentExpr><BooleanLiteralExpr>true </BooleanLiteralExpr><UnresolvedTernaryExpr>? <IntegerLiteralExpr>1 </IntegerLiteralExpr>: </UnresolvedTernaryExpr><IntegerLiteralExpr>0</IntegerLiteralExpr></SequenceExpr><SequenceExpr><DiscardAssignmentExpr>
64+
_ </DiscardAssignmentExpr><AssignmentExpr>= </AssignmentExpr><TupleExpr>(<TupleExprElement><SequenceExpr><BooleanLiteralExpr>true </BooleanLiteralExpr><UnresolvedTernaryExpr>? <IntegerLiteralExpr>1 </IntegerLiteralExpr>: </UnresolvedTernaryExpr><IntegerLiteralExpr>0</IntegerLiteralExpr></SequenceExpr></TupleExprElement>) </TupleExpr><UnresolvedTernaryExpr>? <TupleExpr>(<TupleExprElement><SequenceExpr><BooleanLiteralExpr>true </BooleanLiteralExpr><UnresolvedTernaryExpr>? <IntegerLiteralExpr>1 </IntegerLiteralExpr>: </UnresolvedTernaryExpr><IntegerLiteralExpr>0</IntegerLiteralExpr></SequenceExpr></TupleExprElement>) </TupleExpr>: </UnresolvedTernaryExpr><TupleExpr>(<TupleExprElement><SequenceExpr><BooleanLiteralExpr>true </BooleanLiteralExpr><UnresolvedTernaryExpr>? <IntegerLiteralExpr>1 </IntegerLiteralExpr>: </UnresolvedTernaryExpr><IntegerLiteralExpr>0</IntegerLiteralExpr></SequenceExpr></TupleExprElement>)</TupleExpr></SequenceExpr><SequenceExpr><DiscardAssignmentExpr>
6565
_ </DiscardAssignmentExpr><AssignmentExpr>= </AssignmentExpr><TupleExpr>(<TupleExprElement><IntegerLiteralExpr>1</IntegerLiteralExpr>, </TupleExprElement><TupleExprElement><IntegerLiteralExpr>2</IntegerLiteralExpr></TupleExprElement>)</TupleExpr></SequenceExpr><SequenceExpr><DiscardAssignmentExpr>
6666
_ </DiscardAssignmentExpr><AssignmentExpr>= </AssignmentExpr><TupleExpr>(<TupleExprElement>first: <IntegerLiteralExpr>1</IntegerLiteralExpr>, </TupleExprElement><TupleExprElement>second: <IntegerLiteralExpr>2</IntegerLiteralExpr></TupleExprElement>)</TupleExpr></SequenceExpr><SequenceExpr><DiscardAssignmentExpr>
6767
_ </DiscardAssignmentExpr><AssignmentExpr>= </AssignmentExpr><TupleExpr>(<TupleExprElement><IntegerLiteralExpr>1</IntegerLiteralExpr></TupleExprElement>)</TupleExpr></SequenceExpr><SequenceExpr><DiscardAssignmentExpr>
@@ -196,7 +196,7 @@ protocol P<TypeInheritanceClause>: <InheritedType><ClassRestrictionType>class </
196196
func foo<FunctionSignature><ParameterClause>(<FunctionParameter>_ _: <SimpleTypeIdentifier>Int</SimpleTypeIdentifier>,</FunctionParameter><FunctionParameter>
197197
a b: <SimpleTypeIdentifier>Int </SimpleTypeIdentifier><InitializerClause>= <SequenceExpr><IntegerLiteralExpr>3 </IntegerLiteralExpr><BinaryOperatorExpr>+ </BinaryOperatorExpr><IntegerLiteralExpr>2</IntegerLiteralExpr></SequenceExpr></InitializerClause>,</FunctionParameter><FunctionParameter>
198198
_ c: <SimpleTypeIdentifier>Int </SimpleTypeIdentifier><InitializerClause>= <IntegerLiteralExpr>2</IntegerLiteralExpr></InitializerClause>,</FunctionParameter><FunctionParameter>
199-
d _: <SimpleTypeIdentifier>Int </SimpleTypeIdentifier><InitializerClause>= <SequenceExpr><TernaryExpr><BooleanLiteralExpr>true </BooleanLiteralExpr>? <IntegerLiteralExpr>2</IntegerLiteralExpr>: <IntegerLiteralExpr>3</IntegerLiteralExpr></TernaryExpr></SequenceExpr></InitializerClause>,</FunctionParameter><FunctionParameter><Attribute>
199+
d _: <SimpleTypeIdentifier>Int </SimpleTypeIdentifier><InitializerClause>= <SequenceExpr><BooleanLiteralExpr>true </BooleanLiteralExpr><UnresolvedTernaryExpr>? <IntegerLiteralExpr>2</IntegerLiteralExpr>: </UnresolvedTernaryExpr><IntegerLiteralExpr>3</IntegerLiteralExpr></SequenceExpr></InitializerClause>,</FunctionParameter><FunctionParameter><Attribute>
200200
@objc </Attribute>e: <SimpleTypeIdentifier>X </SimpleTypeIdentifier><InitializerClause>= <BooleanLiteralExpr>true</BooleanLiteralExpr></InitializerClause>,</FunctionParameter><FunctionParameter>
201201
f: <AttributedType>inout <SimpleTypeIdentifier>Int</SimpleTypeIdentifier></AttributedType>,</FunctionParameter><FunctionParameter>
202202
g: <SimpleTypeIdentifier>Int</SimpleTypeIdentifier>...,</FunctionParameter><FunctionParameter>

0 commit comments

Comments
 (0)