unified: Add Swift node type schema generator - #22459
Conversation
Adds the SwiftSyntax-based schemagen tool and a manual wrapper for regenerating swift_node_types.yml after dependency updates. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Copilot review overview
Review tier: Balanced
Findings: 1
New issues introduced by this change (4)
| Severity | Finding |
|---|---|
unified/swift-syntax-rs/schemagen/Sources/schemagen/main.swift — This hard-coded snapshot means regeneration will silently miss any new variable-text token kind… |
|
unified/swift-syntax-rs/schemagen/Sources/schemagen/main.swift — This list is incomplete: swift-syntax also generates an unexpectedAfterX slot after the final… |
|
unified/swift-syntax-rs/schemagen/README.md — The documented filter omits unexpectedAfterX, which swift-syntax generates after the final child.… |
|
unified/swift-syntax-rs/schemagen/Sources/schemagen/main.swift — Add the missing “that” so this sentence is grammatical. |
What changed in this PR
Adds tooling to regenerate Swift extractor node types from pinned swift-syntax definitions.
Changes:
- Adds the Swift schema generator package and regeneration script.
- Marks the schema as generated and documents the workflow.
- Updates extractor and contributor documentation.
| File | Description |
|---|---|
unified/swift-syntax-rs/schemagen/Sources/schemagen/main.swift |
Generates the node schema. |
unified/swift-syntax-rs/schemagen/README.md |
Documents generator design and usage. |
unified/swift-syntax-rs/schemagen/Package.swift |
Defines the generator package. |
unified/swift-syntax-rs/schemagen/.gitignore |
Ignores generated dependencies and builds. |
unified/swift-syntax-rs/README.md |
Documents regeneration workflow. |
unified/scripts/regenerate-node-types.sh |
Resolves sources and runs generation. |
unified/extractor/swift_node_types.yml |
Adds generated-file headers. |
unified/extractor/src/languages/swift/adapter.rs |
Documents the schema’s generator. |
unified/AGENTS.md |
Updates contributor guidance. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| // Named-leaf ("varying") token kinds, mirroring the extractor adapter's | ||
| // VARYING_TOKEN_KINDS. Fixed tokens are anonymous (keyed by text) and are not | ||
| // matched by any rule, so they are not emitted here. | ||
| let varyingTokens = [ | ||
| "identifier", "integerLiteral", "floatLiteral", "stringSegment", | ||
| "binaryOperator", "prefixOperator", "postfixOperator", "dollarIdentifier", | ||
| "regexLiteralPattern", "rawStringPoundDelimiter", "regexPoundDelimiter", | ||
| "shebang", "unknown", | ||
| ] |
| // swift-syntax error-recovery slots (`unexpectedBeforeX` and | ||
| // `unexpectedBetweenXAndY`) are never matched by rules. |
| - `unexpectedBeforeX` and `unexpectedBetweenXAndY` error-recovery children are | ||
| dropped; no rule matches them. This filters on the child name: |
| "shebang", "unknown", | ||
| ] | ||
|
|
||
| // The yeast type references a child maps to. A collection wrapper is elided by |
| fi | ||
| mv "$tmp" "$output" | ||
| chmod 644 "$output" | ||
| echo "Regenerated $output" >&2 |
There was a problem hiding this comment.
Instead of having yet another script, could we maybe do this through Bazel? For Swift we e.g. have bazel run //swift/codegen, so I don't see why something similar shouldn't be possible here (and yes, I saw the Bazel remark in unified/swift-syntax-rs/schemagen/README.md).
| dependencies: [ | ||
| // Deliberately a path dependency on the checkout the neighbouring FFI | ||
| // package resolved, rather than a second URL/exact pin: the schema has | ||
| // to describe the very swift-syntax that the parser links, and a | ||
| // single pin cannot drift from itself. | ||
| .package(name: "swift-syntax", path: "../swift/.build/checkouts/swift-syntax"), | ||
| ], |
There was a problem hiding this comment.
This seems to guarantee something that it doesn't really guarantee: This clearly will get violated when the FFI package was built with Bazel.


Adds tooling for automatically updating
swift_node_types.ymlwhen new versions ofswift-syntaxare released.NB: I have not tested this process on macOS, but I have confirmed that it works well on Codespaces.