@@ -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 = {
@@ -4318,19 +4321,17 @@ object Parsers {
4318
4321
}
4319
4322
4320
4323
/** The Scala parser that can rewrite to indent */
4321
- class ToIndentParser (source : SourceFile )(using Context ) extends Parser (source):
4322
- class ToIndentScanner (source : SourceFile )(using Context ) extends Scanner (source):
4323
- /** A copy of the previous token */
4324
- var prev : TokenData = Scanners .newTokenData
4324
+ private class ToIndentParser (source : SourceFile )(using Context ) extends Parser (source):
4325
4325
4326
+ override def createScanner (): Scanner = new Scanner (source):
4326
4327
override def nextToken (): Unit =
4327
4328
if token != EMPTY then patchIndent()
4328
4329
prev = saveCopy
4329
4330
super .nextToken()
4330
- end ToIndentScanner
4331
4331
4332
- override val in : ToIndentScanner = new ToIndentScanner (source)
4333
4332
assert(in.rewriteToIndent)
4333
+
4334
+ private var prev : TokenData = Scanners .newTokenData
4334
4335
4335
4336
/** The last offset where a colon at the end of line would be required if a subsequent { ... }
4336
4337
* block would be converted to an indentation region. */
@@ -4378,7 +4379,7 @@ object Parsers {
4378
4379
* 7. last token is not a leading operator
4379
4380
*/
4380
4381
private def bracesToIndented [T ](body : => T , rewriteWithColon : Boolean ): T =
4381
- val prevSaved = in. prev.saveCopy
4382
+ val prevSaved = prev.saveCopy
4382
4383
val lastOffsetSaved = in.lastOffset
4383
4384
val underColonSyntax = possibleColonOffset == in.lastOffset
4384
4385
val colonRequired = rewriteWithColon || underColonSyntax
0 commit comments