Skip to content

Commit

Permalink
hcl/parser: parse list of lists
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchellh committed Jan 30, 2017
1 parent db4f076 commit 08c7efd
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
10 changes: 10 additions & 0 deletions decoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 9 additions & 3 deletions hcl/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions test-fixtures/list_of_lists.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
foo = [["foo"], ["bar"]]

0 comments on commit 08c7efd

Please sign in to comment.