@@ -161,11 +161,14 @@ object Parsers:
161
161
else if (in.token == RBRACE || in.token == OUTDENT ) openBraces -= 1
162
162
in.nextToken()
163
163
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) {
165
165
166
- val in : Scanner = new Scanner (source, profile = Profile .current, allowRewrite = allowRewrite )
166
+ val in : Scanner = createScanner( )
167
167
// in.debugTokenStream = true // uncomment to see the token stream of the standard scanner, but not syntax highlighting
168
168
169
+ def createScanner () =
170
+ new Scanner (source, profile = Profile .current, allowRewrite = allowRewrite)
171
+
169
172
/** This is the general parse entry point.
170
173
*/
171
174
def parse (): Tree = {
@@ -4063,19 +4066,17 @@ object Parsers:
4063
4066
}
4064
4067
4065
4068
/** 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):
4070
4070
4071
+ override def createScanner (): Scanner = new Scanner (source):
4071
4072
override def nextToken (): Unit =
4072
4073
if token != EMPTY then patchIndent()
4073
4074
prev = saveCopy
4074
4075
super .nextToken()
4075
- end ToIndentScanner
4076
4076
4077
- override val in : ToIndentScanner = new ToIndentScanner (source)
4078
4077
assert(in.rewriteToIndent)
4078
+
4079
+ private var prev : TokenData = Scanners .newTokenData
4079
4080
4080
4081
/** The last offset where a colon at the end of line would be required if a subsequent { ... }
4081
4082
* block would be converted to an indentation region. */
@@ -4120,7 +4121,7 @@ object Parsers:
4120
4121
* 7. last token is not a leading operator
4121
4122
*/
4122
4123
private def bracesToIndented [T ](body : => T , rewriteWithColon : Boolean ): T =
4123
- val prevSaved = in. prev.saveCopy
4124
+ val prevSaved = prev.saveCopy
4124
4125
val lastOffsetSaved = in.lastOffset
4125
4126
val underColonSyntax = possibleColonOffset == in.lastOffset
4126
4127
val colonRequired = rewriteWithColon || underColonSyntax
0 commit comments