Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a049f92

Browse files
dwijnandjvican
authored andcommittedMar 30, 2017
Final update to SIP-27 Trailing Commas (#731)
* Final update to SIP-27 Trailing Commas * Correct brackets vs braces.. * Use the right non-highlighted code block syntax
1 parent b6ae57c commit a049f92

File tree

1 file changed

+18
-64
lines changed

1 file changed

+18
-64
lines changed
 

‎sips/completed/_posts/2016-06-25-trailing-commas.md

Lines changed: 18 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ disqus: true
44
title: SIP-27 - Trailing Commas
55
redirect_from: "/sips/pending/trailing-commas.html"
66

7-
vote-status: approved
8-
vote-text: The following proposal has been approved but the spec needs to be updated and the implementation has to be ported from Parsers to Scanner.
7+
vote-status: accepted
8+
vote-text: This SIP has been Accepted, and is a part of Scala 2.12.2.
99
---
1010

1111
**By: Dale Wijnand**
@@ -25,6 +25,7 @@ vote-text: The following proposal has been approved but the spec needs to be upd
2525
| Sep 04th 2016 | New drawback: Cross building hinderance ([#533][]) |
2626
| Sep 12th 2016 | Remove cross building hinderance from drawbacks ([#533][]) |
2727
| Nov 12th 2016 | Major rework: multi-line, 2 variants & spec ([#625][]) |
28+
| Mar 14th 2017 | Final rework: multi-line, scanner level ([#731][]) |
2829

2930
## Motivation
3031

@@ -77,7 +78,16 @@ Adding and removing commas also introduces unnecessary noise in diffs:
7778

7879
### VCS authorship attribution
7980

80-
Using the example above, adding a comma after `baz` also unnecessarily changed the authorship of the line.
81+
Adding and removing commas also unnecessarily changed the authorship of the line:
82+
83+
~~~
84+
^199861c (Alice Doe 2016-12-20 10:20:05 +0000 1) Seq(
85+
^199861c (Alice Doe 2016-12-20 10:20:05 +0000 2) foo,
86+
^199861c (Alice Doe 2016-12-20 10:20:05 +0000 3) bar,
87+
66dddcc3 (Bob Doe 2017-01-10 11:45:10 +0000 4) baz,
88+
66dddcc3 (Bob Doe 2017-01-10 11:45:10 +0000 5) quux
89+
^199861c (Alice Doe 2016-12-20 10:20:05 +0000 6) )
90+
~~~
8191

8292
### Simplify code generation
8393

@@ -136,70 +146,13 @@ There are a number of different parts of the Scala grammar that are comma-separa
136146
* `Bindings`
137147
* `ids`, `ValDcl`, `VarDcl`, `VarDef` and `PatDef`
138148

139-
With this proposal I would like to present 2 variants:
140-
141-
1. The first variant adds trailing comma support to only multi-line `ArgumentExprs`, `Params` and `ClassParams`, which I consider to be the parts of the grammar that would most benefit from trailing commas.
142-
143-
2. The second variant adds trailing comma support to the whole grammar (again, only for multi-line), which means more consistency, but also supporting trailing commas in places that in practice don't really require it as much, such as `ids`.
144-
145-
In this proposal, only the first variant is considered: trailing comma support for `ArgumentExprs`, `Params` and `ParamClasses` for the sake of simplicity.
146-
147-
See below for more details on what that would mean.
148-
149-
#### Changing `ArgumentExprs`
150-
151-
**Spec change**
152-
153-
{% highlight diff %}
154-
Exprs ::= Expr {‘,’ Expr}
155-
-ArgumentExprs ::= ‘(’ [Exprs] ‘)’
156-
+ArgumentExprs ::= ‘(’ [Exprs] [‘,’] ‘)'
157-
{% endhighlight %}
158-
159-
**Example**
160-
{% highlight scala %}
161-
Seq(
162-
foo,
163-
bar,
164-
baz,
165-
)
166-
{% endhighlight %}
167-
168-
## `Params` and `ClassParams`
169-
170-
**Spec change**
171-
{% highlight diff %}
172-
Params ::= Param {‘,’ Param}
173-
- ParamClause ::= [nl] ‘(’ [Params] ‘)’
174-
-ParamClauses ::= {ParamClause} [[nl] ‘(’ ‘implicit’ Params ‘)’]
175-
+ ParamClause ::= [nl] ‘(’ [Params] [‘,’] ‘)’
176-
+ParamClauses ::= {ParamClause} [[nl] ‘(’ ‘implicit’ Params [‘,’] ‘)’]
177-
178-
ClassParams ::= ClassParam {‘,’ ClassParam}
179-
- ClassParamClause ::= [nl] ‘(’ [ClassParams] ‘)’
180-
-ClassParamClauses ::= {ClassParamClause} [[nl] ‘(’ ‘implicit’ ClassParams ‘)’]
181-
+ ClassParamClause ::= [nl] ‘(’ [ClassParams] [‘,’] ‘)’
182-
+ClassParamClauses ::= {ClassParamClause} [[nl] ‘(’ ‘implicit’ ClassParams [‘,’] ‘)’]
183-
{% endhighlight %}
184-
185-
**examples**
186-
{% highlight scala %}
187-
def bippy(
188-
foo: Int,
189-
bar: String,
190-
baz: Boolean,
191-
)
192-
193-
class Bippy(
194-
foo: Int,
195-
bar: String,
196-
baz: Boolean,
197-
)
198-
{% endhighlight %}
149+
Following Dr. Martin Odersky's suggestion, the proposal is that trailing commas are only supported in comma-separated elements that are enclosed by parentheses, square brackets or curly braces (`)`, `]`, and `}`, respectively).
199150

200151
## Implementation
201152

202-
The implementation of trailing commas is limited to changing Parsers.scala in the Scala compiler. An implementation of this proposal can be found at [scala/scala#5245][].
153+
As such, the suggested implementation would be a Scanner-level implementation, in which newlines and the closing delimiters are taken into account.
154+
155+
Such an implementation can be found at [scala/scala#5245][].
203156

204157
## Drawbacks/Trade-offs
205158

@@ -222,3 +175,4 @@ As an alternative to changing the language, there already exists today a compile
222175
[scala-commas]: https://github.com/47deg/scala-commas
223176
[#533]: https://github.com/scala/scala.github.com/pull/533
224177
[#625]: https://github.com/scala/scala.github.com/pull/625
178+
[#731]: https://github.com/scala/scala.github.com/pull/731

0 commit comments

Comments
 (0)
Please sign in to comment.