@@ -465,6 +465,44 @@ ParserResult<Expr> Parser::parseExprSequenceElement(Diag<> message,
465
465
}
466
466
}
467
467
468
+ // 'any' followed by another identifier is an existential type.
469
+ if (Tok.isContextualKeyword (" any" ) &&
470
+ peekToken ().is (tok::identifier) &&
471
+ !peekToken ().isAtStartOfLine ()) {
472
+ ParserResult<TypeRepr> ty = parseType ();
473
+ auto *typeExpr = new (Context) TypeExpr (ty.get ());
474
+ return makeParserResult (typeExpr);
475
+ }
476
+
477
+ // 'repeat' as an expression prefix is a pack expansion expression.
478
+ if (Tok.is (tok::kw_repeat)) {
479
+ SourceLoc repeatLoc = consumeToken ();
480
+ auto patternExpr = parseExprImpl (
481
+ diag::expected_expr_after_repeat, isExprBasic);
482
+ if (patternExpr.isNull ())
483
+ return patternExpr;
484
+
485
+ auto *expansion =
486
+ PackExpansionExpr::create (Context, repeatLoc, patternExpr.get (),
487
+ /* genericEnv*/ nullptr );
488
+ return makeParserResult (expansion);
489
+ }
490
+
491
+ // 'each' followed by another identifier is a pack element expr.
492
+ if (Tok.isContextualKeyword (" each" ) &&
493
+ peekToken ().isAny (tok::identifier, tok::kw_self, tok::dollarident,
494
+ tok::code_complete) &&
495
+ !peekToken ().isAtStartOfLine ()) {
496
+ SourceLoc loc = consumeToken ();
497
+ ParserResult<Expr> ref =
498
+ parseExprSequenceElement (diag::expected_expr_after_each, isExprBasic);
499
+ if (ref.isNull ())
500
+ return ref;
501
+
502
+ auto *packRef = PackElementExpr::create (Context, loc, ref.get ());
503
+ return makeParserResult (packRef);
504
+ }
505
+
468
506
SourceLoc tryLoc;
469
507
bool hadTry = consumeIf (tok::kw_try, tryLoc);
470
508
llvm::Optional<Token> trySuffix;
@@ -546,19 +584,6 @@ ParserResult<Expr> Parser::parseExprUnary(Diag<> Message, bool isExprBasic) {
546
584
// First check to see if we have the start of a regex literal `/.../`.
547
585
tryLexRegexLiteral (/* forUnappliedOperator*/ false );
548
586
549
- // 'repeat' as an expression prefix is a pack expansion expression.
550
- if (Tok.is (tok::kw_repeat)) {
551
- SourceLoc repeatLoc = consumeToken ();
552
- auto patternExpr = parseExpr (Message);
553
- if (patternExpr.isNull ())
554
- return patternExpr;
555
-
556
- auto *expansion =
557
- PackExpansionExpr::create (Context, repeatLoc, patternExpr.get (),
558
- /* genericEnv*/ nullptr );
559
- return makeParserResult (expansion);
560
- }
561
-
562
587
// Try parse an 'if' or 'switch' as an expression. Note we do this here in
563
588
// parseExprUnary as we don't allow postfix syntax to hang off such
564
589
// expressions to avoid ambiguities such as postfix '.member', which can
@@ -1715,28 +1740,6 @@ ParserResult<Expr> Parser::parseExprPrimary(Diag<> ID, bool isExprBasic) {
1715
1740
return makeParserResult (new (Context) UnresolvedPatternExpr (pattern));
1716
1741
}
1717
1742
1718
- // 'any' followed by another identifier is an existential type.
1719
- if (Tok.isContextualKeyword (" any" ) &&
1720
- peekToken ().is (tok::identifier) &&
1721
- !peekToken ().isAtStartOfLine ()) {
1722
- ParserResult<TypeRepr> ty = parseType ();
1723
- auto *typeExpr = new (Context) TypeExpr (ty.get ());
1724
- return makeParserResult (typeExpr);
1725
- }
1726
-
1727
- // 'each' followed by another identifier is a pack element expr.
1728
- if (Tok.isContextualKeyword (" each" ) &&
1729
- peekToken ().is (tok::identifier) &&
1730
- !peekToken ().isAtStartOfLine ()) {
1731
- SourceLoc loc = consumeToken ();
1732
- ParserResult<Expr> ref = parseExpr (ID);
1733
- if (ref.isNull ())
1734
- return ref;
1735
-
1736
- auto *packRef = PackElementExpr::create (Context, loc, ref.get ());
1737
- return makeParserResult (packRef);
1738
- }
1739
-
1740
1743
LLVM_FALLTHROUGH;
1741
1744
}
1742
1745
case tok::kw_Self: // Self
0 commit comments