Skip to content

Add MacroExp for freestanding macro expressions #141

@leogdion

Description

@leogdion

Summary

SyntaxKit has no support for freestanding macro expressions (MacroExpansionExprSyntax). A new MacroExp type should be added to cover #macroName(args...) syntax.

Details

  • Conforms to ExprCodeBlock (expression, not a declaration)
  • Follows the Exp suffix naming convention used by FunctionCallExp, PropertyAccessExp, etc.
  • Maps to MacroExpansionExprSyntax in SwiftSyntax
  • Covers both built-in macros and custom user-defined macros:
    • #stringify(x)
    • #colorLiteral(red:green:blue:alpha:)
    • #imageLiteral(resourceName:)
    • Any custom #myMacro(arg:) defined via @freestanding(.expression)

Example API

MacroExp("stringify", ReferenceExp("x"))
// → #stringify(x)

MacroExp("colorLiteral") {
  Argument("red", Literal.float(0.5))
  Argument("green", Literal.float(0.2))
  Argument("blue", Literal.float(0.8))
  Argument("alpha", Literal.float(1.0))
}
// → #colorLiteral(red: 0.5, green: 0.2, blue: 0.8, alpha: 1.0)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions