================ @@ -276,13 +276,44 @@ void FormatTokenLexer::tryMergePreviousTokens() { return; } } - // TableGen's Multi line string starts with [{ - if (Style.isTableGen() && tryMergeTokens({tok::l_square, tok::l_brace}, - TT_TableGenMultiLineString)) { - // Set again with finalizing. This must never be annotated as other types. - Tokens.back()->setFinalizedType(TT_TableGenMultiLineString); - Tokens.back()->Tok.setKind(tok::string_literal); - return; + if (Style.isTableGen()) { + // TableGen's Multi line string starts with [{ + if (tryMergeTokens({tok::l_square, tok::l_brace}, + TT_TableGenMultiLineString)) { + // Set again with finalizing. This must never be annotated as other types. + Tokens.back()->setFinalizedType(TT_TableGenMultiLineString); + Tokens.back()->Tok.setKind(tok::string_literal); + return; + } + // TableGen's bang operator is the form !<name>. + // !cond is a special case with specific syntax. + if (tryMergeTokens({tok::exclaim, tok::identifier}, + TT_TableGenBangOperator)) { + Tokens.back()->Tok.setKind(tok::identifier); + Tokens.back()->Tok.setIdentifierInfo(nullptr); + if (Tokens.back()->TokenText == "!cond") + Tokens.back()->setFinalizedType(TT_TableGenCondOperator); + else + Tokens.back()->setFinalizedType(TT_TableGenBangOperator); + return; + } + if (tryMergeTokens({tok::exclaim, tok::kw_if}, TT_TableGenBangOperator)) { + // Here, "! if" becomes "!if". That is, ! captures if even when the space + // exists. That is only one possibility in TableGen's syntax. + Tokens.back()->Tok.setKind(tok::identifier); + Tokens.back()->Tok.setIdentifierInfo(nullptr); + Tokens.back()->setFinalizedType(TT_TableGenBangOperator); + return; + } + // +, - with numbers are literals. Not unary operators. + if (tryMergeTokens({tok::plus, tok::numeric_constant}, TT_Unknown)) { + Tokens.back()->Tok.setKind(tok::numeric_constant); + return; ---------------- hnakamura5 wrote:
@mydeveloperday Thank you for reviewing this pull request. Now it comes to 1 week since this PR is started. I want to continue before I forget. Could you mind accepting or adding some suggestion? Or if you do not intend neither, can I request another reviewer? https://github.com/llvm/llvm-project/pull/78996 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits