================
@@ -0,0 +1,247 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Defines the Markdown AST node hierarchy for the clang-doc Markdown parser.
+///
+/// Block nodes represent structural constructs (paragraphs, headings, lists,
+/// fenced code blocks, etc). Inline nodes represent span-level content (text,
+/// emphasis, inline code) that appears inside block nodes.
+///
+/// All nodes are arena-allocated via ASTContext, which owns their lifetime.
+/// The parser builds the tree by calling push_back() on simple_ilist members.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_DOC_SUPPORT_MARKDOWN_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_DOC_SUPPORT_MARKDOWN_H
+
+#include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/simple_ilist.h"
+#include "llvm/Support/Casting.h"
+#include "llvm/Support/Compiler.h"
+#include "llvm/Support/raw_ostream.h"
+
+namespace clang::doc::markdown {
+
+enum class NodeKind {
+  // Inline nodes
+  NK_Text,
+  NK_InlineCode,
+  NK_Emphasis,
+  NK_Strong,
+  // Block nodes
+  NK_Paragraph,
+  NK_Heading,
+  NK_FencedCode,
+  NK_Table, // TODO: add TableNode
+  NK_UnorderedList,
+  NK_OrderedList,
+  NK_BlockQuote,
+  NK_ThematicBreak,
+  NK_Document,
+};
+
+struct InlineNode;
+struct BlockNode;
+
+//===----------------------------------------------------------------------===//
+// Inline nodes -- span-level content inside block nodes
+//===----------------------------------------------------------------------===//
+
+/// Base class for all inline nodes. Inline nodes represent span-level content
+/// such as text, emphasis, and inline code. They live in InlineList members
+/// of block nodes.
+struct InlineNode : llvm::ilist_node<InlineNode> {
+  NodeKind Kind;
+  explicit InlineNode(NodeKind K) : Kind(K) {}
+  virtual ~InlineNode() = default;
+  virtual void print(llvm::raw_ostream &OS) const = 0;
+  LLVM_DUMP_METHOD void dump() const;
+};
+
+using InlineList = llvm::simple_ilist<InlineNode>;
+
+/// A plain text run.
+struct TextNode : InlineNode {
+private:
+  llvm::StringRef Text;
+
+public:
+  explicit TextNode(llvm::StringRef T)
+      : InlineNode(NodeKind::NK_Text), Text(T) {}
+  llvm::StringRef getText() const { return Text; }
+  void print(llvm::raw_ostream &OS) const override;
+  static bool classof(const InlineNode *N) {
+    return N->Kind == NodeKind::NK_Text;
+  }
+};
+
+/// A backtick-delimited inline code span.
+struct InlineCodeNode : InlineNode {
+private:
+  llvm::StringRef Code;
+
+public:
+  explicit InlineCodeNode(llvm::StringRef C)
+      : InlineNode(NodeKind::NK_InlineCode), Code(C) {}
+  llvm::StringRef getCode() const { return Code; }
+  void print(llvm::raw_ostream &OS) const override;
+  static bool classof(const InlineNode *N) {
+    return N->Kind == NodeKind::NK_InlineCode;
+  }
+};
+
+/// An emphasis span (* or _).
+struct EmphasisNode : InlineNode {
+  InlineList Children;
+  EmphasisNode() : InlineNode(NodeKind::NK_Emphasis) {}
+  void print(llvm::raw_ostream &OS) const override;
+  static bool classof(const InlineNode *N) {
+    return N->Kind == NodeKind::NK_Emphasis;
+  }
+};
+
+/// A strong emphasis span (** or __).
+struct StrongNode : InlineNode {
----------------
Neil-N4 wrote:

Done. converted to classes with add/remove/iterate methods instead of exposing 
the ilists directly

https://github.com/llvm/llvm-project/pull/205609
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to