|
8 | 8 | See https://swift.org/CONTRIBUTORS.txt for Swift project authors |
9 | 9 | */ |
10 | 10 |
|
| 11 | + |
| 12 | +#if swift(>=5.7) |
| 13 | +/// Visits `Markup` elements and returns a result. |
| 14 | +/// |
| 15 | +/// - note: This interface only provides requirements for visiting each kind of element. It does not require each visit method to descend into child elements. |
| 16 | +/// |
| 17 | +/// Generally, ``MarkupWalker`` is best for walking a ``Markup`` tree if the ``Result`` type is `Void` or is built up some other way, or ``MarkupRewriter`` for recursively changing a tree's structure. This type serves as a common interface to both. However, for building up other structured result types you can implement ``MarkupVisitor`` directly. |
| 18 | +public protocol MarkupVisitor<Result> { |
| 19 | + |
| 20 | + /** |
| 21 | + The result type returned when visiting a element. |
| 22 | + */ |
| 23 | + associatedtype Result |
| 24 | + |
| 25 | + /** |
| 26 | + A default implementation to use when a visitor method isn't implemented for a particular element. |
| 27 | + - parameter markup: the element to visit. |
| 28 | + - returns: The result of the visit. |
| 29 | + */ |
| 30 | + mutating func defaultVisit(_ markup: Markup) -> Result |
| 31 | + |
| 32 | + /** |
| 33 | + Visit any kind of `Markup` element and return the result. |
| 34 | + |
| 35 | + - parameter markup: Any kind of `Markup` element. |
| 36 | + - returns: The result of the visit. |
| 37 | + */ |
| 38 | + mutating func visit(_ markup: Markup) -> Result |
| 39 | + |
| 40 | + /** |
| 41 | + Visit a `BlockQuote` element and return the result. |
| 42 | + |
| 43 | + - parameter blockQuote: A `BlockQuote` element. |
| 44 | + - returns: The result of the visit. |
| 45 | + */ |
| 46 | + mutating func visitBlockQuote(_ blockQuote: BlockQuote) -> Result |
| 47 | + |
| 48 | + /** |
| 49 | + Visit a `CodeBlock` element and return the result. |
| 50 | + |
| 51 | + - parameter codeBlock: An `CodeBlock` element. |
| 52 | + - returns: The result of the visit. |
| 53 | + */ |
| 54 | + mutating func visitCodeBlock(_ codeBlock: CodeBlock) -> Result |
| 55 | + |
| 56 | + /** |
| 57 | + Visit a `CustomBlock` element and return the result. |
| 58 | + |
| 59 | + - parameter customBlock: An `CustomBlock` element. |
| 60 | + - returns: The result of the visit. |
| 61 | + */ |
| 62 | + mutating func visitCustomBlock(_ customBlock: CustomBlock) -> Result |
| 63 | + |
| 64 | + /** |
| 65 | + Visit a `Document` element and return the result. |
| 66 | + |
| 67 | + - parameter document: An `Document` element. |
| 68 | + - returns: The result of the visit. |
| 69 | + */ |
| 70 | + mutating func visitDocument(_ document: Document) -> Result |
| 71 | + |
| 72 | + /** |
| 73 | + Visit a `Heading` element and return the result. |
| 74 | + |
| 75 | + - parameter heading: An `Heading` element. |
| 76 | + - returns: The result of the visit. |
| 77 | + */ |
| 78 | + mutating func visitHeading(_ heading: Heading) -> Result |
| 79 | + |
| 80 | + /** |
| 81 | + Visit a `ThematicBreak` element and return the result. |
| 82 | + |
| 83 | + - parameter thematicBreak: An `ThematicBreak` element. |
| 84 | + - returns: The result of the visit. |
| 85 | + */ |
| 86 | + mutating func visitThematicBreak(_ thematicBreak: ThematicBreak) -> Result |
| 87 | + |
| 88 | + /** |
| 89 | + Visit an `HTML` element and return the result. |
| 90 | + |
| 91 | + - parameter html: An `HTML` element. |
| 92 | + - returns: The result of the visit. |
| 93 | + */ |
| 94 | + mutating func visitHTMLBlock(_ html: HTMLBlock) -> Result |
| 95 | + |
| 96 | + /** |
| 97 | + Visit a `ListItem` element and return the result. |
| 98 | + |
| 99 | + - parameter listItem: An `ListItem` element. |
| 100 | + - returns: The result of the visit. |
| 101 | + */ |
| 102 | + mutating func visitListItem(_ listItem: ListItem) -> Result |
| 103 | + |
| 104 | + /** |
| 105 | + Visit a `OrderedList` element and return the result. |
| 106 | + |
| 107 | + - parameter orderedList: An `OrderedList` element. |
| 108 | + - returns: The result of the visit. |
| 109 | + */ |
| 110 | + mutating func visitOrderedList(_ orderedList: OrderedList) -> Result |
| 111 | + |
| 112 | + /** |
| 113 | + Visit a `UnorderedList` element and return the result. |
| 114 | + |
| 115 | + - parameter unorderedList: An `UnorderedList` element. |
| 116 | + - returns: The result of the visit. |
| 117 | + */ |
| 118 | + mutating func visitUnorderedList(_ unorderedList: UnorderedList) -> Result |
| 119 | + |
| 120 | + /** |
| 121 | + Visit a `Paragraph` element and return the result. |
| 122 | + |
| 123 | + - parameter paragraph: An `Paragraph` element. |
| 124 | + - returns: The result of the visit. |
| 125 | + */ |
| 126 | + mutating func visitParagraph(_ paragraph: Paragraph) -> Result |
| 127 | + |
| 128 | + /** |
| 129 | + Visit a `BlockDirective` element and return the result. |
| 130 | + |
| 131 | + - parameter blockDirective: A `BlockDirective` element. |
| 132 | + - returns: The result of the visit. |
| 133 | + */ |
| 134 | + mutating func visitBlockDirective(_ blockDirective: BlockDirective) -> Result |
| 135 | + |
| 136 | + /** |
| 137 | + Visit a `InlineCode` element and return the result. |
| 138 | + |
| 139 | + - parameter inlineCode: An `InlineCode` element. |
| 140 | + - returns: The result of the visit. |
| 141 | + */ |
| 142 | + mutating func visitInlineCode(_ inlineCode: InlineCode) -> Result |
| 143 | + |
| 144 | + /** |
| 145 | + Visit a `CustomInline` element and return the result. |
| 146 | + |
| 147 | + - parameter customInline: An `CustomInline` element. |
| 148 | + - returns: The result of the visit. |
| 149 | + */ |
| 150 | + mutating func visitCustomInline(_ customInline: CustomInline) -> Result |
| 151 | + |
| 152 | + /** |
| 153 | + Visit a `Emphasis` element and return the result. |
| 154 | + |
| 155 | + - parameter emphasis: An `Emphasis` element. |
| 156 | + - returns: The result of the visit. |
| 157 | + */ |
| 158 | + mutating func visitEmphasis(_ emphasis: Emphasis) -> Result |
| 159 | + |
| 160 | + /** |
| 161 | + Visit a `Image` element and return the result. |
| 162 | + |
| 163 | + - parameter image: An `Image` element. |
| 164 | + - returns: The result of the visit. |
| 165 | + */ |
| 166 | + mutating func visitImage(_ image: Image) -> Result |
| 167 | + |
| 168 | + /** |
| 169 | + Visit a `InlineHTML` element and return the result. |
| 170 | + |
| 171 | + - parameter inlineHTML: An `InlineHTML` element. |
| 172 | + - returns: The result of the visit. |
| 173 | + */ |
| 174 | + mutating func visitInlineHTML(_ inlineHTML: InlineHTML) -> Result |
| 175 | + |
| 176 | + /** |
| 177 | + Visit a `LineBreak` element and return the result. |
| 178 | + |
| 179 | + - parameter lineBreak: An `LineBreak` element. |
| 180 | + - returns: The result of the visit. |
| 181 | + */ |
| 182 | + mutating func visitLineBreak(_ lineBreak: LineBreak) -> Result |
| 183 | + |
| 184 | + /** |
| 185 | + Visit a `Link` element and return the result. |
| 186 | + |
| 187 | + - parameter link: An `Link` element. |
| 188 | + - returns: The result of the visit. |
| 189 | + */ |
| 190 | + mutating func visitLink(_ link: Link) -> Result |
| 191 | + |
| 192 | + /** |
| 193 | + Visit a `SoftBreak` element and return the result. |
| 194 | + |
| 195 | + - parameter softBreak: An `SoftBreak` element. |
| 196 | + - returns: The result of the visit. |
| 197 | + */ |
| 198 | + mutating func visitSoftBreak(_ softBreak: SoftBreak) -> Result |
| 199 | + |
| 200 | + /** |
| 201 | + Visit a `Strong` element and return the result. |
| 202 | + |
| 203 | + - parameter strong: An `Strong` element. |
| 204 | + - returns: The result of the visit. |
| 205 | + */ |
| 206 | + mutating func visitStrong(_ strong: Strong) -> Result |
| 207 | + |
| 208 | + /** |
| 209 | + Visit a `Text` element and return the result. |
| 210 | + |
| 211 | + - parameter text: A `Text` element. |
| 212 | + - returns: The result of the visit. |
| 213 | + */ |
| 214 | + mutating func visitText(_ text: Text) -> Result |
| 215 | + |
| 216 | + /** |
| 217 | + Visit a `Strikethrough` element and return the result. |
| 218 | + |
| 219 | + - parameter strikethrough: A `Strikethrough` element. |
| 220 | + - returns: The result of the visit. |
| 221 | + */ |
| 222 | + mutating func visitStrikethrough(_ strikethrough: Strikethrough) -> Result |
| 223 | + |
| 224 | + /** |
| 225 | + Visit a `Table` element and return the result. |
| 226 | + |
| 227 | + - parameter table: A `Table` element. |
| 228 | + - returns: The result of the visit. |
| 229 | + */ |
| 230 | + mutating func visitTable(_ table: Table) -> Result |
| 231 | + |
| 232 | + /** |
| 233 | + Visit a `Table.Head` element and return the result. |
| 234 | + |
| 235 | + - parameter tableHead: A `Table.Head` element. |
| 236 | + - returns: The result of the visit. |
| 237 | + */ |
| 238 | + mutating func visitTableHead(_ tableHead: Table.Head) -> Result |
| 239 | + |
| 240 | + /** |
| 241 | + Visit a `Table.Body` element and return the result. |
| 242 | + |
| 243 | + - parameter tableBody: A `Table.Body` element. |
| 244 | + - returns: The result of the visit. |
| 245 | + */ |
| 246 | + mutating func visitTableBody(_ tableBody: Table.Body) -> Result |
| 247 | + |
| 248 | + /** |
| 249 | + Visit a `Table.Row` element and return the result. |
| 250 | + |
| 251 | + - parameter tableRow: A `Table.Row` element. |
| 252 | + - returns: The result of the visit. |
| 253 | + */ |
| 254 | + mutating func visitTableRow(_ tableRow: Table.Row) -> Result |
| 255 | + |
| 256 | + /** |
| 257 | + Visit a `Table.Cell` element and return the result. |
| 258 | + |
| 259 | + - parameter tableCell: A `Table.Cell` element. |
| 260 | + - returns: The result of the visit. |
| 261 | + */ |
| 262 | + mutating func visitTableCell(_ tableCell: Table.Cell) -> Result |
| 263 | + |
| 264 | + /** |
| 265 | + Visit a `SymbolLink` element and return the result. |
| 266 | + |
| 267 | + - parameter symbolLink: A `SymbolLink` element. |
| 268 | + - returns: The result of the visit. |
| 269 | + */ |
| 270 | + mutating func visitSymbolLink(_ symbolLink: SymbolLink) -> Result |
| 271 | + |
| 272 | + /** |
| 273 | + Visit an `InlineAttributes` element and return the result. |
| 274 | + |
| 275 | + - parameter attribute: An `InlineAttributes` element. |
| 276 | + - returns: The result of the visit. |
| 277 | + */ |
| 278 | + mutating func visitInlineAttributes(_ attributes: InlineAttributes) -> Result |
| 279 | + |
| 280 | + /** |
| 281 | + Visit a `DoxygenParam` element and return the result. |
| 282 | + |
| 283 | + - parameter doxygenParam: A `DoxygenParam` element. |
| 284 | + - returns: The result of the visit. |
| 285 | + */ |
| 286 | + mutating func visitDoxygenParameter(_ doxygenParam: DoxygenParameter) -> Result |
| 287 | + |
| 288 | + /** |
| 289 | + Visit a `DoxygenReturns` element and return the result. |
| 290 | + |
| 291 | + - parameter doxygenReturns: A `DoxygenReturns` element. |
| 292 | + - returns: The result of the visit. |
| 293 | + */ |
| 294 | + mutating func visitDoxygenReturns(_ doxygenReturns: DoxygenReturns) -> Result |
| 295 | +} |
| 296 | +#else |
11 | 297 | /// Visits `Markup` elements and returns a result. |
12 | 298 | /// |
13 | 299 | /// - note: This interface only provides requirements for visiting each kind of element. It does not require each visit method to descend into child elements. |
@@ -291,6 +577,7 @@ public protocol MarkupVisitor { |
291 | 577 | */ |
292 | 578 | mutating func visitDoxygenReturns(_ doxygenReturns: DoxygenReturns) -> Result |
293 | 579 | } |
| 580 | +#endif |
294 | 581 |
|
295 | 582 | extension MarkupVisitor { |
296 | 583 | // Default implementation: call `accept` on the markup element, |
|
0 commit comments