9
9
# format that can be fed directly into [Jison](https://github.com/zaach/jison). These
10
10
# are read by jison in the `parser.lexer` function defined in coffeescript.coffee.
11
11
12
- {Rewriter , INVERSES } = require ' ./rewriter'
12
+ {Rewriter , INVERSES , UNFINISHED } = require ' ./rewriter'
13
13
14
14
# Import the helpers we need.
15
15
{count, starts, compact, repeat, invertLiterate, merge,
@@ -38,7 +38,7 @@ exports.Lexer = class Lexer
38
38
@literate = opts .literate # Are we lexing literate CoffeeScript?
39
39
@indent = 0 # The current indentation level.
40
40
@baseIndent = 0 # The overall minimum indentation level.
41
- @indebt = 0 # The over-indentation at the current level.
41
+ @continuationLineAdditionalIndent = 0 # The over-indentation at the current level.
42
42
@outdebt = 0 # The under-outdentation at the current level.
43
43
@indents = [] # The stack of all current indentation levels.
44
44
@indentLiteral = ' ' # The indentation.
@@ -531,13 +531,15 @@ exports.Lexer = class Lexer
531
531
@ error ' indentation mismatch' , offset : indent .length
532
532
return indent .length
533
533
534
- if size - @indebt is @indent
534
+ if size - @continuationLineAdditionalIndent is @indent
535
535
if noNewlines then @ suppressNewlines () else @ newlineToken offset
536
536
return indent .length
537
537
538
538
if size > @indent
539
539
if noNewlines
540
- @indebt = size - @indent unless backslash
540
+ @continuationLineAdditionalIndent = size - @indent unless backslash
541
+ if @continuationLineAdditionalIndent
542
+ prev .continuationLineIndent = @indent + @continuationLineAdditionalIndent
541
543
@ suppressNewlines ()
542
544
return indent .length
543
545
unless @tokens .length
@@ -548,19 +550,20 @@ exports.Lexer = class Lexer
548
550
@ token ' INDENT' , diff, offset : offset + indent .length - size, length : size
549
551
@indents .push diff
550
552
@ends .push {tag : ' OUTDENT' }
551
- @outdebt = @indebt = 0
553
+ @outdebt = @continuationLineAdditionalIndent = 0
552
554
@indent = size
553
555
@indentLiteral = newIndentLiteral
554
556
else if size < @baseIndent
555
557
@ error ' missing indentation' , offset : offset + indent .length
556
558
else
557
- @indebt = 0
558
- @ outdentToken {moveOut : @indent - size, noNewlines, outdentLength : indent .length , offset, indentSize : size}
559
+ endsContinuationLineIndentation = @continuationLineAdditionalIndent > 0
560
+ @continuationLineAdditionalIndent = 0
561
+ @ outdentToken {moveOut : @indent - size, noNewlines, outdentLength : indent .length , offset, indentSize : size, endsContinuationLineIndentation}
559
562
indent .length
560
563
561
564
# Record an outdent token or multiple tokens, if we happen to be moving back
562
565
# inwards past several recorded indents. Sets new @indent value.
563
- outdentToken : ({moveOut, noNewlines, outdentLength = 0 , offset = 0 , indentSize}) ->
566
+ outdentToken : ({moveOut, noNewlines, outdentLength = 0 , offset = 0 , indentSize, endsContinuationLineIndentation }) ->
564
567
decreasedIndent = @indent - moveOut
565
568
while moveOut > 0
566
569
lastIndent = @indents [@indents .length - 1 ]
@@ -582,7 +585,9 @@ exports.Lexer = class Lexer
582
585
@outdebt -= moveOut if dent
583
586
@ suppressSemicolons ()
584
587
585
- @ token ' TERMINATOR' , ' \n ' , offset : offset + outdentLength, length : 0 unless @ tag () is ' TERMINATOR' or noNewlines
588
+ unless @ tag () is ' TERMINATOR' or noNewlines
589
+ terminatorToken = @ token ' TERMINATOR' , ' \n ' , offset : offset + outdentLength, length : 0
590
+ terminatorToken .endsContinuationLineIndentation = {preContinuationLineIndent : @indent } if endsContinuationLineIndentation
586
591
@indent = decreasedIndent
587
592
@indentLiteral = @indentLiteral [... decreasedIndent]
588
593
this
@@ -1463,8 +1468,3 @@ LINE_BREAK = ['INDENT', 'OUTDENT', 'TERMINATOR']
1463
1468
1464
1469
# Additional indent in front of these is ignored.
1465
1470
INDENTABLE_CLOSERS = [')', '}', '] ']
1466
-
1467
- # Tokens that, when appearing at the end of a line, suppress a following TERMINATOR/INDENT token
1468
- UNFINISHED = ['\\ ', '. ', '?. ', '?::', 'UNARY', 'DO', 'DO_IIFE', 'MATH', 'UNARY_MATH', '+', '-' ,
1469
- '**', 'SHIFT', 'RELATION', 'COMPARE', '&', '^', '|', '&&', '||',
1470
- 'BIN?', 'EXTENDS']
0 commit comments