@@ -145,44 +145,31 @@ func (s *Scanner) updateIndentLevel() {
145
145
}
146
146
}
147
147
148
- func (s * Scanner ) indentStateFromIndentNumDifference () IndentState {
149
- switch {
150
- case s .prevLineIndentNum < s .indentNum :
151
- return IndentStateUp
152
- case s .prevLineIndentNum == s .indentNum :
153
- return IndentStateEqual
154
- default :
155
- return IndentStateDown
156
- }
157
- }
158
-
159
148
func (s * Scanner ) updateIndentState (ctx * Context ) {
160
- s .updateIndentLevel ()
161
-
162
149
if s .lastDelimColumn > 0 {
163
150
if s .lastDelimColumn < s .column {
164
151
s .indentState = IndentStateUp
165
- } else if s .lastDelimColumn != s .column || s .prevLineIndentNum != s .indentNum {
166
- // The following case ( current position is 'd' ), some variables becomes like here
167
- // - lastDelimColumn: 1 of 'a'
168
- // - indentNumBasedIndentState: IndentStateDown because d's indentNum(1) is less than c's indentNum(3).
169
- // Therefore, s.lastDelimColumn(1) == s.column(1) is true, but we want to treat this as IndentStateDown.
170
- // So, we look also current indentState value by the above prevLineIndentNum based logic, and determines finally indentState.
171
- // ---
172
- // a:
173
- // b
174
- // c
175
- // d: e
176
- // ^
177
- s .indentState = IndentStateDown
178
152
} else {
179
- s .indentState = IndentStateEqual
153
+ // If lastDelimColumn and s.column are the same,
154
+ // treat as Down state since it is the same column as delimiter.
155
+ s .indentState = IndentStateDown
180
156
}
181
157
} else {
182
158
s .indentState = s .indentStateFromIndentNumDifference ()
183
159
}
184
160
}
185
161
162
+ func (s * Scanner ) indentStateFromIndentNumDifference () IndentState {
163
+ switch {
164
+ case s .prevLineIndentNum < s .indentNum :
165
+ return IndentStateUp
166
+ case s .prevLineIndentNum == s .indentNum :
167
+ return IndentStateEqual
168
+ default :
169
+ return IndentStateDown
170
+ }
171
+ }
172
+
186
173
func (s * Scanner ) updateIndent (ctx * Context , c rune ) {
187
174
if s .isFirstCharAtLine && s .isNewLineChar (c ) && ctx .isDocument () {
188
175
return
@@ -195,6 +182,7 @@ func (s *Scanner) updateIndent(ctx *Context, c rune) {
195
182
s .indentState = IndentStateKeep
196
183
return
197
184
}
185
+ s .updateIndentLevel ()
198
186
s .updateIndentState (ctx )
199
187
s .isFirstCharAtLine = false
200
188
}
@@ -207,10 +195,6 @@ func (s *Scanner) isChangedToIndentStateUp() bool {
207
195
return s .indentState == IndentStateUp
208
196
}
209
197
210
- func (s * Scanner ) isChangedToIndentStateEqual () bool {
211
- return s .indentState == IndentStateEqual
212
- }
213
-
214
198
func (s * Scanner ) addBufferedTokenIfExists (ctx * Context ) {
215
199
ctx .addToken (s .bufferedToken (ctx ))
216
200
}
@@ -634,23 +618,16 @@ func (s *Scanner) scan(ctx *Context) (pos int) {
634
618
pos = ctx .nextPos ()
635
619
c := ctx .currentChar ()
636
620
s .updateIndent (ctx , c )
621
+ if s .isChangedToIndentStateDown () {
622
+ s .addBufferedTokenIfExists (ctx )
623
+ }
637
624
if ctx .isDocument () {
638
- if (s .indentNum == 0 && s .isChangedToIndentStateEqual ()) ||
639
- s .isChangedToIndentStateDown () {
640
- s .addBufferedTokenIfExists (ctx )
625
+ if s .isChangedToIndentStateDown () {
641
626
s .breakLiteral (ctx )
642
627
} else {
643
628
s .scanLiteral (ctx , c )
644
629
continue
645
630
}
646
- } else if s .isChangedToIndentStateDown () {
647
- s .addBufferedTokenIfExists (ctx )
648
- } else if s .isChangedToIndentStateEqual () {
649
- // if first character is new line character, buffer expect to raw folded literal
650
- if len (ctx .obuf ) > 0 && s .newLineCount (ctx .obuf ) <= 1 {
651
- // doesn't raw folded literal
652
- s .addBufferedTokenIfExists (ctx )
653
- }
654
631
}
655
632
switch c {
656
633
case '{' :
0 commit comments