Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,28 @@ public enum CaseDetectionMacro: MemberMacro {
) throws -> [DeclSyntax] {
declaration.memberBlock.members
.compactMap { $0.decl.as(EnumCaseDeclSyntax.self) }
.map { $0.elements.first!.name }
.map { ($0, $0.initialUppercased) }
.map { original, uppercased in
.map { $0.elements }
.flatMap { $0 }
.map { $0.name }
.map { ($0, $0.pascalcased) }
.map { original, pascalcased in
"""
var is\(raw: uppercased): Bool {
if case .\(raw: original) = self {
return true
}

return false
var is\(raw: pascalcased): Bool {
self == .\(raw: original)
}
"""
}
}
}

extension TokenSyntax {
fileprivate var initialUppercased: String {
let name = self.text
guard let initial = name.first else {
return name
fileprivate var pascalcased: String {
self.text
.replacingOccurrences(of: "_", with: " ")
.replacingOccurrences(of: "(?<=.)([A-Z])", with: " $1", options: .regularExpression)
.lowercased()
.split(separator: " ")
.map { $0.capitalized }
.joined()
}

return "\(initial.uppercased())\(name.dropFirst())"
}
}