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.
|
// 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),
|
||||||
}
|
}
|
||||||
|
@ -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"
|
||||||
|
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…
x
Reference in New Issue
Block a user