Merge pull request #51 from hashicorp/fix-comma
parser: fix syntax error on missing comma
This commit is contained in:
commit
8ec7833c13
@ -248,16 +248,22 @@ func (p *Parser) listType() (*ast.ListType, error) {
|
|||||||
Lbrack: p.tok.Pos,
|
Lbrack: p.tok.Pos,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
needComma := false
|
||||||
for {
|
for {
|
||||||
tok := p.scan()
|
tok := p.scan()
|
||||||
switch tok.Type {
|
switch tok.Type {
|
||||||
case token.NUMBER, token.FLOAT, token.STRING:
|
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()
|
node, err := p.literalType()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
l.Add(node)
|
l.Add(node)
|
||||||
|
needComma = true
|
||||||
case token.COMMA:
|
case token.COMMA:
|
||||||
// get next list item or we are at the end
|
// get next list item or we are at the end
|
||||||
// do a look-ahead for line comment
|
// do a look-ahead for line comment
|
||||||
@ -271,6 +277,8 @@ func (p *Parser) listType() (*ast.ListType, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
p.unscan()
|
p.unscan()
|
||||||
|
|
||||||
|
needComma = false
|
||||||
continue
|
continue
|
||||||
case token.BOOL:
|
case token.BOOL:
|
||||||
// TODO(arslan) should we support? not supported by HCL yet
|
// TODO(arslan) should we support? not supported by HCL yet
|
||||||
|
@ -275,6 +275,10 @@ func TestParse(t *testing.T) {
|
|||||||
"array_comment.hcl",
|
"array_comment.hcl",
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"array_comment_2.hcl",
|
||||||
|
true,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
const fixtureDir = "./test-fixtures"
|
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…
x
Reference in New Issue
Block a user