hcl/parser: error on bare object keys in object

This commit is contained in:
Mitchell Hashimoto 2016-03-14 20:54:33 +01:00
parent 7df3f8587e
commit faa2fba9b8
3 changed files with 15 additions and 1 deletions

View File

@ -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),
}

View File

@ -311,6 +311,10 @@ func TestParse(t *testing.T) {
"key_without_value.hcl",
true,
},
{
"object_key_without_value.hcl",
true,
},
}
const fixtureDir = "./test-fixtures"

View File

@ -0,0 +1,3 @@
foo {
bar
}