hcl/parser: error on bare object keys in object
This commit is contained in:
parent
7df3f8587e
commit
faa2fba9b8
@ -128,6 +128,13 @@ func (p *Parser) objectItem() (*ast.ObjectItem, error) {
|
||||
// receive a value (but we did receive a key) for the item.
|
||||
err = nil
|
||||
}
|
||||
if len(keys) > 0 && err != nil && p.tok.Type == token.RBRACE {
|
||||
// Object key with no value in an object
|
||||
err = nil
|
||||
|
||||
// Reset the token type so we don't think it completed fine.
|
||||
p.tok.Type = token.EOF
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -215,7 +222,7 @@ func (p *Parser) objectKey() ([]*ast.ObjectKey, error) {
|
||||
case token.ILLEGAL:
|
||||
fmt.Println("illegal")
|
||||
default:
|
||||
return nil, &PosError{
|
||||
return keys, &PosError{
|
||||
Pos: p.tok.Pos,
|
||||
Err: fmt.Errorf("expected: IDENT | STRING | ASSIGN | LBRACE got: %s", p.tok.Type),
|
||||
}
|
||||
|
@ -311,6 +311,10 @@ func TestParse(t *testing.T) {
|
||||
"key_without_value.hcl",
|
||||
true,
|
||||
},
|
||||
{
|
||||
"object_key_without_value.hcl",
|
||||
true,
|
||||
},
|
||||
}
|
||||
|
||||
const fixtureDir = "./test-fixtures"
|
||||
|
3
hcl/parser/test-fixtures/object_key_without_value.hcl
Normal file
3
hcl/parser/test-fixtures/object_key_without_value.hcl
Normal file
@ -0,0 +1,3 @@
|
||||
foo {
|
||||
bar
|
||||
}
|
Loading…
Reference in New Issue
Block a user