Skip to content
This repository has been archived by the owner on Oct 3, 2019. It is now read-only.

Commit

Permalink
hcl/hclsyntax: Allow newline between { and "for" keyword
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
apparentlymart committed Dec 12, 2018
1 parent 447c39e commit 854da97
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
8 changes: 8 additions & 0 deletions hcl/hclsyntax/expression_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions hcl/hclsyntax/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 854da97

Please sign in to comment.