diff --git a/decoder_test.go b/decoder_test.go index e58165f..480be4f 100644 --- a/decoder_test.go +++ b/decoder_test.go @@ -207,6 +207,16 @@ func TestDecode_interface(t *testing.T) { }, }, }, + { + "list_of_lists.hcl", + false, + map[string]interface{}{ + "foo": []interface{}{ + []interface{}{"foo"}, + []interface{}{"bar"}, + }, + }, + }, { "list_of_maps.hcl", false, diff --git a/hcl/parser/parser.go b/hcl/parser/parser.go index 8dd73e0..6e54bed 100644 --- a/hcl/parser/parser.go +++ b/hcl/parser/parser.go @@ -389,9 +389,15 @@ func (p *Parser) listType() (*ast.ListType, error) { l.Add(node) needComma = true case token.LBRACK: - // TODO(arslan) should we support nested lists? Even though it's - // written in README of HCL, it's not a part of the grammar - // (not defined in parse.y) + node, err := p.listType() + if err != nil { + return nil, &PosError{ + Pos: tok.Pos, + Err: fmt.Errorf( + "error while trying to parse list within list: %s", err), + } + } + l.Add(node) case token.RBRACK: // finished l.Rbrack = p.tok.Pos diff --git a/test-fixtures/list_of_lists.hcl b/test-fixtures/list_of_lists.hcl new file mode 100644 index 0000000..8af3458 --- /dev/null +++ b/test-fixtures/list_of_lists.hcl @@ -0,0 +1,2 @@ +foo = [["foo"], ["bar"]] +