Skip to content

Commit

Permalink
hcl/parser: support bools in lists
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchellh committed Jan 20, 2017
1 parent eb6f65b commit e59762b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
17 changes: 17 additions & 0 deletions decoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,23 @@ func TestDecode_interface(t *testing.T) {
true,
nil,
},

{
"object_with_bool.hcl",
false,
map[string]interface{}{
"path": []map[string]interface{}{
map[string]interface{}{
"policy": "write",
"permissions": []map[string]interface{}{
map[string]interface{}{
"bool": []interface{}{false},
},
},
},
},
},
},
}

for _, tc := range cases {
Expand Down
4 changes: 1 addition & 3 deletions hcl/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ func (p *Parser) listType() (*ast.ListType, error) {
}
}
switch tok.Type {
case token.NUMBER, token.FLOAT, token.STRING, token.HEREDOC:
case token.BOOL, token.NUMBER, token.FLOAT, token.STRING, token.HEREDOC:
node, err := p.literalType()
if err != nil {
return nil, err
Expand Down Expand Up @@ -388,8 +388,6 @@ func (p *Parser) listType() (*ast.ListType, error) {
}
l.Add(node)
needComma = true
case token.BOOL:
// TODO(arslan) should we support? not supported by HCL yet
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
Expand Down
4 changes: 4 additions & 0 deletions hcl/parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ func TestListType(t *testing.T) {
`foo = [123, "123",]`,
[]token.Type{token.NUMBER, token.STRING},
},
{
`foo = [false]`,
[]token.Type{token.BOOL},
},
{
`foo = []`,
[]token.Type{},
Expand Down
6 changes: 6 additions & 0 deletions test-fixtures/object_with_bool.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
path {
policy = "write"
permissions = {
"bool" = [false]
}
}

0 comments on commit e59762b

Please sign in to comment.