@@ -7,13 +7,24 @@ import com.intellij.lexer.LookAheadLexer
77
88class ToonLexerAdapter : LookAheadLexer (FlexAdapter (ToonLexer (null))) {
99 private val indentStack = mutableListOf (0 )
10+ private var start = false
1011
1112 override fun lookAhead (baseLexer : Lexer ) {
1213 val tokenType = baseLexer.tokenType
1314
15+ println (" tokenType: $tokenType " )
1416 if (tokenType == null ) {
15- addToken(ToonTypes .DEDENT )
16- super .lookAhead(baseLexer)
17+ if (! start) {
18+ start = true
19+ super .lookAhead(baseLexer)
20+ return
21+ }
22+ val endOffset = baseLexer.tokenEnd
23+ println (" compensation last: ${indentStack.size} , position: $endOffset " )
24+ while (indentStack.size > 1 ) {
25+ indentStack.removeLast()
26+ addToken(endOffset, ToonTypes .DEDENT )
27+ }
1728 return
1829 }
1930
@@ -42,6 +53,7 @@ class ToonLexerAdapter : LookAheadLexer(FlexAdapter(ToonLexer(null))) {
4253 columns++
4354 index++
4455 }
56+
4557 ' \r ' , ' \n ' -> return
4658 else -> break
4759 }
@@ -57,11 +69,13 @@ class ToonLexerAdapter : LookAheadLexer(FlexAdapter(ToonLexer(null))) {
5769 when {
5870 newIndent > currentIndent -> {
5971 indentStack.add(newIndent)
60- addToken(ToonTypes .INDENT )
72+ addToken(logicalLineStart, ToonTypes .INDENT )
6173 }
74+
6275 newIndent < currentIndent -> {
76+ println (" compensation in process: ${indentStack.size} , position: $logicalLineStart " )
6377 while (indentStack.size > 1 && newIndent < indentStack.last()) {
64- indentStack.removeAt(indentStack.size - 1 )
78+ indentStack.removeLast( )
6579 addToken(logicalLineStart, ToonTypes .DEDENT )
6680 }
6781 }
0 commit comments