@@ -28,6 +28,8 @@ object Scanners {
2828
2929 type Token = Int
3030
31+ private val identity : IndentWidth => IndentWidth = Predef .identity
32+
3133 trait TokenData {
3234
3335 /** the next token */
@@ -392,25 +394,24 @@ object Scanners {
392394 }
393395 )
394396
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 */
398398 def indentWidth (offset : Offset ): IndentWidth = {
399399 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) )
402402 else {
403403 val nextChar = buf(idx)
404- if (nextChar == ' ' || nextChar == '\t ' )
404+ if (nextChar == LF ) k(Run (ch, n))
405+ else if (nextChar == ' ' || nextChar == '\t ' )
405406 if (nextChar == ch)
406- recur(idx - 1 , ch, n + 1 )
407+ recur(idx - 1 , ch, n + 1 , k )
407408 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 )
410411 }
411- else Run (ch, n )
412+ else recur(idx - 1 , ' ' , 0 , identity )
412413 }
413- recur(offset - 1 , ' ' , 0 )
414+ recur(offset - 1 , ' ' , 0 , identity )
414415 }
415416
416417 /** Handle newlines, possibly inserting an INDENT, OUTDENT, NEWLINE, or NEWLINES token
@@ -1286,6 +1287,7 @@ object Scanners {
12861287 /* Initialization: read first char, then first token */
12871288 nextChar()
12881289 nextToken()
1290+ currentRegion = Indented (indentWidth(offset), Set (), EMPTY , null )
12891291 }
12901292 // end Scanner
12911293
0 commit comments