Skip to content

Commit 6409a2f

Browse files
committed
Drop stopAtComma parameter in skip.
It turns out it's not needed. We can safely stop at a comma when in a statement sequence. It's not materially different from stopping a closing parenthesis.
1 parent 9cbee41 commit 6409a2f

File tree

3 files changed

+14
-15
lines changed

3 files changed

+14
-15
lines changed

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -252,14 +252,16 @@ object Parsers {
252252

253253
/** Skip on error to next safe point.
254254
*/
255-
protected def skip(stopAtComma: Boolean): Unit =
255+
protected def skip(): Unit =
256256
val lastRegion = in.currentRegion
257+
in.skipping = true
257258
def atStop =
258259
in.token == EOF
259-
|| ((stopAtComma && in.token == COMMA) || skipStopTokens.contains(in.token)) && (in.currentRegion eq lastRegion)
260+
|| skipStopTokens.contains(in.token) && (in.currentRegion eq lastRegion)
260261
while !atStop do
261262
in.nextToken()
262263
lastErrorOffset = in.offset
264+
in.skipping = false
263265

264266
def warning(msg: Message, sourcePos: SourcePosition): Unit =
265267
report.warning(msg, sourcePos)
@@ -281,13 +283,13 @@ object Parsers {
281283
if (in.token == EOF) incompleteInputError(msg)
282284
else
283285
syntaxError(msg, offset)
284-
skip(stopAtComma = true)
286+
skip()
285287

286288
def syntaxErrorOrIncomplete(msg: Message, span: Span): Unit =
287289
if (in.token == EOF) incompleteInputError(msg)
288290
else
289291
syntaxError(msg, span)
290-
skip(stopAtComma = true)
292+
skip()
291293

292294
/** Consume one token of the specified type, or
293295
* signal an error if it is not there.
@@ -355,7 +357,8 @@ object Parsers {
355357
false // it's a statement that might be legal in an outer context
356358
else
357359
in.nextToken() // needed to ensure progress; otherwise we might cycle forever
358-
skip(stopAtComma=false)
360+
lastErrorOffset = in.offset
361+
skip()
359362
true
360363

361364
in.observeOutdented()
@@ -562,18 +565,12 @@ object Parsers {
562565
def inDefScopeBraces[T](body: => T, rewriteWithColon: Boolean = false): T =
563566
inBracesOrIndented(body, rewriteWithColon)
564567

565-
/** part { `separator` part }
566-
*/
567-
def tokenSeparated[T](separator: Int, part: () => T): List[T] = {
568+
def commaSeparated[T](part: () => T): List[T] =
568569
val ts = new ListBuffer[T] += part()
569-
while (in.token == separator) {
570+
while in.token == COMMA do
570571
in.nextToken()
571572
ts += part()
572-
}
573573
ts.toList
574-
}
575-
576-
def commaSeparated[T](part: () => T): List[T] = tokenSeparated(COMMA, part)
577574

578575
def inSepRegion[T](f: Region => Region)(op: => T): T =
579576
val cur = in.currentRegion
@@ -3766,7 +3763,7 @@ object Parsers {
37663763
val derived =
37673764
if (isIdent(nme.derives)) {
37683765
in.nextToken()
3769-
tokenSeparated(COMMA, () => convertToTypeId(qualId()))
3766+
commaSeparated(() => convertToTypeId(qualId()))
37703767
}
37713768
else Nil
37723769
possibleTemplateStart()

compiler/src/dotty/tools/dotc/parsing/Scanners.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ object Scanners {
170170
/** A switch whether operators at the start of lines can be infix operators */
171171
private[Scanners] var allowLeadingInfixOperators = true
172172

173+
var skipping = false
174+
173175
var debugTokenStream = false
174176
val showLookAheadOnDebug = false
175177

compiler/src/dotty/tools/dotc/parsing/Tokens.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ object Tokens extends TokensCommon {
287287

288288
final val endMarkerTokens = identifierTokens | BitSet(IF, WHILE, FOR, MATCH, TRY, NEW, THROW, GIVEN, VAL, THIS)
289289

290-
final val skipStopTokens = BitSet(SEMI, NEWLINE, NEWLINES, RBRACE, RPAREN, RBRACKET, OUTDENT)
290+
final val skipStopTokens = BitSet(SEMI, COMMA, NEWLINE, NEWLINES, RBRACE, RPAREN, RBRACKET, OUTDENT)
291291

292292
final val softModifierNames = Set(nme.inline, nme.opaque, nme.open, nme.transparent, nme.infix)
293293
}

0 commit comments

Comments
 (0)