Skip to content

Add SwiftSyntaxBuilder convenience initializers that mix parser integration and result builders #1012

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

ahoppen
Copy link
Member

@ahoppen ahoppen commented Oct 24, 2022

The most important use case of this is that we now allow things like

FunctionDecl("func fibonacci(_ n: Int) -> Int") {
  // result builder to generate body
}

Previously, the syntax tree for the signature had to be created manually.


While I was touching the convenience initializers, I merged them into a single file (which makes them easier to navigate IMO)


ahoppen@fe30a08 contains the corresponding changes to adopt these initializers in CodeGeneration.

@ahoppen
Copy link
Member Author

ahoppen commented Oct 24, 2022

@swift-ci Please test

@ahoppen ahoppen force-pushed the ahoppen/convenience-inits-mixing-string-and-result-builder branch from 81f9396 to fa34bdb Compare October 24, 2022 22:41
@ahoppen ahoppen requested review from kimdv and fwcd October 24, 2022 22:42
@ahoppen
Copy link
Member Author

ahoppen commented Oct 24, 2022

@swift-ci Please test

Comment on lines +19 to +20
let buildable = ProtocolDecl("public protocol DeclListBuildable") {
FunctionDecl("func buildDeclList(format: Format, leadingTrivia: Trivia?) -> [DeclSyntax]")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😍

Comment on lines +21 to +23
SwitchCase("case \(num):") {
Expr("print(count)")
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So nice and easy to read! 🎉

@ahoppen ahoppen force-pushed the ahoppen/convenience-inits-mixing-string-and-result-builder branch from 6cd8020 to 8e1c49c Compare October 25, 2022 08:55
@ahoppen
Copy link
Member Author

ahoppen commented Oct 25, 2022

@swift-ci Please test

@ahoppen ahoppen merged commit 5e9dcce into swiftlang:main Oct 25, 2022
@ahoppen ahoppen deleted the ahoppen/convenience-inits-mixing-string-and-result-builder branch October 25, 2022 15:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants