[clang] [clang-format] Add OneLineFormatOffRegex option (PR #137577)
Björn Schäpers via cfe-commits
cfe-commits at lists.llvm.org
Mon Apr 28 12:20:13 PDT 2025
================
@@ -83,8 +83,42 @@ FormatTokenLexer::FormatTokenLexer(
ArrayRef<FormatToken *> FormatTokenLexer::lex() {
assert(Tokens.empty());
assert(FirstInLineIndex == 0);
+ const llvm::Regex FormatOffRegex(Style.OneLineFormatOffRegex);
+ enum { FO_None, FO_CurrentLine, FO_NextLine } FormatOff = FO_None;
do {
Tokens.push_back(getNextToken());
+ auto &Tok = *Tokens.back();
+ const auto NewlinesBefore = Tok.NewlinesBefore;
+ switch (FormatOff) {
+ case FO_CurrentLine:
+ if (NewlinesBefore == 0)
+ Tok.Finalized = true;
+ else
+ FormatOff = FO_None;
+ break;
+ case FO_NextLine:
+ if (NewlinesBefore == 1) {
+ FormatOff = FO_CurrentLine;
+ Tok.Finalized = true;
+ } else {
+ FormatOff = FO_None;
+ }
+ break;
+ default:
+ if (!FormattingDisabled && FormatOffRegex.match(Tok.TokenText)) {
+ if (Tok.TokenText.starts_with("//") &&
----------------
HazardyKnusperkeks wrote:
What about `/*`? I'm thinking of using it inside a macro definition.
https://github.com/llvm/llvm-project/pull/137577
More information about the cfe-commits
mailing list