Allow trailing commas in comma-separated syntax elements #319

Closed
opened 2025-12-30 01:23:31 +01:00 by adam · 0 comments
Owner

Originally created by @HT154 on GitHub (Jul 21, 2025).

Many languages—Swift included—allow trailing commas between comma-separated syntax elements.
Allowing this means that adding elements to the end or reordering elements doesn't incur additional diff to manage the comma absence on the new/former final element.

These syntax rules in Pkl should allow trailing commas:

  • Function parameter lists (method definitions)
  • Argument lists (method calls)
  • Type argument lists (in declared type names)
  • Type parameter lists (in class/module headers)
  • Function type parameter lists (function type annotations)
  • Type constraint lists
  • Object body parameter lists (sugar'd lambdas)

Pkl's formatter should likely enforce trailing commas are present when the containing syntax rules are broken over multiple lines.
This will require support in Pkl's various grammars (pkl-intellij, tree-sitter-pkl).
This should probably also affect the pkl.experimental.syntax library in pkl-pantry.

Originally created by @HT154 on GitHub (Jul 21, 2025). Many languages—Swift included—allow trailing commas between comma-separated syntax elements. Allowing this means that adding elements to the end or reordering elements doesn't incur additional diff to manage the comma absence on the new/former final element. These syntax rules in Pkl should allow trailing commas: * Function parameter lists (method definitions) * Argument lists (method calls) * Type argument lists (in declared type names) * Type parameter lists (in class/module headers) * Function type parameter lists (function type annotations) * Type constraint lists * Object body parameter lists (sugar'd lambdas) Pkl's formatter should likely enforce trailing commas are present when the containing syntax rules are broken over multiple lines. This will require support in Pkl's various grammars (pkl-intellij, tree-sitter-pkl). This should probably also affect the `pkl.experimental.syntax` library in pkl-pantry.
adam closed this issue 2025-12-30 01:23:31 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/pkl#319