@@ -62,14 +62,8 @@ ParserResult<Expr> Parser::parseExprImpl(Diag<> Message,
62
62
return makeParserResult (new (Context) UnresolvedPatternExpr (pattern.get ()));
63
63
}
64
64
65
- auto expr = parseExprSequence (Message, isExprBasic,
65
+ return parseExprSequence (Message, isExprBasic,
66
66
/* forConditionalDirective*/ false );
67
- if (expr.hasCodeCompletion ())
68
- return expr;
69
- if (expr.isNull ())
70
- return nullptr ;
71
-
72
- return makeParserResult (expr.get ());
73
67
}
74
68
75
69
// / parseExprIs
@@ -173,7 +167,7 @@ ParserResult<Expr> Parser::parseExprSequence(Diag<> Message,
173
167
174
168
SmallVector<Expr*, 8 > SequencedExprs;
175
169
SourceLoc startLoc = Tok.getLoc ();
176
- bool HasCodeCompletion = false ;
170
+ ParserStatus SequenceStatus ;
177
171
bool PendingTernary = false ;
178
172
179
173
while (true ) {
@@ -183,20 +177,18 @@ ParserResult<Expr> Parser::parseExprSequence(Diag<> Message,
183
177
// Parse a unary expression.
184
178
ParserResult<Expr> Primary =
185
179
parseExprSequenceElement (Message, isExprBasic);
180
+ SequenceStatus |= Primary;
186
181
187
- if (Primary.hasCodeCompletion ()) {
188
- HasCodeCompletion = true ;
189
- if (CodeCompletion)
182
+ if (SequenceStatus.hasCodeCompletion () && CodeCompletion)
190
183
CodeCompletion->setLeadingSequenceExprs (SequencedExprs);
191
- }
184
+
192
185
if (Primary.isNull ()) {
193
- if (HasCodeCompletion ) {
186
+ if (SequenceStatus. hasCodeCompletion () ) {
194
187
SequencedExprs.push_back (new (Context) CodeCompletionExpr (PreviousLoc));
195
188
break ;
196
189
}
197
- return Primary ;
190
+ return nullptr ;
198
191
}
199
-
200
192
SequencedExprs.push_back (Primary.get ());
201
193
202
194
// We know we can make a syntax node for ternary expression.
@@ -205,6 +197,9 @@ ParserResult<Expr> Parser::parseExprSequence(Diag<> Message,
205
197
PendingTernary = false ;
206
198
}
207
199
200
+ if (SequenceStatus.isError () && !SequenceStatus.hasCodeCompletion ())
201
+ break ;
202
+
208
203
if (isForConditionalDirective && Tok.isAtStartOfLine ())
209
204
break ;
210
205
@@ -242,9 +237,8 @@ ParserResult<Expr> Parser::parseExprSequence(Diag<> Message,
242
237
// Parse the middle expression of the ternary.
243
238
ParserResult<Expr> middle =
244
239
parseExprSequence (diag::expected_expr_after_if_question, isExprBasic);
240
+ SequenceStatus |= middle;
245
241
ParserStatus Status = middle;
246
- if (middle.hasCodeCompletion ())
247
- HasCodeCompletion = true ;
248
242
if (middle.isNull ())
249
243
return nullptr ;
250
244
@@ -304,6 +298,7 @@ ParserResult<Expr> Parser::parseExprSequence(Diag<> Message,
304
298
305
299
// Store the expr itself as a placeholder RHS. The real RHS is the
306
300
// type parameter stored in the node itself.
301
+ SequenceStatus |= is;
307
302
SequencedExprs.push_back (is.get ());
308
303
SequencedExprs.push_back (is.get ());
309
304
@@ -320,6 +315,7 @@ ParserResult<Expr> Parser::parseExprSequence(Diag<> Message,
320
315
321
316
// Store the expr itself as a placeholder RHS. The real RHS is the
322
317
// type parameter stored in the node itself.
318
+ SequenceStatus |= as;
323
319
SequencedExprs.push_back (as.get ());
324
320
SequencedExprs.push_back (as.get ());
325
321
@@ -334,6 +330,7 @@ ParserResult<Expr> Parser::parseExprSequence(Diag<> Message,
334
330
ParserResult<Expr> arrow = parseExprArrow ();
335
331
if (arrow.isNull () || arrow.hasCodeCompletion ())
336
332
return arrow;
333
+ SequenceStatus |= arrow;
337
334
SequencedExprs.push_back (arrow.get ());
338
335
break ;
339
336
}
@@ -356,19 +353,13 @@ ParserResult<Expr> Parser::parseExprSequence(Diag<> Message,
356
353
assert (!SequencedExprs.empty ());
357
354
358
355
// If we saw no operators, don't build a sequence.
359
- if (SequencedExprs.size () == 1 ) {
360
- auto Result = makeParserResult (SequencedExprs[0 ]);
361
- if (HasCodeCompletion)
362
- Result.setHasCodeCompletion ();
363
- return Result;
364
- }
356
+ if (SequencedExprs.size () == 1 )
357
+ return makeParserResult (SequenceStatus, SequencedExprs[0 ]);
365
358
366
359
ExprSequnceContext.createNodeInPlace (SyntaxKind::ExprList);
367
360
ExprSequnceContext.setCreateSyntax (SyntaxKind::SequenceExpr);
368
- auto Result = makeParserResult (SequenceExpr::create (Context, SequencedExprs));
369
- if (HasCodeCompletion)
370
- Result.setHasCodeCompletion ();
371
- return Result;
361
+ return makeParserResult (SequenceStatus,
362
+ SequenceExpr::create (Context, SequencedExprs));
372
363
}
373
364
374
365
// / parseExprSequenceElement
@@ -568,9 +559,12 @@ ParserResult<Expr> Parser::parseExprKeyPath() {
568
559
569
560
// FIXME: diagnostics
570
561
ParserResult<Expr> rootResult, pathResult;
562
+ ParserStatus parseStatus;
563
+
571
564
if (!startsWithSymbol (Tok, ' .' )) {
572
565
rootResult = parseExprPostfix (diag::expr_keypath_expected_expr,
573
566
/* isBasic=*/ true );
567
+ parseStatus = rootResult;
574
568
575
569
if (rootResult.isParseError ())
576
570
return rootResult;
@@ -600,10 +594,11 @@ ParserResult<Expr> Parser::parseExprKeyPath() {
600
594
pathResult = parseExprPostfixSuffix (inner, /* isExprBasic=*/ true ,
601
595
/* periodHasKeyPathBehavior=*/ false ,
602
596
unusedHasBindOptional);
597
+ parseStatus |= pathResult;
603
598
}
604
599
605
- if (! rootResult.getPtrOrNull () && ! pathResult.getPtrOrNull ())
606
- return pathResult ;
600
+ if (rootResult.isNull () && pathResult.isNull ())
601
+ return nullptr ;
607
602
608
603
auto keypath = new (Context) KeyPathExpr (
609
604
backslashLoc, rootResult.getPtrOrNull (), pathResult.getPtrOrNull ());
@@ -619,7 +614,6 @@ ParserResult<Expr> Parser::parseExprKeyPath() {
619
614
return makeParserCodeCompletionResult (keypath);
620
615
}
621
616
622
- ParserStatus parseStatus = ParserStatus (rootResult) | ParserStatus (pathResult);
623
617
return makeParserResult (parseStatus, keypath);
624
618
}
625
619
0 commit comments