Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
MahdiBM committed Jul 10, 2024
1 parent fc06553 commit a1ae02e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 78 deletions.
2 changes: 1 addition & 1 deletion Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"location" : "https://github.com/mahdibm/swift-mustache",
"state" : {
"branch" : "mmbm-swift-6",
"revision" : "72f3279b228908c786d80289e7260439163654f2"
"revision" : "b3cd0bca48cd1883e52a1ed6b79dfccd64ff5952"
}
},
{
Expand Down
108 changes: 31 additions & 77 deletions Sources/EnumeratorMacro/Enumerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,97 +2,51 @@
import SwiftSyntaxMacros

@attached(member, names: arbitrary)
public macro Enumerator(_ templates: String...) = #externalMacro(
public macro Enumerator(_ templates: StaticString...) = #externalMacro(
module: "EnumeratorMacroImpl",
type: "EnumeratorMacroType"
)

//@attached(member, names: arbitrary)
//macro CreateSubtype(
// _ template: String = """
// enum Subtype: String {
// {{#cases}}
// case {{name}}
// {{/cases}}
// }
// """
//) = #externalMacro(
// module: "EnumeratorMacroImpl",
// type: "EnumeratorMacroType"
//)
//
//@CreateSubtype()
//enum TestEnum2 {
// case a(value: String)
// case b
// case f
// case testCase(testValue: String)
//
// func dso() {
// let a = Subtype.a
// }
//}
//
//@CreateSubtype()
//enum TestEnumd2 {
// case a(value: String)
// case b
// case f
// case testCase(testValue: String)
//}
@attached(member, names: arbitrary)
macro CreateSubtype(
_ templates: String = """
enum Subtype: String {
{{#cases}}
case {{name}}
{{/cases}}
}
"""
) = #externalMacro(
module: "EnumeratorMacroImpl",
type: "EnumeratorMacroType"
)

@Enumerator("""
enum Subtype: String {
{{#cases}}
case {{name}}
{{/cases}}
}
""",
"""
var subtype: Subtype {
switch self {
{{#cases}}
case .{{name}}:
return .{{name}}
{{/cases}}
}
}
""",
"""
var parameterNames: [String] {
switch self {
{{#cases}}
case .{{name}}:
return [
{{^parameters}}
"empty"
{{/parameters}}
{{#parameters}}
"{{snakeCased(name)}}"
{{/parameters}}
]
case {{name}}
{{/cases}}
}
}
""",
"""
{{#cases}}
var is{{capitalized(name)}}: Bool {
switch self {
case .{{name}}:
return true
default:
return false
}
}
{{/cases}}
""")
enum TestEnum {
enum TestEnum2 {
case a(value: String)
case b
case f
case testCase(testValue: String)

func isTheSameCase(as other: Self) -> Bool {
self.subtype == other.subtype
func dso() {
let a = Subtype.a
}
}

@CreateSubtype()
enum TestEnumd2 {
case a(value: String)
case b
case f
case testCase(testValue: String)

// func dso() {
// let a = Subtype.a
// }
}

0 comments on commit a1ae02e

Please sign in to comment.