openrewrite / openrewrite/rewrite
HclParser might fail if you use `if` as property name
Open
Nobody has claimed this yet.
bug
hcl
parser
test provided
- Dominant language
- Java
- Stars
- 3.7k
- Forks
- 570
- Avg merge
- 13h 12m
- Merged PRs (30d)
- 261
Description
What version of OpenRewrite are you using?
Current main = 9e52e9987a45d3310795a9c5834783f9e8b53216
What is the smallest, simplest way to reproduce the problem?
The following test when added to HclParserTest:
@Test
void usingIf() {
rewriteRun(
hcl(
"""
resource "not_a_real_one_for_sure" deny {
if = "a"
}
"""
)
);
}
fails with:
Caused by: org.openrewrite.hcl.HclParsingException: Syntax error in file.tf at line 2:2 mismatched input 'if' expecting {'null', '}', Identifier}.
at org.openrewrite.hcl.HclParser$ForwardingErrorListener.syntaxError(HclParser.java:108)
... 26 more
Caused by: org.antlr.v4.runtime.InputMismatchException
at org.antlr.v4.runtime.DefaultErrorStrategy.recoverInline(DefaultErrorStrategy.java:485)
at org.antlr.v4.runtime.Parser.match(Parser.java:208)
at org.openrewrite.hcl.internal.grammar.HCLParser.blockExpr(HCLParser.java:1111)
... 21 more
while I think this is a valid HCL source.
Terraform doesn't seem to have a problem with it.
OSS Repro
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the reproducer in HclParserTest and trace the syntax error from HclParser.java into the generated HCLParser.java blockExpr path. Run the usingIf test against the shown HCL input; done means the valid property name parses without the reported HclParsingException.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100