diff --git a/lexer.go b/lexer.go index b70ff74..2593466 100644 --- a/lexer.go +++ b/lexer.go @@ -175,6 +175,10 @@ func lexVoid(l *lexer) stateFn { l.ignore() } + if l.depth > 0 { + return lexRvalue + } + if l.next() == eof { break } diff --git a/lexer_test.go b/lexer_test.go index 9a98689..e5846bd 100644 --- a/lexer_test.go +++ b/lexer_test.go @@ -207,6 +207,22 @@ func TestArrayInts(t *testing.T) { }) } +func TestMultilineArrayComments(t *testing.T) { + testFlow(t, "a = [1, # wow\n2, # such items\n3, # so array\n]", []token{ + token{tokenKey, "a"}, + token{tokenEqual, "="}, + token{tokenLeftBracket, "["}, + token{tokenInteger, "1"}, + token{tokenComma, ","}, + token{tokenInteger, "2"}, + token{tokenComma, ","}, + token{tokenInteger, "3"}, + token{tokenComma, ","}, + token{tokenRightBracket, "]"}, + token{tokenEOF, ""}, + }) +} + func TestKeyEqualArrayBools(t *testing.T) { testFlow(t, "foo = [true, false, true]", []token{ token{tokenKey, "foo"}, diff --git a/parser_test.go b/parser_test.go index 7f7888e..629e0a6 100644 --- a/parser_test.go +++ b/parser_test.go @@ -170,6 +170,20 @@ func TestNewlinesInArrays(t *testing.T) { }) } +func TestArrayWithExtraComma(t *testing.T) { + tree, err := Load("a = [1,\n2,\n3,\n]") + assertTree(t, tree, err, map[string]interface{}{ + "a": []int64{int64(1), int64(2), int64(3)}, + }) +} + +func TestArrayWithExtraCommaComment(t *testing.T) { + tree, err := Load("a = [1, # wow\n2, # such items\n3, # so array\n]") + assertTree(t, tree, err, map[string]interface{}{ + "a": []int64{int64(1), int64(2), int64(3)}, + }) +} + func TestMissingFile(t *testing.T) { _, err := LoadFile("foo.toml") if err.Error() != "open foo.toml: no such file or directory" {