@@ -225,7 +225,7 @@ object Parsers {
225
225
|| allowedMods.contains(in.token)
226
226
|| in.isSoftModifierInModifierPosition && ! excludedSoftModifiers.contains(in.name)
227
227
228
- def isStatSep : Boolean = in.isNewLine || in.token == SEMI
228
+ def isStatSep : Boolean = in.isStatSep
229
229
230
230
/** A '$' identifier is treated as a splice if followed by a `{`.
231
231
* A longer identifier starting with `$` is treated as a splice/id combination
@@ -252,13 +252,8 @@ object Parsers {
252
252
253
253
/** Skip on error to next safe point.
254
254
*/
255
- protected def skip (stopAtComma : Boolean ): Unit =
256
- val lastRegion = in.currentRegion
257
- def atStop =
258
- in.token == EOF
259
- || ((stopAtComma && in.token == COMMA ) || skipStopTokens.contains(in.token)) && (in.currentRegion eq lastRegion)
260
- while ! atStop do
261
- in.nextToken()
255
+ def skip (): Unit =
256
+ in.skip()
262
257
lastErrorOffset = in.offset
263
258
264
259
def warning (msg : Message , sourcePos : SourcePosition ): Unit =
@@ -272,35 +267,37 @@ object Parsers {
272
267
273
268
/** Issue an error at current offset that input is incomplete */
274
269
def incompleteInputError (msg : Message ): Unit =
275
- report.incompleteInputError(msg, source.atSpan(Span (in.offset)))
270
+ if in.offset != lastErrorOffset then
271
+ report.incompleteInputError(msg, source.atSpan(Span (in.offset)))
276
272
277
273
/** If at end of file, issue an incompleteInputError.
278
274
* Otherwise issue a syntax error and skip to next safe point.
279
275
*/
280
276
def syntaxErrorOrIncomplete (msg : Message , offset : Int = in.offset): Unit =
281
- if (in.token == EOF ) incompleteInputError(msg)
277
+ if in.token == EOF then
278
+ incompleteInputError(msg)
282
279
else
283
280
syntaxError(msg, offset)
284
- skip(stopAtComma = true )
281
+ skip()
285
282
286
283
def syntaxErrorOrIncomplete (msg : Message , span : Span ): Unit =
287
- if (in.token == EOF ) incompleteInputError(msg)
284
+ if in.token == EOF then
285
+ incompleteInputError(msg)
288
286
else
289
287
syntaxError(msg, span)
290
- skip(stopAtComma = true )
288
+ skip()
291
289
292
290
/** Consume one token of the specified type, or
293
291
* signal an error if it is not there.
294
292
*
295
293
* @return The offset at the start of the token to accept
296
294
*/
297
- def accept (token : Int ): Int = {
295
+ def accept (token : Int ): Int =
298
296
val offset = in.offset
299
- if ( in.token != token)
297
+ if in.token != token then
300
298
syntaxErrorOrIncomplete(ExpectedTokenButFound (token, in.token))
301
- if ( in.token == token) in.nextToken()
299
+ if in.token == token then in.nextToken()
302
300
offset
303
- }
304
301
305
302
def accept (name : Name ): Int = {
306
303
val offset = in.offset
@@ -355,7 +352,7 @@ object Parsers {
355
352
false // it's a statement that might be legal in an outer context
356
353
else
357
354
in.nextToken() // needed to ensure progress; otherwise we might cycle forever
358
- skip(stopAtComma = false )
355
+ skip()
359
356
true
360
357
361
358
in.observeOutdented()
@@ -562,18 +559,14 @@ object Parsers {
562
559
def inDefScopeBraces [T ](body : => T , rewriteWithColon : Boolean = false ): T =
563
560
inBracesOrIndented(body, rewriteWithColon)
564
561
565
- /** part { `separator` part }
566
- */
567
- def tokenSeparated [ T ]( separator : Int , part : () => T ) : List [T ] = {
568
- val ts = new ListBuffer [ T ] += part()
569
- while (in.token == separator) {
570
- in.nextToken ()
571
- ts += part()
562
+ def commaSeparated [ T ]( part : () => T ) : List [ T ] =
563
+ in.currentRegion.withCommasExpected {
564
+ val ts = new ListBuffer [T ] += part()
565
+ while in.token == COMMA do
566
+ in.nextToken()
567
+ ts += part ()
568
+ ts.toList
572
569
}
573
- ts.toList
574
- }
575
-
576
- def commaSeparated [T ](part : () => T ): List [T ] = tokenSeparated(COMMA , part)
577
570
578
571
def inSepRegion [T ](f : Region => Region )(op : => T ): T =
579
572
val cur = in.currentRegion
@@ -3766,7 +3759,7 @@ object Parsers {
3766
3759
val derived =
3767
3760
if (isIdent(nme.derives )) {
3768
3761
in.nextToken()
3769
- tokenSeparated( COMMA , () => convertToTypeId(qualId()))
3762
+ commaSeparated( () => convertToTypeId(qualId()))
3770
3763
}
3771
3764
else Nil
3772
3765
possibleTemplateStart()
0 commit comments