hcl/parser: parse list of lists

This commit is contained in:
Mitchell Hashimoto 2017-01-30 13:05:20 -08:00
parent db4f076892
commit 08c7efd78d
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
3 changed files with 21 additions and 3 deletions

View File

@ -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,

View File

@ -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

View File

@ -0,0 +1,2 @@
foo = [["foo"], ["bar"]]