Reclaim "in" as an identifier

In Swift the "in" keyword is really a form of punctuation, and highly
context specific punctuation at that. It never begins a statement, nor
does the grammar require it be statement keyword. The grammar also
doesn't use it outside of for-each loops, and its use within a for-each
loop is highly unambiguous.

Thanks to Chris for the performance related feedback. This improves the
performance of getter/setter parsing as well.

Swift SVN r3880
This commit is contained in:
Dave Zarzycki
2013-01-26 01:49:18 +00:00
parent 6cfcb412b3
commit d7cc4b4a91
7 changed files with 13 additions and 31 deletions

View File

@@ -146,8 +146,7 @@ void Parser::parseBraceItemList(SmallVectorImpl<ExprStmtOrDecl> &Entries,
while (Tok.isNot(tok::r_brace) && Tok.isNot(tok::eof)) {
if (IsGetSet) {
Identifier Id = Context.getIdentifier(Tok.getText());
if (Id == GetIdent || Id == SetIdent)
if (Tok.isContextualKeyword("get") || Tok.isContextualKeyword("set"))
break;
}
@@ -382,9 +381,9 @@ NullablePtr<Stmt> Parser::parseStmtFor() {
}
// If we have a leading identifier followed by a ':' or 'in', then this is a
// pattern, so it is foreach.
if (Tok.is(tok::identifier) &&
(peekToken().is(tok::colon) || peekToken().is(tok::kw_in)))
// pattern, so it is foreach.
if (Tok.is(tok::identifier) &&
(peekToken().is(tok::colon) || peekToken().isContextualKeyword("in")))
return parseStmtForEach(ForLoc);
// Otherwise, this is some sort of c-style for loop.
@@ -486,8 +485,7 @@ NullablePtr<Stmt> Parser::parseStmtForEach(SourceLoc ForLoc) {
return parseStmtForCStyle(ForLoc, LPLoc, CForLoopHack);
}
// 'in'
if (!Tok.is(tok::kw_in)) {
if (!Tok.isContextualKeyword("in")) {
if (Pattern.isNonNull())
diagnose(Tok.getLoc(), diag::expected_foreach_in);
return nullptr;