json/parser: can parse lists of objects
This commit is contained in:
parent
eabb04dcd5
commit
637d86c42d
@ -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:
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user