parser: fix syntax error on missing comma

Fixes hashicorp/terraform#3877
This commit is contained in:
Fatih Arslan 2015-11-12 15:26:23 +02:00
parent fa160f1206
commit 99ce7c7e2c
3 changed files with 18 additions and 0 deletions

View File

@ -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

View File

@ -275,6 +275,10 @@ func TestParse(t *testing.T) {
"array_comment.hcl",
false,
},
{
"array_comment_2.hcl",
true,
},
}
const fixtureDir = "./test-fixtures"

View File

@ -0,0 +1,6 @@
provisioner "remote-exec" {
scripts = [
"${path.module}/scripts/install-consul.sh" // missing comma
"${path.module}/scripts/install-haproxy.sh"
]
}