Skip to content

Conversation

@amartini51
Copy link
Member

@amartini51 amartini51 commented Dec 12, 2025

This updates the formal grammar and reference for all new places where a trailing comma is allowed, and shows them in the guide's discussion of array and dictionary literals. The guided tour already shows an example, so no change there except removing a stale TODO comment.

The SE proposal also adds support for trailing commas in \() style string interpolation, but the documentation for string interpolation currently only talks about the older single-expression form, so there isn't a place to add trailing commas. When updating the docs for SE-0228, adding info about trailing commas can be part of that work. See interpolation_grammar_73014172 for some initial work there.

Fixes: #418
Fixes: rdar://144570685

The grammar as written overproduces by allowing a comma after any
element in the literal -- while this does produce an optional trailing
comma, it also produces an optional second comma after any list element.
By definition, a trailing comma comes after only the last element.
The grammar for \() interpolation in string literals doesn't produce any
commas.  Updating that can be part of the docs work for SE-0228 and
SE-0477 -- there's nowhere to add a trailing comma right now.
This issue was resolved in commit 37eb636 (Show multiline string with
indentation in the tour (swiftlang#121), 2023-03-30).

References: 37eb636
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.

The grammar is missing trailing commas [SE-0439]

1 participant