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)
|
l.Add(node)
|
||||||
case token.COMMA:
|
case token.COMMA:
|
||||||
continue
|
continue
|
||||||
|
case token.LBRACE:
|
||||||
|
node, err := p.objectType()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
l.Add(node)
|
||||||
case token.BOOL:
|
case token.BOOL:
|
||||||
// TODO(arslan) should we support? not supported by HCL yet
|
// TODO(arslan) should we support? not supported by HCL yet
|
||||||
case token.LBRACK:
|
case token.LBRACK:
|
||||||
|
@ -66,6 +66,10 @@ func TestListType(t *testing.T) {
|
|||||||
`"foo": ["123", 123]`,
|
`"foo": ["123", 123]`,
|
||||||
[]token.Type{token.STRING, token.NUMBER},
|
[]token.Type{token.STRING, token.NUMBER},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
`"foo": ["123", {}]`,
|
||||||
|
[]token.Type{token.STRING, token.LBRACE},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, l := range literals {
|
for _, l := range literals {
|
||||||
@ -84,8 +88,11 @@ func TestListType(t *testing.T) {
|
|||||||
|
|
||||||
tokens := []token.Type{}
|
tokens := []token.Type{}
|
||||||
for _, li := range list.List {
|
for _, li := range list.List {
|
||||||
if tp, ok := li.(*ast.LiteralType); ok {
|
switch v := li.(type) {
|
||||||
tokens = append(tokens, tp.Token.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