diff --git a/clang-tools-extra/pseudo/lib/cxx/CXX.cpp b/clang-tools-extra/pseudo/lib/cxx/CXX.cpp --- a/clang-tools-extra/pseudo/lib/cxx/CXX.cpp +++ b/clang-tools-extra/pseudo/lib/cxx/CXX.cpp @@ -427,6 +427,7 @@ return { {Extension::Brackets, recoverBrackets}, {Extension::NextDeclaration, recoverNextDeclaration}, + {Extension::NextStatement, recoverNextDeclaration}, }; } diff --git a/clang-tools-extra/pseudo/lib/cxx/Recovery.cpp b/clang-tools-extra/pseudo/lib/cxx/Recovery.cpp --- a/clang-tools-extra/pseudo/lib/cxx/Recovery.cpp +++ b/clang-tools-extra/pseudo/lib/cxx/Recovery.cpp @@ -31,6 +31,11 @@ auto ConsiderForBraces = [&](tok::TokenKind K) { if (K == tok::kw_export || K == tok::kw_extern || K == tok::kw_namespace) AcceptBraces = true; + // Statements that don't end in semicolons: + // while/switch/if/for (...) {} + if (K == tok::kw_for || K == tok::kw_while || K == tok::kw_if || + K == tok::kw_switch) + AcceptBraces = true; }; // Some tokens are pretty good indicators of a declaration starting, when @@ -71,6 +76,15 @@ case tok::kw_public: case tok::kw_private: case tok::kw_protected: + // Typical keywords for statements + case tok::kw_for: + case tok::kw_while: + case tok::kw_if: + case tok::kw_goto: + case tok::kw_switch: + case tok::kw_return: + case tok::kw_break: + case tok::kw_continue: return true; default: return false; diff --git a/clang-tools-extra/pseudo/lib/cxx/cxx.bnf b/clang-tools-extra/pseudo/lib/cxx/cxx.bnf --- a/clang-tools-extra/pseudo/lib/cxx/cxx.bnf +++ b/clang-tools-extra/pseudo/lib/cxx/cxx.bnf @@ -283,8 +283,8 @@ labeled-statement := DEFAULT : statement expression-statement := expression_opt ; compound-statement := { statement-seq_opt [recover=Brackets] } -statement-seq := statement -statement-seq := statement-seq statement +statement-seq := statement [recover=NextStatement] +statement-seq := statement-seq statement [recover=NextStatement] selection-statement := IF CONSTEXPR_opt ( init-statement_opt condition ) statement [guard] selection-statement := IF CONSTEXPR_opt ( init-statement_opt condition ) statement ELSE statement selection-statement := SWITCH ( init-statement_opt condition ) statement