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

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

mateusrodriguesxyz
Copy link

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
Member

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
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
apple/swift-syntax#2515

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

@Jamezzzb Jamezzzb 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
Author

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

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

if true, { }
Copy link
Collaborator

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
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
Author

mateusrodriguesxyz commented Apr 22, 2024

The swift-syntax implementation (apple/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.

None yet

5 participants