hcl/hclsyntax: Allow newline between { and "for" keyword
We were previously enabling newline-sensitivity too soon, before checking for the "for" keyword, and thus seeing the newline token instead of the for token when peeking ahead. Now we peek for the for token first and turn on newline-sensitivity only if it isn't present. This fixes another bug in turn where we would previously have parsed the for expression itself in newline-sensitive mode, which we no longer do because we delegate to the for expression parser sooner.
This commit is contained in:
parent
447c39ed03
commit
854da97291
@ -499,6 +499,14 @@ upper(
|
||||
0,
|
||||
},
|
||||
|
||||
{
|
||||
"{\n for k, v in {hello: \"world\"}:\nk => v\n}",
|
||||
nil,
|
||||
cty.ObjectVal(map[string]cty.Value{
|
||||
"hello": cty.StringVal("world"),
|
||||
}),
|
||||
0,
|
||||
},
|
||||
{
|
||||
`{for k, v in {hello: "world"}: k => v if k == "hello"}`,
|
||||
nil,
|
||||
|
@ -1090,13 +1090,13 @@ func (p *parser) parseObjectCons() (Expression, hcl.Diagnostics) {
|
||||
panic("parseObjectCons called without peeker pointing to open brace")
|
||||
}
|
||||
|
||||
p.PushIncludeNewlines(true)
|
||||
defer p.PopIncludeNewlines()
|
||||
|
||||
if forKeyword.TokenMatches(p.Peek()) {
|
||||
return p.finishParsingForExpr(open)
|
||||
}
|
||||
|
||||
p.PushIncludeNewlines(true)
|
||||
defer p.PopIncludeNewlines()
|
||||
|
||||
var close Token
|
||||
|
||||
var diags hcl.Diagnostics
|
||||
|
Loading…
Reference in New Issue
Block a user