Skip to content

Trailing comma implementation#71975

Closed
mateusrodriguesxyz wants to merge 11 commits intoswiftlang:mainfrom
mateusrodriguesxyz:trailing-comma
Closed

Trailing comma implementation#71975
mateusrodriguesxyz wants to merge 11 commits intoswiftlang:mainfrom
mateusrodriguesxyz:trailing-comma

Conversation

@mateusrodriguesxyz
Copy link
Copy Markdown
Contributor

This is a prototype implementation for Allow trailing comma in tuples, arguments and if/guard/while conditions gated behind -enable-experimental-feature TrailingComma.

@CodaFi
Copy link
Copy Markdown
Contributor

CodaFi commented Feb 29, 2024

A heads up that the full implementation will require changes to the Swift parser in swift-syntax.

@mateusrodriguesxyz
Copy link
Copy Markdown
Contributor Author

A heads up that the full implementation will require changes to the Swift parser in swift-syntax.

Sorry, I should have linked the swift-syntax PR
swiftlang/swift-syntax#2515

@mateusrodriguesxyz
Copy link
Copy Markdown
Contributor Author

mateusrodriguesxyz commented Mar 7, 2024

@CodaFi I've updated the implementation for conditionals to use a much simpler lookahead approach

Copy link
Copy Markdown
Contributor

@jameesbrown jameesbrown left a comment

Choose a reason for hiding this comment

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

I have reviewed and left comments suggesting a few small changes.

@mateusrodriguesxyz
Copy link
Copy Markdown
Contributor Author

@CodaFi could you take another look here? The implementation is up to date with the one approved in swiftlang/swift-syntax#2515 Thanks!

func testConditionsWithTrailingComma() {
func f(_ block: (Bool) -> Bool) -> Bool { block(true) }

if true, { }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What about cases such as if true { let a = 1 } how would those be handled? Looking through isStartOfConditionalStmtBody method, I couldn't see if those would be handled or not.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It parses fine because skipSingle() jumps from { to } and then there's nothing after that rules out { let a = 1 } as the if body.

Co-authored-by: Luciano Almeida <passos.luciano@outlook.com>
@mateusrodriguesxyz
Copy link
Copy Markdown
Contributor Author

mateusrodriguesxyz commented Apr 22, 2024

The swift-syntax implementation (swiftlang/swift-syntax#2515) has been merged.

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.

5 participants