[clang] [Clang][Comments] Support for parsing headers in Doxygen \par commands (PR #91100)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Mon May 6 07:31:34 PDT 2024


================
@@ -149,6 +149,63 @@ class TextTokenRetokenizer {
     addToken();
   }
 
+  /// Check if this line starts with @par or \par
+  bool startsWithParCommand() {
+    unsigned Offset = 1;
+
+    /// Skip all whitespace characters at the beginning.
+    /// This needs to backtrack because Pos has already advanced past the
+    /// actual \par or @par command by the time this function is called.
+    while (isWhitespace(*(Pos.BufferPtr - Offset)))
+      Offset++;
+
+    /// Check if next four characters are \par or @par
+    llvm::StringRef LineStart(Pos.BufferPtr - 5, 4);
+    return LineStart.starts_with("\\par") || LineStart.starts_with("@par");
+  }
+
+  /// Extract a par command argument-header.
+  bool lexParHeading(Token &Tok) {
+    if (isEnd())
+      return false;
+
+    Position SavedPos = Pos;
+
+    consumeWhitespace();
+    SmallString<32> WordText;
+    const char *WordBegin = Pos.BufferPtr;
+    SourceLocation Loc = getSourceLocation();
+
+    if (!startsWithParCommand())
+      return false;
+
+    // Read until the end of this token, which is effectively the end of the
+    // line This gets us the content of the par header, if there is one.
+    while (!isEnd()) {
+      WordText.push_back(peek());
+      if (Pos.BufferPtr + 1 == Pos.BufferEnd) {
+        consumeChar();
+        break;
+      } else {
+        consumeChar();
+      }
----------------
AaronBallman wrote:

```suggestion
      }
      consumeChar();
```
No need for an `else` because we'd have broken out of the loop if we entered the `if`.

https://github.com/llvm/llvm-project/pull/91100


More information about the cfe-commits mailing list