-
Notifications
You must be signed in to change notification settings - Fork 8
SPICE-0019: Trailing commas #21
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
Open
HT154
wants to merge
2
commits into
apple:main
Choose a base branch
from
HT154:trailing-commas
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+85
−0
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| = Trailing commas | ||
|
|
||
| * Proposal: link:./SPICE-0019-trailing-commas.adoc[SPICE-0019] | ||
| * Author: https://github.com/HT154[Jen Basch] | ||
| * Status: Accepted or Rejected | ||
| * Implemented in: Pkl 0.30.0 | ||
| * Category: Language, Tooling | ||
|
|
||
| == Introduction | ||
|
|
||
| This SPICE proposes changes Pkl's grammar to allow trailing commas in comma-separated syntax elements. | ||
|
|
||
| == Motivation | ||
|
|
||
| Many languages—Swift included—allow trailing commas in comma-separated syntax elements. | ||
| Allowing trailing commas allows users to add or reorder syntax elements in lists without incurring the effort (or diff) of managing the comma on the new/former final element. | ||
|
|
||
| == Proposed Solution | ||
|
|
||
| Pkl's grammar will be updated to accept trailing commas in these syntax elements: | ||
|
|
||
| * Function parameter lists (method definitions) | ||
| * Argument lists (method calls) | ||
| * Type parameter lists (in class/module definitions) | ||
| * Type argument lists (in declared type names, i.e. type annotations) | ||
| * Function type parameter lists (function type annotations) | ||
| * Type constraint lists | ||
| * Object body parameter lists (sugared lambdas) | ||
|
|
||
| == Detailed design | ||
|
|
||
| Pkl's parser will be updated to accept trailing commas in syntax elements that are comma-separated lists. | ||
|
|
||
| Corresponding changes will be necessary in the language's tooling: | ||
|
|
||
| === pkl-intellij | ||
|
|
||
| The plugin's grammar will be updated to accept trailing commas. | ||
|
|
||
| === tree-sitter-pkl | ||
|
|
||
| The grammar will be updated to accept trailing commas. | ||
|
|
||
| === pkl-formatter (see link:./SPICE-0014-canonical-formatter.adoc[SPICE-0014]) | ||
|
|
||
| In comma-separated syntax elements with a newline between the final element and the terminating token add a trailing comma after the final element. | ||
|
|
||
| [source,pkl] | ||
| ---- | ||
| // before formatting | ||
| x = myMethod(1, 2, 3) | ||
| y = myMethod( | ||
| 1, 2, 3 | ||
| ) | ||
| z = myMethod( | ||
| 1, | ||
| 2, | ||
| 3 | ||
| ) | ||
|
|
||
| // after formatting | ||
| x = myMethod(1, 2, 3) // <1> | ||
| y = myMethod( | ||
| 1, 2, 3, // <2> | ||
| ) | ||
| z = myMethod( | ||
| 1, | ||
| 2, | ||
| 3, // <3> | ||
| ) | ||
| ---- | ||
| <1> No newline is present between the final argument and the `)` so no trailing comma is added. | ||
| <2> A newline is present between the final argument and the `)` so a trailing comma is added. This happens even with multiple/all arguments on the same line. | ||
| <3> A newline is present between the final argument and the `)` so a trailing comma is added. | ||
|
|
||
| == Compatibility | ||
|
|
||
| This change has no impact on compatibility. | ||
| This does involve a change the language's grammar, but it only admits inputs that were previously invalid. | ||
|
|
||
| Changing the grammars in pkl-intellij and tree-sitter-pkl may result in cases where users mix newer tooling versions with older Pkl releases. | ||
| In these cases, evaluation may fail with editors providing no feedback that the code is invalid. | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.