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. // receive a value (but we did receive a key) for the item.
err = nil 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 { if err != nil {
return nil, err return nil, err
} }
@ -215,7 +222,7 @@ func (p *Parser) objectKey() ([]*ast.ObjectKey, error) {
case token.ILLEGAL: case token.ILLEGAL:
fmt.Println("illegal") fmt.Println("illegal")
default: default:
return nil, &PosError{ return keys, &PosError{
Pos: p.tok.Pos, Pos: p.tok.Pos,
Err: fmt.Errorf("expected: IDENT | STRING | ASSIGN | LBRACE got: %s", p.tok.Type), 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", "key_without_value.hcl",
true, true,
}, },
{
"object_key_without_value.hcl",
true,
},
} }
const fixtureDir = "./test-fixtures" const fixtureDir = "./test-fixtures"

View File

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