1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
|
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2022 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
import Foundation
import SyntaxSupport
let nodesSections: String = {
var result = ""
var handledSyntaxTypes: Set<String> = []
func addSection(heading: String, types: [String]) {
handledSyntaxTypes.formUnion(types)
result += "### \(heading)\n\n"
for type in types {
result += "- <doc:SwiftSyntax/\(type)>\n"
}
result += "\n"
}
var nodeKinds: [(SyntaxNodeKind, String)] = [
(.decl, "Declarations"),
(.expr, "Expressions"),
(.pattern, "Patterns"),
(.stmt, "Statements"),
(.type, "Types"),
]
for (baseKind, heading) in nodeKinds {
let baseTypes = ["\(baseKind.syntaxType)", "\(baseKind.syntaxType)Protocol", "Missing\(baseKind.syntaxType)"]
let leafTypes =
SYNTAX_NODES
.filter({ $0.base == baseKind && !$0.kind.isMissing && !$0.isExperimental && !$0.kind.isDeprecated })
.map(\.kind.syntaxType.description)
addSection(heading: heading, types: baseTypes + leafTypes)
}
addSection(
heading: "Collections",
types: [
"SyntaxChildren",
"SyntaxChildrenIndex",
]
+ SYNTAX_NODES.flatMap({ (node: Node) -> [String] in
guard let node = node.collectionNode, !node.isExperimental else {
return []
}
return [node.kind.syntaxType.description]
+ node.elementChoices
.filter { SYNTAX_NODE_MAP[$0] != nil && !SYNTAX_NODE_MAP[$0]!.isExperimental && !$0.isDeprecated }
.map(\.syntaxType.description)
.filter { !handledSyntaxTypes.contains($0) }
})
)
addSection(
heading: "Attributes",
types: ATTRIBUTE_NODES.filter({ !$0.isExperimental && !$0.kind.isDeprecated }).map(\.kind.syntaxType.description)
.sorted()
)
addSection(
heading: "Miscellaneous Syntax",
types: SYNTAX_NODES.filter({ !$0.isExperimental && !$0.kind.isDeprecated }).map(\.kind.syntaxType.description)
.filter({
!handledSyntaxTypes.contains($0)
})
)
addSection(heading: "Traits", types: TRAITS.map { "\($0.protocolName)" })
return result
}()
var contributingDocs: String = {
let contributingDocsFolder = URL(fileURLWithPath: #filePath)
.deletingLastPathComponent()
.deletingLastPathComponent()
.deletingLastPathComponent()
.deletingLastPathComponent()
.deletingLastPathComponent()
.deletingLastPathComponent()
.appendingPathComponent("Sources")
.appendingPathComponent("SwiftSyntax")
.appendingPathComponent("Documentation.docc")
.appendingPathComponent("Contributing")
let files =
(try? FileManager.default.contentsOfDirectory(at: contributingDocsFolder, includingPropertiesForKeys: nil)) ?? []
return files.compactMap { file in
if file.pathExtension != "md" {
return nil
}
let doccName = file.lastPathComponent
.replacingOccurrences(of: ".md", with: "")
.replacingOccurrences(of: " ", with: "-")
return "- <doc:\(doccName)>"
}.sorted().joined(separator: "\n")
}()
let swiftSyntaxDoccIndex: String = {
let templateURL = URL(fileURLWithPath: #filePath)
.deletingLastPathComponent()
.appendingPathComponent("SwiftSyntaxDoccIndexTemplate.md")
let template = try! String(contentsOf: templateURL)
return
template
.replacingOccurrences(of: "{{Nodes}}", with: nodesSections)
.replacingOccurrences(of: "{{ContributingDocs}}", with: contributingDocs)
}()
|