@@ -168,11 +168,14 @@ object Parsers {
168168 }
169169 }
170170
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) {
172172
173- val in : Scanner = new Scanner (source, profile = Profile .current, allowRewrite = allowRewrite )
173+ val in : Scanner = createScanner( )
174174 // in.debugTokenStream = true // uncomment to see the token stream of the standard scanner, but not syntax highlighting
175175
176+ def createScanner () =
177+ new Scanner (source, profile = Profile .current, allowRewrite = allowRewrite)
178+
176179 /** This is the general parse entry point.
177180 */
178181 def parse (): Tree = {
@@ -4318,19 +4321,17 @@ object Parsers {
43184321 }
43194322
43204323 /** 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):
43254325
4326+ override def createScanner (): Scanner = new Scanner (source):
43264327 override def nextToken (): Unit =
43274328 if token != EMPTY then patchIndent()
43284329 prev = saveCopy
43294330 super .nextToken()
4330- end ToIndentScanner
43314331
4332- override val in : ToIndentScanner = new ToIndentScanner (source)
43334332 assert(in.rewriteToIndent)
4333+
4334+ private var prev : TokenData = Scanners .newTokenData
43344335
43354336 /** The last offset where a colon at the end of line would be required if a subsequent { ... }
43364337 * block would be converted to an indentation region. */
@@ -4378,7 +4379,7 @@ object Parsers {
43784379 * 7. last token is not a leading operator
43794380 */
43804381 private def bracesToIndented [T ](body : => T , rewriteWithColon : Boolean ): T =
4381- val prevSaved = in. prev.saveCopy
4382+ val prevSaved = prev.saveCopy
43824383 val lastOffsetSaved = in.lastOffset
43834384 val underColonSyntax = possibleColonOffset == in.lastOffset
43844385 val colonRequired = rewriteWithColon || underColonSyntax
0 commit comments