Skip to content

Commit

Permalink
Merge pull request #42 from jroper/fix-trailing-comma-comments
Browse files Browse the repository at this point in the history
Fixed trailing comma comments bug
  • Loading branch information
gurkankaymak authored Aug 12, 2023
2 parents 6ee0f72 + 5cb5942 commit 9ccc664
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
7 changes: 6 additions & 1 deletion parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,12 @@ func (p *parser) extractArray() (Array, error) {

token = p.scanner.TokenText()

if p.scanner.TokenText() == commaToken {
if token == commentToken {
p.consumeComment()
token = p.scanner.TokenText()
}

if token == commaToken {
return nil, adjacentCommasError(p.scanner.Line, p.scanner.Column)
}
}
Expand Down
8 changes: 8 additions & 0 deletions parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1172,6 +1172,14 @@ func TestExtractArray(t *testing.T) {
assertDeepEqual(t, got, Array{Int(1)})
})

t.Run("extract the array without an error when the trailing comma is followed by a comment", func(t *testing.T) {
parser := newParser(strings.NewReader("[1,#comment\n]"))
parser.advance()
got, err := parser.extractArray()
assertNoError(t, err)
assertDeepEqual(t, got, Array{Int(1)})
})

t.Run("extract the array without an error if if elements are separated with ASCII newline", func(t *testing.T) {
parser := newParser(strings.NewReader("[1\n2]"))
parser.advance()
Expand Down

0 comments on commit 9ccc664

Please sign in to comment.