Skip to content

Commit

Permalink
Keep prev/next reference between tokens containing comments when filt…
Browse files Browse the repository at this point in the history
…ering comment tokens
  • Loading branch information
goccy committed Oct 12, 2021
1 parent bf7fe89 commit d647cb1
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions parser/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,21 +176,23 @@ func (c *context) progress(num int) {
}

func newContext(tokens token.Tokens, mode Mode) *context {
filteredTokens := token.Tokens{}
filteredTokens := []*token.Token{}
if mode&ParseComments != 0 {
filteredTokens = tokens
} else {
for _, tk := range tokens {
if tk.Type == token.CommentType {
continue
}
filteredTokens.Add(tk)
// keep prev/next reference between tokens containing comments
// https://github.com/goccy/go-yaml/issues/254
filteredTokens = append(filteredTokens, tk)
}
}
return &context{
idx: 0,
size: len(filteredTokens),
tokens: filteredTokens,
tokens: token.Tokens(filteredTokens),
mode: mode,
path: "$",
}
Expand Down

0 comments on commit d647cb1

Please sign in to comment.