@@ -559,19 +559,24 @@ object Parsers {
559
559
def inDefScopeBraces [T ](body : => T , rewriteWithColon : Boolean = false ): T =
560
560
inBracesOrIndented(body, rewriteWithColon)
561
561
562
- /**
563
- * @param readFirst If true, assume we have not read the first `part`. Otherwise,
564
- * expect that we have (i.e the next thing to expect is a [[COMMA ]]).
565
- */
566
- def commaSeparated [T ](part : () => T , readFirst : Boolean = true ): List [T ] =
562
+ /** <part> {`,` <part>} */
563
+ def commaSeparated [T ](part : () => T ): List [T ] =
567
564
in.currentRegion.withCommasExpected {
568
- val ts = new ListBuffer [T ]
569
- if (readFirst) ts += part()
565
+ commaSeparatedRest(part(), part)
566
+ }
567
+
568
+ /** {`,` <part>}
569
+ *
570
+ * currentRegion.commasExpected has to be set separately.
571
+ */
572
+ def commaSeparatedRest [T ](leading : T , part : () => T ): List [T ] =
573
+ if in.token == COMMA then
574
+ val ts = new ListBuffer [T ] += leading
570
575
while in.token == COMMA do
571
576
in.nextToken()
572
577
ts += part()
573
578
ts.toList
574
- }
579
+ else leading :: Nil
575
580
576
581
def inSepRegion [T ](f : Region => Region )(op : => T ): T =
577
582
val cur = in.currentRegion
@@ -1402,13 +1407,15 @@ object Parsers {
1402
1407
else {
1403
1408
if isErased then imods = addModifier(imods)
1404
1409
val paramStart = in.offset
1405
- val ts = funArgType() match {
1406
- case Ident (name) if name != tpnme.WILDCARD && in.isColon() =>
1407
- isValParamList = true
1408
- typedFunParam(paramStart, name.toTermName, imods) :: commaSeparated(
1409
- () => typedFunParam(in.offset, ident(), imods), readFirst = false )
1410
- case t =>
1411
- t :: commaSeparated(funArgType, readFirst = false )
1410
+ val ts = in.currentRegion.withCommasExpected {
1411
+ funArgType() match
1412
+ case Ident (name) if name != tpnme.WILDCARD && in.isColon() =>
1413
+ isValParamList = true
1414
+ commaSeparatedRest(
1415
+ typedFunParam(paramStart, name.toTermName, imods),
1416
+ () => typedFunParam(in.offset, ident(), imods))
1417
+ case t =>
1418
+ commaSeparatedRest(t, funArgType)
1412
1419
}
1413
1420
accept(RPAREN )
1414
1421
if isValParamList || in.isArrow then
@@ -3188,8 +3195,7 @@ object Parsers {
3188
3195
}
3189
3196
else ImportSelector (from)
3190
3197
3191
- def importSelector (idOK : Boolean )(): ImportSelector =
3192
- val isWildcard = in.token == USCORE || in.token == GIVEN || isIdent(nme.raw.STAR )
3198
+ def importSelector (idOK : Boolean ): ImportSelector =
3193
3199
atSpan(in.offset) {
3194
3200
in.token match
3195
3201
case USCORE => wildcardSelector()
@@ -3201,6 +3207,14 @@ object Parsers {
3201
3207
namedSelector(termIdent())
3202
3208
}
3203
3209
3210
+ def importSelectors (): List [ImportSelector ] =
3211
+ var idOK = true
3212
+ commaSeparated { () =>
3213
+ val isWildcard = in.token == USCORE || in.token == GIVEN || isIdent(nme.raw.STAR )
3214
+ try importSelector(idOK)
3215
+ finally idOK &= ! isWildcard
3216
+ }
3217
+
3204
3218
def importSelection (qual : Tree ): Tree =
3205
3219
if in.isIdent(nme.as) && qual.isInstanceOf [RefTree ] then
3206
3220
qual match
@@ -3217,7 +3231,7 @@ object Parsers {
3217
3231
case GIVEN =>
3218
3232
mkTree(qual, givenSelector() :: Nil )
3219
3233
case LBRACE =>
3220
- mkTree(qual, inBraces(commaSeparated(importSelector(idOK = true ) )))
3234
+ mkTree(qual, inBraces(importSelectors( )))
3221
3235
case _ =>
3222
3236
if isIdent(nme.raw.STAR ) then
3223
3237
mkTree(qual, wildcardSelector() :: Nil )
0 commit comments