Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ay42 committed May 28, 2024
1 parent 9656cc6 commit 6fadab9
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 23 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# swift-equatable
11 changes: 0 additions & 11 deletions Sources/Equatable/Equatable.swift

This file was deleted.

8 changes: 8 additions & 0 deletions Sources/Equatable/EquatableMacro.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/// A macro that produces both a value and a string containing the
/// source code that generated the value. For example,
///
/// #stringify(x + y)
///
/// produces a tuple `(x + y, "x + y")`.
@attached(extension, conformances: Equatable)
public macro equatable() = #externalMacro(module: "MacroExamplesImplementation", type: "EquatableExtensionMacro")
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,13 @@ import SwiftSyntaxMacros
/// will expand to
///
/// (x + y, "x + y")
public struct StringifyMacro: ExpressionMacro {
public static func expansion(
of node: some FreestandingMacroExpansionSyntax,
in context: some MacroExpansionContext
) -> ExprSyntax {
guard let argument = node.argumentList.first?.expression else {
fatalError("compiler bug: the macro does not have any arguments")
}

return "(\(argument), \(literal: argument.description))"
}
public enum EquatableExtensionMacro: ExtensionMacro {

}

@main
struct EquatablePlugin: CompilerPlugin {
let providingMacros: [Macro.Type] = [
StringifyMacro.self,
EquatableExtensionMacro.self,
]
}

0 comments on commit 6fadab9

Please sign in to comment.