@@ -28,6 +28,8 @@ object Scanners {
28
28
29
29
type Token = Int
30
30
31
+ private val identity : IndentWidth => IndentWidth = Predef .identity
32
+
31
33
trait TokenData {
32
34
33
35
/** the next token */
@@ -392,25 +394,24 @@ object Scanners {
392
394
}
393
395
)
394
396
395
- /** The indentation width of the given offset.
396
- * It is assumed that only blank characters are between the start of the line and the offset.
397
- */
397
+ /** The indentation width of the given offset */
398
398
def indentWidth (offset : Offset ): IndentWidth = {
399
399
import IndentWidth .{Run , Conc }
400
- def recur (idx : Int , ch : Char , n : Int ): IndentWidth =
401
- if (idx < 0 ) Run (ch, n)
400
+ def recur (idx : Int , ch : Char , n : Int , k : IndentWidth => IndentWidth ): IndentWidth =
401
+ if (idx < 0 ) k( Run (ch, n) )
402
402
else {
403
403
val nextChar = buf(idx)
404
- if (nextChar == ' ' || nextChar == '\t ' )
404
+ if (nextChar == LF ) k(Run (ch, n))
405
+ else if (nextChar == ' ' || nextChar == '\t ' )
405
406
if (nextChar == ch)
406
- recur(idx - 1 , ch, n + 1 )
407
+ recur(idx - 1 , ch, n + 1 , k )
407
408
else {
408
- val prefix = recur(idx - 1 , nextChar, 1 )
409
- if (n == 0 ) prefix else Conc (prefix, Run (ch, n) )
409
+ val k1 : IndentWidth => IndentWidth = if (n == 0 ) k else Conc (_, Run (ch, n) )
410
+ recur(idx - 1 , nextChar, 1 , k1 )
410
411
}
411
- else Run (ch, n )
412
+ else recur(idx - 1 , ' ' , 0 , identity )
412
413
}
413
- recur(offset - 1 , ' ' , 0 )
414
+ recur(offset - 1 , ' ' , 0 , identity )
414
415
}
415
416
416
417
/** Handle newlines, possibly inserting an INDENT, OUTDENT, NEWLINE, or NEWLINES token
@@ -1286,6 +1287,7 @@ object Scanners {
1286
1287
/* Initialization: read first char, then first token */
1287
1288
nextChar()
1288
1289
nextToken()
1290
+ currentRegion = Indented (indentWidth(offset), Set (), EMPTY , null )
1289
1291
}
1290
1292
// end Scanner
1291
1293
0 commit comments