json/parser: can parse lists of objects

This commit is contained in:
Mitchell Hashimoto 2015-11-08 16:28:18 -08:00
parent eabb04dcd5
commit 637d86c42d
2 changed files with 16 additions and 2 deletions

View File

@ -212,6 +212,13 @@ func (p *Parser) listType() (*ast.ListType, error) {
l.Add(node)
case token.COMMA:
continue
case token.LBRACE:
node, err := p.objectType()
if err != nil {
return nil, err
}
l.Add(node)
case token.BOOL:
// TODO(arslan) should we support? not supported by HCL yet
case token.LBRACK:

View File

@ -66,6 +66,10 @@ func TestListType(t *testing.T) {
`"foo": ["123", 123]`,
[]token.Type{token.STRING, token.NUMBER},
},
{
`"foo": ["123", {}]`,
[]token.Type{token.STRING, token.LBRACE},
},
}
for _, l := range literals {
@ -84,8 +88,11 @@ func TestListType(t *testing.T) {
tokens := []token.Type{}
for _, li := range list.List {
if tp, ok := li.(*ast.LiteralType); ok {
tokens = append(tokens, tp.Token.Type)
switch v := li.(type) {
case *ast.LiteralType:
tokens = append(tokens, v.Token.Type)
case *ast.ObjectType:
tokens = append(tokens, token.LBRACE)
}
}