Skip to content

Conversation

HT154
Copy link
Contributor

@HT154 HT154 commented Jul 22, 2025

Implements apple/pkl-evolution#21

This changes Pkl's grammar but is not breaking. It only admits inputs that were previously invalid.

Covers these syntax elements:

  • Function parameter lists (method definitions) - tested in parser/methodTrailingCommas.pkl
  • Argument lists (method calls) - tested in parser/methodTrailingCommas.pkl
  • Type argument lists (in declared type names) - tested in parser/trailingCommas.pkl
  • Type parameter lists (in class/module headers) - tested in parser/trailingCommas.pkl
  • Type constraint lists - tested in parser/constraintsTrailingComma.pkl
  • Function type parameter lists (function type annotations) - tested in parser/lambdaTrailingCommas.pkl
  • Object body parameter lists (sugar'd lambdas) - tested in parser/lambdaTrailingCommas.pkl

Resolves #1132

Comment on lines +1743 to +1745
if (lookahead == terminator) {
return res;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This extra check is needed because some callers parse the element of the list themselves (while determining what construct it is) so it's possible for this function to be reached while at terminator.

Copy link
Member

@bioball bioball left a comment

Choose a reason for hiding this comment

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

Just a few nits, but overall this looks good!

Would also like @stackoverflow to take a look and review the parser changes.

Do you also mind writing a quick SPICE documenting the changes here?

@HT154 HT154 changed the title Allow trailing commas in comma-separated syntax elements SPICE-0019: Allow trailing commas in comma-separated syntax elements Aug 12, 2025
@HT154 HT154 requested a review from bioball August 12, 2025 23:48
Copy link
Contributor

@stackoverflow stackoverflow left a comment

Choose a reason for hiding this comment

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

Looks good!

Copy link
Member

@bioball bioball left a comment

Choose a reason for hiding this comment

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

LGTM! This is a nice improvement, thanks!

@bioball bioball merged commit ae5f02b into apple:main Aug 21, 2025
4 checks passed
@HT154 HT154 deleted the trailing-commas branch September 9, 2025 16:25
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.

Allow trailing commas in comma-separated syntax elements
3 participants