Skip to content
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

Trailing comma implementation #71975

Closed

Conversation

mateusrodriguesxyz
Copy link
Contributor

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

lib/Parse/ParseStmt.cpp Outdated Show resolved Hide resolved
lib/Parse/ParsePattern.cpp Outdated Show resolved Hide resolved
@CodaFi
Copy link
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
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
Contributor Author

mateusrodriguesxyz commented Mar 7, 2024

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

test/stmt/if_while_var.swift Show resolved Hide resolved
test/Parse/invalid.swift Outdated Show resolved Hide resolved
Copy link
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
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
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
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
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