Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specify swift-syntax version in manifest #41

Merged
merged 2 commits into from
Dec 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
"package": "SwiftSyntax",
"repositoryURL": "https://github.com/apple/swift-syntax",
"state": {
"branch": "main",
"revision": "dfb8deb846e16d98e1d5b2261ed608121e096037",
"version": null
"branch": null,
"revision": "6ad4ea24b01559dde0773e3d091f1b9e36175036",
"version": "509.0.2"
}
}
]
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ let docc: PackageDescription.Package.Dependency = .package(
)
let swiftSyntax = PackageDescription.Package.Dependency.package(
url: "https://github.com/apple/swift-syntax",
branch: "main"
from: "509.0.2"
)

let package = Package(
Expand Down
18 changes: 8 additions & 10 deletions Sources/CsvBuilder/CsvCompositionParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public struct CsvCompositionParser {
if !validateInheritedType(decl: decl) {
break
}
let members = decl.members.members
let members = decl.memberBlock.members
let columns = decl.findColumns(type: C.self, members: members)
.map { Csv.Column.init(name: $0, style: .random()) }
allColumns.append(contentsOf: columns)
Expand All @@ -60,31 +60,29 @@ public struct CsvCompositionParser {

static func validateInheritedType(decl: StructDeclSyntax) -> Bool {
decl.inheritanceClause?
.inheritedTypeCollection
.map(\.typeName)
.inheritedTypes
.map(\.type)
.compactMap { syntax in
syntax.as(SimpleTypeIdentifierSyntax.self)
syntax.as(IdentifierTypeSyntax.self)
}
.first(where: { syntax in
syntax.name.description.contains("CsvComposition")
}) != nil
}

static func extractColumns<C: CsvComposition>(_ type: C.Type, variableDecl decl: VariableDeclSyntax) -> [String] {
guard let attributes = decl.attributes else {
return []
}
let attributes = decl.attributes
return attributes.compactMap { attribute in
var columns: [String] = []
for attr in attributes {
guard let attr = attr.as(AttributeSyntax.self) else {
continue
}
let hasCsvRowsAttr = attr.attributeName.as(SimpleTypeIdentifierSyntax.self)?.name.text == "CsvRows"
let hasCsvRowsAttr = attr.attributeName.as(IdentifierTypeSyntax.self)?.name.text == "CsvRows"
if !hasCsvRowsAttr {
continue
}
guard let tokens = attr.argument?.tokens(viewMode: .all) else {
guard let tokens = attr.arguments?.tokens(viewMode: .all) else {
continue
}
let column = tokens
Expand All @@ -107,7 +105,7 @@ public struct CsvCompositionParser {
}

extension StructDeclSyntax {
func findColumns(type: (some CsvComposition).Type, members: MemberDeclListSyntax) -> [String] {
func findColumns(type: (some CsvComposition).Type, members: MemberBlockItemListSyntax) -> [String] {
var columns: [String] = []
for member in members {
guard let decl = member.decl.as(VariableDeclSyntax.self) else {
Expand Down