# Swift macros without requiring swift-syntax

**URL:** <https://forums.swift.org/t/swift-macros-without-requiring-swift-syntax/67324>\
**Category:** Community Showcase\
**Tags:** macros, buildtoolplugin\
**Created:** [September 17, 2023, 12:15pm UTC](https://forums.swift.org/t/swift-macros-without-requiring-swift-syntax/67324 "2023-09-17T12:15:11Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jjrscott](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jjrscott/32/12494_2.png) [@jjrscott](https://forums.swift.org/u/jjrscott)\
**Post date:** [September 17, 2023, 12:15pm UTC](https://forums.swift.org/t/swift-macros-without-requiring-swift-syntax/67324/1 "2023-09-17T12:15:11Z")

</div>

[GitHub - jjrscott/SwiftCompilerPlugin: Swift macros without requiring swift-syntax](https://github.com/jjrscott/SwiftCompilerPlugin) extracts the bare minimum from [swift-syntax](https://github.com/apple/swift-syntax) to be able to build a macro in Xcode 15. All you get are the strings, no fancy object trees.

If nothing else it will allow you to see what is _really_ sent to your plugin before it's converted to structures etc.

### Example

Here's the classic example from the default Xcode template which implements `stringify` renamed here to be `ExpressionMacro`.

```swift
@freestanding(expression)
public macro ExpressionMacro<T>(_ value: T) -> (T, String) = #externalMacro(module: "ExampleMacros", type: "ExpressionMacro")

...

let (result, code) = #ExpressionMacro(a + b)
(a + b, "a + b")
/* {
  "expandFreestandingMacro" : {
    "macro" : {
      "moduleName" : "ExampleMacros",
      "name" : "ExpressionMacro",
      "typeName" : "ExpressionMacro"
    },
    "syntax" : {
      "kind" : "expression",
      "location" : {
        "fileID" : "ExampleClient\/main.swift",
        "fileName" : "***/SwiftCompilerPlugin\/Examples\/Sources\/ExampleClient\/main.swift",
        "line" : 7,
        "offset" : 78,
        "column" : 22
      },
      "source" : "#ExpressionMacro(a + b)"
    },
    "discriminator" : "$s13ExampleClient33_C7C48FD1C44CD1E5F2188E7B86F2D462Ll15ExpressionMacrofMf_",
    "macroRole" : "expression"
  }
}*/

```
