@@ -268,6 +268,13 @@ object Scanners {
268
268
/** The current region. This is initially an Indented region with zero indentation width. */
269
269
var currentRegion : Region = Indented (IndentWidth .Zero , Set (), EMPTY , null )
270
270
271
+ // begin
272
+ /* Initialization: read first char, then first token */
273
+ nextChar()
274
+ nextToken()
275
+ currentRegion = topLevelRegion(indentWidth(offset))
276
+ // end begin
277
+
271
278
// Get next token ------------------------------------------------------------
272
279
273
280
/** Are we directly in a multiline string interpolation expression?
@@ -438,19 +445,19 @@ object Scanners {
438
445
def indentWidth (offset : Offset ): IndentWidth =
439
446
import IndentWidth .{Run , Conc }
440
447
def recur (idx : Int , ch : Char , n : Int , k : IndentWidth => IndentWidth ): IndentWidth =
441
- if (idx < 0 ) k(Run (ch, n))
442
- else {
443
- val nextChar = buf(idx)
444
- if (nextChar == LF ) k(Run (ch, n))
445
- else if (nextChar == ' ' || nextChar == '\t ' )
446
- if (nextChar == ch)
448
+ inline def runK = k(Run (ch, n))
449
+ inline def konkat : IndentWidth => IndentWidth = if n == 0 then k else Conc (_, Run (ch, n))
450
+ if idx < 0 then runK
451
+ else
452
+ buf(idx) match
453
+ case LF => runK
454
+ case nextChar @ (' ' | '\t ' ) =>
455
+ if nextChar == ch then
447
456
recur(idx - 1 , ch, n + 1 , k)
448
- else {
449
- val k1 : IndentWidth => IndentWidth = if (n == 0 ) k else Conc (_, Run (ch, n))
450
- recur(idx - 1 , nextChar, 1 , k1)
451
- }
452
- else recur(idx - 1 , ' ' , 0 , identity)
453
- }
457
+ else
458
+ recur(idx - 1 , nextChar, 1 , konkat)
459
+ case _ =>
460
+ recur(idx - 1 , ' ' , 0 , identity)
454
461
recur(offset - 1 , ' ' , 0 , identity)
455
462
end indentWidth
456
463
@@ -1419,11 +1426,6 @@ object Scanners {
1419
1426
1420
1427
nextToken()
1421
1428
}
1422
-
1423
- /* Initialization: read first char, then first token */
1424
- nextChar()
1425
- nextToken()
1426
- currentRegion = topLevelRegion(indentWidth(offset))
1427
1429
}
1428
1430
end Scanner
1429
1431
0 commit comments