@@ -161,11 +161,14 @@ object Parsers:
161161 else if (in.token == RBRACE || in.token == OUTDENT ) openBraces -= 1
162162 in.nextToken()
163163
164- class Parser private [parsing ] (source : SourceFile , allowRewrite : Boolean = true )(using Context ) extends ParserCommon (source) {
164+ class Parser private [Parsers ] (source : SourceFile , allowRewrite : Boolean = true )(using Context ) extends ParserCommon (source) {
165165
166- val in : Scanner = new Scanner (source, profile = Profile .current, allowRewrite = allowRewrite )
166+ val in : Scanner = createScanner( )
167167 // in.debugTokenStream = true // uncomment to see the token stream of the standard scanner, but not syntax highlighting
168168
169+ def createScanner () =
170+ new Scanner (source, profile = Profile .current, allowRewrite = allowRewrite)
171+
169172 /** This is the general parse entry point.
170173 */
171174 def parse (): Tree = {
@@ -4063,19 +4066,17 @@ object Parsers:
40634066 }
40644067
40654068 /** The Scala parser that can rewrite to indent */
4066- class ToIndentParser (source : SourceFile )(using Context ) extends Parser (source):
4067- class ToIndentScanner (source : SourceFile )(using Context ) extends Scanner (source):
4068- /** A copy of the previous token */
4069- var prev : TokenData = Scanners .newTokenData
4069+ private class ToIndentParser (source : SourceFile )(using Context ) extends Parser (source):
40704070
4071+ override def createScanner (): Scanner = new Scanner (source):
40714072 override def nextToken (): Unit =
40724073 if token != EMPTY then patchIndent()
40734074 prev = saveCopy
40744075 super .nextToken()
4075- end ToIndentScanner
40764076
4077- override val in : ToIndentScanner = new ToIndentScanner (source)
40784077 assert(in.rewriteToIndent)
4078+
4079+ private var prev : TokenData = Scanners .newTokenData
40794080
40804081 /** The last offset where a colon at the end of line would be required if a subsequent { ... }
40814082 * block would be converted to an indentation region. */
@@ -4120,7 +4121,7 @@ object Parsers:
41204121 * 7. last token is not a leading operator
41214122 */
41224123 private def bracesToIndented [T ](body : => T , rewriteWithColon : Boolean ): T =
4123- val prevSaved = in. prev.saveCopy
4124+ val prevSaved = prev.saveCopy
41244125 val lastOffsetSaved = in.lastOffset
41254126 val underColonSyntax = possibleColonOffset == in.lastOffset
41264127 val colonRequired = rewriteWithColon || underColonSyntax
0 commit comments