Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
goccy committed Nov 17, 2024
1 parent 666aeb3 commit 8608ab6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 4 additions & 1 deletion scanner/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ func (c *Context) addDocumentIndent(column int) {
}
// Since addBuf ignore space character, add to the buffer directly.
c.buf = append(c.buf, ' ')
c.notSpaceCharPos = len(c.buf)
}
}

Expand Down Expand Up @@ -295,7 +296,9 @@ func (c *Context) bufferedSrc() []rune {
}

// If the text ends with a space character, remove all of them.
src = []rune(strings.TrimRight(string(src), " "))
if c.hasTrimAllEndNewlineOpt() {
src = []rune(strings.TrimRight(string(src), " "))
}
if string(src) == "\n" {
// If the content consists only of a newline,
// it can be considered as the document ending without any specified value,
Expand Down
6 changes: 5 additions & 1 deletion scanner/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -639,13 +639,17 @@ func (s *Scanner) trimCommentFromDocumentOpt(text string, header rune) (string,
func (s *Scanner) scanDocument(ctx *Context, c rune) error {
ctx.addOriginBuf(c)
if ctx.isEOS() {
if s.isFirstCharAtLine && c == ' ' {
ctx.addDocumentIndent(s.column)
} else {
ctx.addBuf(c)
}
ctx.updateDocumentLineIndentColumn(s.column)
if err := ctx.validateDocumentLineIndentColumn(); err != nil {
invalidTk := token.Invalid(err.Error(), string(ctx.obuf), s.pos())
s.progressColumn(ctx, 1)
return ErrInvalidToken(invalidTk)
}
ctx.addBuf(c)
value := ctx.bufferedSrc()
ctx.addToken(token.String(string(value), string(ctx.obuf), s.pos()))
ctx.clear()
Expand Down

0 comments on commit 8608ab6

Please sign in to comment.