Skip to content

Commit faecb8d

Browse files
committed
Lookahead in parseList, not isStartOf{Decl,Stmt}.
Fixed whitespace.
1 parent acdd16f commit faecb8d

File tree

4 files changed

+12
-5
lines changed

4 files changed

+12
-5
lines changed

lib/Parse/ParseDecl.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -2589,8 +2589,6 @@ bool Parser::isStartOfDecl() {
25892589
// If this is obviously not the start of a decl, then we're done.
25902590
if (!isKeywordPossibleDeclStart(Tok)) return false;
25912591

2592-
if (peekToken().is(tok::colon)) return false;
2593-
25942592
// When 'init' appears inside another 'init', it's likely the user wants to
25952593
// invoke an initializer but forgets to prefix it with 'self.' or 'super.'
25962594
// Otherwise, expect 'init' to be the start of a declaration (and complain

lib/Parse/ParseExpr.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -3466,7 +3466,7 @@ ParserResult<Expr> Parser::parseExprCollection() {
34663466
break;
34673467

34683468
if (Tok.isAtStartOfLine())
3469-
continue;
3469+
continue;
34703470

34713471
diagnose(Tok, diag::expected_separator, ",")
34723472
.fixItInsertAfter(PreviousLoc, ",");

lib/Parse/ParseStmt.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ bool Parser::isStartOfStmt() {
6262
case tok::pound_warning:
6363
case tok::pound_error:
6464
case tok::pound_sourceLocation:
65-
if (peekToken().is(tok::colon)) return false;
6665
return true;
6766

6867
case tok::pound_line:

lib/Parse/Parser.cpp

+11-1
Original file line numberDiff line numberDiff line change
@@ -1015,9 +1015,19 @@ Parser::parseList(tok RightK, SourceLoc LeftLoc, SourceLoc &RightLoc,
10151015
}
10161016
break;
10171017
}
1018+
1019+
// If the next token is at the beginning of a new line, could be an argument
1020+
// label, is followed by a colon, and separator omission is permitted,
1021+
// expect that we'll parse another list element which begins with that
1022+
// argument label and continue parsing the list.
1023+
if (Tok.isAtStartOfLine() && AllowSepOmission && Tok.canBeArgumentLabel()
1024+
&& peekToken().is(tok::colon)) {
1025+
continue;
1026+
}
1027+
10181028
// If we're in a comma-separated list, the next token is at the
10191029
// beginning of a new line and can never start an element, break.
1020-
if (Tok.isAtStartOfLine() &&
1030+
if (Tok.isAtStartOfLine() &&
10211031
(Tok.is(tok::r_brace) || isStartOfDecl() || isStartOfStmt())) {
10221032
break;
10231033
}

0 commit comments

Comments
 (0)