diff options
author | John McCall <rjmccall@apple.com> | 2010-09-07 18:31:03 +0000 |
---|---|---|
committer | John McCall <rjmccall@apple.com> | 2010-09-07 18:31:03 +0000 |
commit | 1ca73da0e65b6ebf061491927baa1d380bfc3b99 (patch) | |
tree | 8a439d3801ba7b06526f8447af56e241000b959d /clang/lib/Parse/Parser.cpp | |
parent | 4f5d4b4a6e21c6cbec4c8a5e9dfe041199979ec4 (diff) | |
download | bcm5719-llvm-1ca73da0e65b6ebf061491927baa1d380bfc3b99.tar.gz bcm5719-llvm-1ca73da0e65b6ebf061491927baa1d380bfc3b99.zip |
Improve error recovery when we see ':' and expect a ';'.
I, at least, make this typo all the time.
llvm-svn: 113243
Diffstat (limited to 'clang/lib/Parse/Parser.cpp')
-rw-r--r-- | clang/lib/Parse/Parser.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp index ca06ba72f64..02802773a03 100644 --- a/clang/lib/Parse/Parser.cpp +++ b/clang/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() && |