parser: fix syntax error on missing comma
Fixes hashicorp/terraform#3877
This commit is contained in:
parent
fa160f1206
commit
99ce7c7e2c
@ -248,16 +248,22 @@ func (p *Parser) listType() (*ast.ListType, error) {
|
||||
Lbrack: p.tok.Pos,
|
||||
}
|
||||
|
||||
needComma := false
|
||||
for {
|
||||
tok := p.scan()
|
||||
switch tok.Type {
|
||||
case token.NUMBER, token.FLOAT, token.STRING:
|
||||
if needComma {
|
||||
return nil, fmt.Errorf("unexpected token: %s. Expecting %s", tok.Type, token.COMMA)
|
||||
}
|
||||
|
||||
node, err := p.literalType()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
l.Add(node)
|
||||
needComma = true
|
||||
case token.COMMA:
|
||||
// get next list item or we are at the end
|
||||
// do a look-ahead for line comment
|
||||
@ -271,6 +277,8 @@ func (p *Parser) listType() (*ast.ListType, error) {
|
||||
}
|
||||
}
|
||||
p.unscan()
|
||||
|
||||
needComma = false
|
||||
continue
|
||||
case token.BOOL:
|
||||
// TODO(arslan) should we support? not supported by HCL yet
|
||||
|
@ -275,6 +275,10 @@ func TestParse(t *testing.T) {
|
||||
"array_comment.hcl",
|
||||
false,
|
||||
},
|
||||
{
|
||||
"array_comment_2.hcl",
|
||||
true,
|
||||
},
|
||||
}
|
||||
|
||||
const fixtureDir = "./test-fixtures"
|
||||
|
6
hcl/parser/test-fixtures/array_comment_2.hcl
Normal file
6
hcl/parser/test-fixtures/array_comment_2.hcl
Normal file
@ -0,0 +1,6 @@
|
||||
provisioner "remote-exec" {
|
||||
scripts = [
|
||||
"${path.module}/scripts/install-consul.sh" // missing comma
|
||||
"${path.module}/scripts/install-haproxy.sh"
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue
Block a user