aboutsummaryrefslogtreecommitdiff
path: root/lib/Parse/Parser.cpp
diff options
context:
space:
mode:
authorJohn McCall <rjmccall@apple.com>2010-09-07 18:31:03 +0000
committerJohn McCall <rjmccall@apple.com>2010-09-07 18:31:03 +0000
commit837b1a37116cf4e64f8bb7db34982dee1fba7647 (patch)
tree5f7809a4f69bec53e8d2854cf7314d1a9f994f06 /lib/Parse/Parser.cpp
parent0e728644deb2fe4601dff82b73e8fd06d52e171c (diff)
Improve error recovery when we see ':' and expect a ';'.
I, at least, make this typo all the time. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@113243 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Parse/Parser.cpp')
-rw-r--r--lib/Parse/Parser.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/Parse/Parser.cpp b/lib/Parse/Parser.cpp
index ca06ba72f6..02802773a0 100644
--- a/lib/Parse/Parser.cpp
+++ b/lib/Parse/Parser.cpp
@@ -133,6 +133,13 @@ SourceLocation Parser::MatchRHSPunctuation(tok::TokenKind RHSTok,
return R;
}
+static bool IsCommonTypo(tok::TokenKind ExpectedTok, const Token &Tok) {
+ switch (ExpectedTok) {
+ case tok::semi: return Tok.is(tok::colon); // : for ;
+ default: return false;
+ }
+}
+
/// ExpectAndConsume - The parser expects that 'ExpectedTok' is next in the
/// input. If so, it is consumed and false is returned.
///
@@ -146,6 +153,19 @@ bool Parser::ExpectAndConsume(tok::TokenKind ExpectedTok, unsigned DiagID,
return false;
}
+ // Detect common single-character typos and resume.
+ if (IsCommonTypo(ExpectedTok, Tok)) {
+ SourceLocation Loc = Tok.getLocation();
+ Diag(Loc, DiagID)
+ << Msg
+ << FixItHint::CreateReplacement(SourceRange(Loc),
+ getTokenSimpleSpelling(ExpectedTok));
+ ConsumeAnyToken();
+
+ // Pretend there wasn't a problem.
+ return false;
+ }
+
const char *Spelling = 0;
SourceLocation EndLoc = PP.getLocForEndOfToken(PrevTokLocation);
if (EndLoc.isValid() &&