Parsing postfix exprs: if we have '.<keyword><code_complete>', try to recover

by creating an identifier with the same spelling as the keyword.

Fixes code completion for cases like 'foo.is#^A^#'.


Swift SVN r6727
This commit is contained in:
Dmitri Hrybenko
2013-07-29 23:56:21 +00:00
parent 81a5a41944
commit 8f83ca67e3

View File

@@ -838,6 +838,27 @@ NullablePtr<Expr> Parser::parseExprPostfix(Diag<> ID) {
} }
if (consumeIf(tok::period) || (IsPeriod && consumeIf(tok::period_prefix))) { if (consumeIf(tok::period) || (IsPeriod && consumeIf(tok::period_prefix))) {
if (Tok.isNot(tok::identifier) && Tok.isNot(tok::integer_literal)) { if (Tok.isNot(tok::identifier) && Tok.isNot(tok::integer_literal)) {
if (peekToken().is(tok::code_complete)) {
switch (Tok.getKind()) {
default:
break;
#define KEYWORD(kw) \
case tok::kw_##kw:
#include "swift/Parse/Tokens.def"
{
// If we have a '.<keyword><code_complete>', then try to recover
// by creating an identifier with the same spelling as the
// keyword.
Identifier Name = Context.getIdentifier(Tok.getText());
Result = new (Context) UnresolvedDotExpr(Result.get(), TokLoc,
Name, Tok.getLoc());
consumeToken();
}
break;
}
}
if (Tok.is(tok::code_complete) && CodeCompletion && Result.isNonNull()) { if (Tok.is(tok::code_complete) && CodeCompletion && Result.isNonNull()) {
CodeCompletion->completeDotExpr(Result.get()); CodeCompletion->completeDotExpr(Result.get());
return nullptr; return nullptr;