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

for expression with keyword on newline doesn't seem to parse correctly #51

Closed
apparentlymart opened this issue Oct 15, 2018 · 1 comment

Comments

@apparentlymart
Copy link
Member

Given input like this:

foo = {
  for net in networks:
  net.foo => net.bar
}

...the parser seems to not be detecting that for keyword as a for expression introducer and instead treating it as a map key expression.

It seems like the peek-ahead for that keyword isn't working correctly with the intervening newline, even though we turn off newline-sensitive tokenization before peeking it:

hcl2/hcl/hclsyntax/parser.go

Lines 1023 to 1028 in 3e4b7e0

p.PushIncludeNewlines(false)
defer p.PopIncludeNewlines()
if forKeyword.TokenMatches(p.Peek()) {
return p.finishParsingForExpr(open)
}

Perhaps somehow the newline token is ending up in the peek slot before PushIncludeNewlines(false) takes effect, and so it's still there when we subsequently call Peek. Will need to dig into the parser code some more to see what's going on here.

@apparentlymart
Copy link
Member Author

This is fixed in 854da97.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant