hashicorp / hcl2

Former temporary home for experimental new version of HCL
https://github.com/hashicorp/hcl
Mozilla Public License 2.0
373 stars 66 forks source link

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

Closed apparentlymart closed 5 years ago

apparentlymart commented 5 years ago

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:

https://github.com/hashicorp/hcl2/blob/3e4b7e0eb20ecc20e70dbd458f7a54daf0032830/hcl/hclsyntax/parser.go#L1023-L1028

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 commented 5 years ago

This is fixed in 854da9729131f4579bf87a7f0757629a3cb90eac.