-
Notifications
You must be signed in to change notification settings - Fork 441
Deprecate SyntaxFactory #539
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
Conversation
@swift-ci Please test |
64b17d4
to
d7e2ccb
Compare
@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.
LGTM assuming there was no good reason for it (I assume just an easy place to see all the nodes that could be created?)
From what I remember in conversations with @bitjammer, the goal of I personally don't know if that's necessarily worth it, especially as we're moving toward a Result-builder DSL future for Swift |
Yes, I agree that the verbosity of |
That’s right. The motivation was that there were just an incredible number of node types. If the tools and documentation could be improved, or there is another approach that could provide scoped hints to code completion, there’s no need. |
I personally like factory methods on the type instead of static func make(...) -> Self
static func blank() -> Self One drawback of func genFunctionDecl() -> FunctionDeclSyntax {
...
return .make(....)
} I feel |
@@ -17,6 +17,6 @@ public extension TupleExprElement { | |||
/// The presence of the colon will be inferred based on the presence of the label. | |||
init(label: String? = nil, expression: ExpressibleAsExprBuildable) { | |||
self.init( | |||
label: label.map(TokenSyntax.identifier), colon: label == nil ? nil : .colon, expression: expression) | |||
label: label.map { TokenSyntax.identifier($0) }, colon: label == nil ? nil : .colon, expression: expression) |
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.
Isn't it equivalent to what it was?
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.
The old implementation doesn’t work anymore because TokenSyntax.identifier
now takes three arguments, two of which are defaulted. But the argument default values are not used when referencing the function.
Instead of always writing `SyntaxFactory.make*` we can just use the initializers of the nodes that should be created, which leads code that’s nicer to read. rdar://97910890
b93da38
to
3bb792d
Compare
@swift-ci Please test |
@@ -119,6 +124,7 @@ public enum SyntaxFactory { | |||
% leading_trivia = token_trivia(token.requires_leading_space) | |||
% trailing_trivia = token_trivia(token.requires_trailing_space) | |||
% if token.is_keyword: | |||
@available(*, deprecated, message: "Use TokenSyntax.${token.swift_kind()}Keyword instead") |
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.
Nit: update this deprecation and remove the Keyword suffix
3bb792d
to
c1eeac6
Compare
Sources/SwiftSyntax/Tokens.swift.gyb
Outdated
% leading_trivia = '.space' if token.requires_leading_space else '[]' | ||
% trailing_trivia = '.space' if token.requires_trailing_space else '[]' | ||
% if token.is_keyword: | ||
public static func `${lowercase_first_word(token.name)}`( |
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.
What's wrong with token.swift_kind()
? I feel, for example, TokenSyntax.is(presence: .missing)
doesn't seem to be creating a new instance. ... And I'm not a fan of TokenSyntax.`init`()
I do think SwiftSyntaxBuilder
should use token.swift_kind()
c1eeac6
to
0682c85
Compare
@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.
We decided to go with initializers, instead of factory methods.
SwiftSyntax failed to build because swiftlang#539 and swiftlang#578 conflicted
Instead of always writing
SyntaxFactory.make*
we can just use the initializers of the nodes that should be created, which leads to a lot nicer code IMO.CC @akyrtzi @harlanhaskins in case you remember any compelling reasons why we decided to use
SyntaxFactory
instead of initializers when this was implemented.rdar://97910890