@@ -168,11 +168,14 @@ object Parsers {
168
168
}
169
169
}
170
170
171
- class Parser private [parsing ] (source : SourceFile , allowRewrite : Boolean = true )(using Context ) extends ParserCommon (source) {
171
+ class Parser private [Parsers ] (source : SourceFile , allowRewrite : Boolean = true )(using Context ) extends ParserCommon (source) {
172
172
173
- val in : Scanner = new Scanner (source, profile = Profile .current, allowRewrite = allowRewrite )
173
+ val in : Scanner = createScanner( )
174
174
// in.debugTokenStream = true // uncomment to see the token stream of the standard scanner, but not syntax highlighting
175
175
176
+ def createScanner () =
177
+ new Scanner (source, profile = Profile .current, allowRewrite = allowRewrite)
178
+
176
179
/** This is the general parse entry point.
177
180
*/
178
181
def parse (): Tree = {
@@ -4319,19 +4322,17 @@ object Parsers {
4319
4322
}
4320
4323
4321
4324
/** The Scala parser that can rewrite to indent */
4322
- class ToIndentParser (source : SourceFile )(using Context ) extends Parser (source):
4323
- class ToIndentScanner (source : SourceFile )(using Context ) extends Scanner (source):
4324
- /** A copy of the previous token */
4325
- var prev : TokenData = Scanners .newTokenData
4325
+ private class ToIndentParser (source : SourceFile )(using Context ) extends Parser (source):
4326
4326
4327
+ override def createScanner (): Scanner = new Scanner (source):
4327
4328
override def nextToken (): Unit =
4328
4329
if token != EMPTY then patchIndent()
4329
4330
prev = saveCopy
4330
4331
super .nextToken()
4331
- end ToIndentScanner
4332
4332
4333
- override val in : ToIndentScanner = new ToIndentScanner (source)
4334
4333
assert(in.rewriteToIndent)
4334
+
4335
+ private var prev : TokenData = Scanners .newTokenData
4335
4336
4336
4337
/** The last offset where a colon at the end of line would be required if a subsequent { ... }
4337
4338
* block would be converted to an indentation region. */
@@ -4379,7 +4380,7 @@ object Parsers {
4379
4380
* 7. last token is not a leading operator
4380
4381
*/
4381
4382
private def bracesToIndented [T ](body : => T , rewriteWithColon : Boolean ): T =
4382
- val prevSaved = in. prev.saveCopy
4383
+ val prevSaved = prev.saveCopy
4383
4384
val lastOffsetSaved = in.lastOffset
4384
4385
val underColonSyntax = possibleColonOffset == in.lastOffset
4385
4386
val colonRequired = rewriteWithColon || underColonSyntax
0 commit comments