Skip to content

Commit

Permalink
fix parsing of comment (#576)
Browse files Browse the repository at this point in the history
  • Loading branch information
goccy authored Dec 7, 2024
1 parent 831423f commit 264b167
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
31 changes: 17 additions & 14 deletions scanner/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -701,8 +701,11 @@ func (s *Scanner) scanTag(ctx *Context) bool {
}

func (s *Scanner) scanComment(ctx *Context) bool {
if ctx.existsBuffer() && (ctx.previousChar() != ' ' && ctx.previousChar() != '\t') {
return false
if ctx.existsBuffer() {
c := ctx.previousChar()
if c != ' ' && c != '\t' && !s.isNewLineChar(c) {
return false
}
}

s.addBufferedTokenIfExists(ctx)
Expand All @@ -711,19 +714,19 @@ func (s *Scanner) scanComment(ctx *Context) bool {

for idx, c := range ctx.src[ctx.idx:] {
ctx.addOriginBuf(c)
switch c {
case '\n', '\r':
if ctx.previousChar() == '\\' {
continue
}
value := ctx.source(ctx.idx, ctx.idx+idx)
progress := len([]rune(value))
ctx.addToken(token.Comment(value, string(ctx.obuf), s.pos()))
s.progressColumn(ctx, progress)
s.progressLine(ctx)
ctx.clear()
return true
if !s.isNewLineChar(c) {
continue
}
if ctx.previousChar() == '\\' {
continue
}
value := ctx.source(ctx.idx, ctx.idx+idx)
progress := len([]rune(value))
ctx.addToken(token.Comment(value, string(ctx.obuf), s.pos()))
s.progressColumn(ctx, progress)
s.progressLine(ctx)
ctx.clear()
return true
}
// document ends with comment.
value := string(ctx.src[ctx.idx:])
Expand Down
1 change: 0 additions & 1 deletion yaml_test_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ var failureTestNames = []string{
"block-mapping-with-missing-keys", // no json.
"block-scalar-with-more-spaces-than-first-content-line",
"colon-at-the-beginning-of-adjacent-flow-scalar",
"comment-in-flow-sequence-before-comma", // pass yamlv3.
"comment-without-whitespace-after-doublequoted-scalar",
"construct-binary",
"dash-in-flow-sequence",
Expand Down

0 comments on commit 264b167

Please sign in to comment.