Skip to content

Add a convenience initializer for TernaryExpr #610

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

Merged
merged 2 commits into from
Aug 20, 2022

Conversation

fwcd
Copy link
Member

@fwcd fwcd commented Aug 19, 2022

Generating ternary expressions using SwiftSyntaxBuilder with correct formatting is quite verbose currently:

TernaryExpr(
  conditionExpression: ...,
  questionMark: .infixQuestionMarkToken(leadingTrivia: .space, trailingTrivia: .space),
  firstChoice: ...,
  colonMark: .colonToken(leadingTrivia: .space),
  secondChoice: ...
)

This PR adds a convenience initializer that makes constructed TernaryExprs in Swift almost as terse as their generated equivalents:

TernaryExpr(
  if: ...,
  then: ...,
  else: ...
)

I've used the if-then-else terminology for the labels since it is short, clear and easily disambiguable from the generated initializer, but feel free to suggest alternative spellings.

@fwcd fwcd requested a review from ahoppen as a code owner August 19, 2022 18:11
@fwcd
Copy link
Member Author

fwcd commented Aug 19, 2022

@swift-ci please test

@fwcd fwcd merged commit 6ce8c48 into swiftlang:main Aug 20, 2022
@fwcd fwcd deleted the ternary-convenience-init branch August 20, 2022 13:39
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