-
Notifications
You must be signed in to change notification settings - Fork 441
Migrate from strings to typed buildable nodes in SyntaxBuildableWrappers
#542
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migrate from strings to typed buildable nodes in SyntaxBuildableWrappers
#542
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple of notes on the implementation
/// If optional `?`, otherwise the empty string. | ||
var optionalQuestionMark: String { | ||
isOptional ? "?" : "" | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This property is replaced with optionalWrapped(type:)
and optionalChained(expr:)
, depending on whether a type or an expression is needed.
var expressibleAs: String { | ||
/// The `ExpressibleAs*` Swift type for this syntax kind without any | ||
/// question marks attached. | ||
var expressibleAsBaseName: String { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR factors out a few ...BaseName
properties (expressibleAs
, syntax
, buildable
). These represent a non-optional type and will still be strings (as opposed to, e.g. ExpressibleAsTypeBuildable
s) to make them easy to embed in string interpolations and across type and expression contexts.
Thus .xyzBaseName
replaces the earlier .nonOptional.xyz
idiom.
let buildableConformances: [String] = [type.expressibleAsBaseName, type.listBuildableBaseName] + (isSyntax ? [] : [syntaxType.buildableBaseName]) | ||
let listConformances: [String] = isSyntax ? [] : [syntaxType.listBuildableBaseName] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously we relied on these types being non-optional. Since optional types wouldn't make sense e.g. in conformance lists and dealing with strings is easier, we use the base names now in a few more places (this shouldn't change anything in the generated code).
inheritanceClause: createTypeInheritanceClause(conformances: listConformances) | ||
) { | ||
FunctionDecl( | ||
leadingTrivia: [ | ||
"/// Builds list of `\(type.syntax)`s.", | ||
"/// Builds list of `\(type.syntaxBaseName)`s.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same goes here (and for the other places where base names are now used).
@swift-ci please test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two minor comment, otherwise LGTM.
Also, I think that optionalWrapped
and optionalChained
are good examples of how SwiftSyntaxBuilder simplifies source generation. 👍
Sources/SwiftSyntaxBuilderGeneration/SyntaxBuildableChild.swift
Outdated
Show resolved
Hide resolved
Previously 'nil' was (incorrectly) generated as an identifier.
ec34a35
to
966a50c
Compare
@swift-ci please test |
As proposed in #485 (review), this PR migrates the generated snippets of Swift code in
SyntaxBuildableType
andSyntaxBuildableChild
toExprBuildable
s andTypeBuildable
s.This will pave the way for a future PR porting
BuildableNodes.swift.gyb
toSwiftSyntaxBuilderGeneration
.