Skip to content

Commit 75464f6

Browse files
committed
[Parser] Parse contextual 'each' in expressions as PackElementExpr.
1 parent e7bcf37 commit 75464f6

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

lib/Parse/ParseExpr.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1612,6 +1612,19 @@ ParserResult<Expr> Parser::parseExprPrimary(Diag<> ID, bool isExprBasic) {
16121612
return makeParserResult(typeExpr);
16131613
}
16141614

1615+
// 'each' followed by another identifier is a pack element expr.
1616+
if (Tok.isContextualKeyword("each") &&
1617+
peekToken().is(tok::identifier) &&
1618+
!peekToken().isAtStartOfLine()) {
1619+
SourceLoc loc = consumeToken();
1620+
ParserResult<Expr> ref = parseExpr(ID);
1621+
if (ref.isNull())
1622+
return ref;
1623+
1624+
auto *packRef = PackElementExpr::create(Context, loc, ref.get());
1625+
return makeParserResult(packRef);
1626+
}
1627+
16151628
LLVM_FALLTHROUGH;
16161629
case tok::kw_Self: // Self
16171630
return parseExprIdentifier();

0 commit comments

Comments
 (0)