Skip to content

Conversation

@Gautam-aman
Copy link

@Gautam-aman Gautam-aman commented Dec 31, 2025

Fixes parsing failure when if is used as an attribute name in HCL.

Terraform allows keywords as attribute names, but the current grammar only accepts Identifier, causing valid HCL to fail parsing.

This change allows if in attribute position only and adds a regression test.

@timtebeek
Copy link
Member

timtebeek commented Dec 31, 2025

Thanks for looking into this @Gautam-aman ; are you sure you pushed all the changes you were after? As I'm seeing no reference that identifierLike, and a failure in running the tests.

@timtebeek timtebeek marked this pull request as draft December 31, 2025 17:40
@Gautam-aman Gautam-aman marked this pull request as ready for review December 31, 2025 18:31
@Gautam-aman
Copy link
Author

This PR is now ready for review.

The grammar and visitor changes allow if to be used as an HCL attribute key
(e.g. if = true) while preserving its role in conditional and for expressions.

Local build and tests pass:

  • :rewrite-hcl:compileJava
  • :rewrite-hcl:test

Happy to address any feedback.

Gautam-aman and others added 2 commits January 1, 2026 01:06
…/JsonPathParserVisitor.java

Co-authored-by: Tim te Beek <[email protected]>
…erVisitor.java

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@Gautam-aman
Copy link
Author

All review feedback has been addressed and the PR is ready.
Thanks for taking a look!

@Gautam-aman Gautam-aman requested a review from timtebeek January 2, 2026 17:32
@Gautam-aman
Copy link
Author

Thanks for the review and merge , appreciate it!

@timtebeek
Copy link
Member

Thanks! There's one open question that I'd like @greg-at-moderne to weigh in on; please don't resolve that comment before then:

Mostly I'm wondering if the fix here is too specific for the problem that was reported, whereas I think there might be similar cases that we'd want to tackle here as well.

@Gautam-aman
Copy link
Author

I agree it’s worth considering whether this should be generalized beyond the reported case. I’m happy to wait for @greg-at-moderne’s input and adjust the approach if needed.

Let me know how you’d like to proceed.

@greg-at-moderne greg-at-moderne self-requested a review January 7, 2026 10:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working hcl parser

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

HclParser might fail if you use if as property name

3 participants