mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
`expected-expansion` can be a bit unergonomic to use, because it requires pointing out not only the line, but also the column (which is not always obvious), and the nested diagnostics have to refer to absolute lines that aren't present in the source file. This makes both creating and updating these test cases easier through automation.
20 lines
634 B
Swift
20 lines
634 B
Swift
import SwiftSyntax
|
|
import SwiftSyntaxBuilder
|
|
import SwiftSyntaxMacros
|
|
|
|
public struct UnstringifyPeerMacro: PeerMacro {
|
|
public static func expansion(
|
|
of node: AttributeSyntax,
|
|
providingPeersOf declaration: some DeclSyntaxProtocol,
|
|
in context: some MacroExpansionContext
|
|
) throws -> [DeclSyntax] {
|
|
do {
|
|
let argumentList = node.arguments!.as(LabeledExprListSyntax.self)!
|
|
let arguments = [LabeledExprSyntax](argumentList)
|
|
let arg = arguments.first!.expression.as(StringLiteralExprSyntax.self)!
|
|
let content = arg.representedLiteralValue!
|
|
return [DeclSyntax("\(raw: content)")]
|
|
}
|
|
}
|
|
}
|