Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@kbrockhoff
Copy link
Contributor

What's changed?

Added escaped backslash "\" to HCL grammar and reran Antlr generator.

What's your motivation?

HCL parsing fails in the edge case where an escaped backslash is the last value in a string.

Any additional context

This situation can arise when configuring AWS SecretsManager password rotation Lambdas.

Checklist

  • I've added unit tests to cover both positive and negative cases
  • I've read and applied the recipe conventions and best practices
  • I've used the IntelliJ IDEA auto-formatter on affected files

@github-project-automation github-project-automation bot moved this from In Progress to Ready to Review in OpenRewrite Oct 10, 2025
@jkschneider jkschneider merged commit 9242ddc into openrewrite:main Oct 10, 2025
2 checks passed
@github-project-automation github-project-automation bot moved this from Ready to Review to Done in OpenRewrite Oct 10, 2025
@jkschneider jkschneider changed the title Add support to HCL grammer for escaped backslash Add support to HCL grammar for escaped backslash Oct 10, 2025
Comment on lines +19 to +24
import org.antlr.v4.runtime.Lexer;
import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.TokenStream;
import org.antlr.v4.runtime.*;
import org.antlr.v4.runtime.atn.ATN;
import org.antlr.v4.runtime.atn.ATNDeserializer;
import org.antlr.v4.runtime.atn.LexerATNSimulator;
import org.antlr.v4.runtime.atn.PredictionContextCache;
import org.antlr.v4.runtime.atn.*;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import org.antlr.v4.runtime.Lexer;
import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.TokenStream;
import org.antlr.v4.runtime.*;
import org.antlr.v4.runtime.atn.ATN;
import org.antlr.v4.runtime.atn.ATNDeserializer;
import org.antlr.v4.runtime.atn.LexerATNSimulator;
import org.antlr.v4.runtime.atn.PredictionContextCache;
import org.antlr.v4.runtime.atn.*;
import org.antlr.v4.runtime.atn.ATN;
import org.antlr.v4.runtime.atn.ATNDeserializer;
import org.antlr.v4.runtime.atn.LexerATNSimulator;
import org.antlr.v4.runtime.atn.PredictionContextCache;

Comment on lines +36 to +42
FOR_BRACE=1, FOR_BRACK=2, IF=3, IN=4, BooleanLiteral=5, NULL=6, LBRACE=7,
RBRACE=8, ASSIGN=9, Identifier=10, WS=11, COMMENT=12, LINE_COMMENT=13,
NEWLINE=14, NumericLiteral=15, QUOTE=16, HEREDOC_START=17, PLUS=18, AND=19,
EQ=20, LT=21, COLON=22, LBRACK=23, LPAREN=24, MINUS=25, OR=26, NEQ=27,
GT=28, QUESTION=29, RBRACK=30, RPAREN=31, MUL=32, NOT=33, LEQ=34, DOT=35,
DIV=36, GEQ=37, ARROW=38, COMMA=39, MOD=40, ELLIPSIS=41, TILDE=42, TEMPLATE_INTERPOLATION_START=43,
TemplateStringLiteral=44, TemplateStringLiteralChar=45, HP_WS=46, HP_COMMENT=47,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
FOR_BRACE=1, FOR_BRACK=2, IF=3, IN=4, BooleanLiteral=5, NULL=6, LBRACE=7,
RBRACE=8, ASSIGN=9, Identifier=10, WS=11, COMMENT=12, LINE_COMMENT=13,
NEWLINE=14, NumericLiteral=15, QUOTE=16, HEREDOC_START=17, PLUS=18, AND=19,
EQ=20, LT=21, COLON=22, LBRACK=23, LPAREN=24, MINUS=25, OR=26, NEQ=27,
GT=28, QUESTION=29, RBRACK=30, RPAREN=31, MUL=32, NOT=33, LEQ=34, DOT=35,
DIV=36, GEQ=37, ARROW=38, COMMA=39, MOD=40, ELLIPSIS=41, TILDE=42, TEMPLATE_INTERPOLATION_START=43,
TemplateStringLiteral=44, TemplateStringLiteralChar=45, HP_WS=46, HP_COMMENT=47,
FOR_BRACE=1, FOR_BRACK=2, IF=3, IN=4, BooleanLiteral=5, NULL=6, LBRACE=7,
RBRACE=8, ASSIGN=9, Identifier=10, WS=11, COMMENT=12, LINE_COMMENT=13,
NEWLINE=14, NumericLiteral=15, QUOTE=16, HEREDOC_START=17, PLUS=18, AND=19,
EQ=20, LT=21, COLON=22, LBRACK=23, LPAREN=24, MINUS=25, OR=26, NEQ=27,
GT=28, QUESTION=29, RBRACK=30, RPAREN=31, MUL=32, NOT=33, LEQ=34, DOT=35,
DIV=36, GEQ=37, ARROW=38, COMMA=39, MOD=40, ELLIPSIS=41, TILDE=42, TEMPLATE_INTERPOLATION_START=43,
TemplateStringLiteral=44, TemplateStringLiteralChar=45, HP_WS=46, HP_COMMENT=47,

Comment on lines +56 to +64
"FOR_BRACE", "FOR_BRACK", "IF", "IN", "BooleanLiteral", "NULL", "LBRACE",
"RBRACE", "ASSIGN", "StringLiteralChar", "Identifier", "WS", "COMMENT",
"LINE_COMMENT", "NEWLINE", "LetterOrDigit", "Letter", "EscapeSequence",
"HexDigit", "NumericLiteral", "ExponentPart", "QUOTE", "HEREDOC_START",
"PLUS", "AND", "EQ", "LT", "COLON", "LBRACK", "LPAREN", "MINUS", "OR",
"NEQ", "GT", "QUESTION", "RBRACK", "RPAREN", "MUL", "NOT", "LEQ", "DOT",
"DIV", "GEQ", "ARROW", "COMMA", "MOD", "ELLIPSIS", "TILDE", "TEMPLATE_INTERPOLATION_START",
"TemplateStringLiteral", "TemplateStringLiteralChar", "END_QUOTE", "HP_NEWLINE",
"HP_WS", "HP_COMMENT", "HP_LINE_COMMENT", "HPIdentifier", "H_NEWLINE",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"FOR_BRACE", "FOR_BRACK", "IF", "IN", "BooleanLiteral", "NULL", "LBRACE",
"RBRACE", "ASSIGN", "StringLiteralChar", "Identifier", "WS", "COMMENT",
"LINE_COMMENT", "NEWLINE", "LetterOrDigit", "Letter", "EscapeSequence",
"HexDigit", "NumericLiteral", "ExponentPart", "QUOTE", "HEREDOC_START",
"PLUS", "AND", "EQ", "LT", "COLON", "LBRACK", "LPAREN", "MINUS", "OR",
"NEQ", "GT", "QUESTION", "RBRACK", "RPAREN", "MUL", "NOT", "LEQ", "DOT",
"DIV", "GEQ", "ARROW", "COMMA", "MOD", "ELLIPSIS", "TILDE", "TEMPLATE_INTERPOLATION_START",
"TemplateStringLiteral", "TemplateStringLiteralChar", "END_QUOTE", "HP_NEWLINE",
"HP_WS", "HP_COMMENT", "HP_LINE_COMMENT", "HPIdentifier", "H_NEWLINE",
"FOR_BRACE", "FOR_BRACK", "IF", "IN", "BooleanLiteral", "NULL", "LBRACE",
"RBRACE", "ASSIGN", "StringLiteralChar", "Identifier", "WS", "COMMENT",
"LINE_COMMENT", "NEWLINE", "LetterOrDigit", "Letter", "EscapeSequence",
"HexDigit", "NumericLiteral", "ExponentPart", "QUOTE", "HEREDOC_START",
"PLUS", "AND", "EQ", "LT", "COLON", "LBRACK", "LPAREN", "MINUS", "OR",
"NEQ", "GT", "QUESTION", "RBRACK", "RPAREN", "MUL", "NOT", "LEQ", "DOT",
"DIV", "GEQ", "ARROW", "COMMA", "MOD", "ELLIPSIS", "TILDE", "TEMPLATE_INTERPOLATION_START",
"TemplateStringLiteral", "TemplateStringLiteralChar", "END_QUOTE", "HP_NEWLINE",
"HP_WS", "HP_COMMENT", "HP_LINE_COMMENT", "HPIdentifier", "H_NEWLINE",

Comment on lines +72 to +82
null, null, null, "'if'", "'in'", null, "'null'", "'{'", "'}'", "'='",
null, null, null, null, null, null, null, null, "'+'", "'&&'", "'=='",
"'<'", "':'", "'['", "'('", "'-'", "'||'", "'!='", "'>'", "'?'", "']'",
"')'", "'*'", "'!'", "'<='", "'.'", "'/'", "'>='", "'=>'", "','", "'%'",
"'...'", "'~'"
};
}
private static final String[] _LITERAL_NAMES = makeLiteralNames();
private static String[] makeSymbolicNames() {
return new String[] {
null, "FOR_BRACE", "FOR_BRACK", "IF", "IN", "BooleanLiteral", "NULL",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
null, null, null, "'if'", "'in'", null, "'null'", "'{'", "'}'", "'='",
null, null, null, null, null, null, null, null, "'+'", "'&&'", "'=='",
"'<'", "':'", "'['", "'('", "'-'", "'||'", "'!='", "'>'", "'?'", "']'",
"')'", "'*'", "'!'", "'<='", "'.'", "'/'", "'>='", "'=>'", "','", "'%'",
"'...'", "'~'"
};
}
private static final String[] _LITERAL_NAMES = makeLiteralNames();
private static String[] makeSymbolicNames() {
return new String[] {
null, "FOR_BRACE", "FOR_BRACK", "IF", "IN", "BooleanLiteral", "NULL",
null, null, null, "'if'", "'in'", null, "'null'", "'{'", "'}'", "'='",
null, null, null, null, null, null, null, null, "'+'", "'&&'", "'=='",
"'<'", "':'", "'['", "'('", "'-'", "'||'", "'!='", "'>'", "'?'", "']'",
"')'", "'*'", "'!'", "'<='", "'.'", "'/'", "'>='", "'=>'", "','", "'%'",
null, "FOR_BRACE", "FOR_BRACK", "IF", "IN", "BooleanLiteral", "NULL",
"LBRACE", "RBRACE", "ASSIGN", "Identifier", "WS", "COMMENT", "LINE_COMMENT",
"NEWLINE", "NumericLiteral", "QUOTE", "HEREDOC_START", "PLUS", "AND",
"EQ", "LT", "COLON", "LBRACK", "LPAREN", "MINUS", "OR", "NEQ", "GT",
"QUESTION", "RBRACK", "RPAREN", "MUL", "NOT", "LEQ", "DOT", "DIV", "GEQ",
"ARROW", "COMMA", "MOD", "ELLIPSIS", "TILDE", "TEMPLATE_INTERPOLATION_START",
"TemplateStringLiteral", "TemplateStringLiteralChar", "HP_WS", "HP_COMMENT",

Comment on lines +132 to +133
private Stack<CurlyType> leftCurlyStack = new Stack<CurlyType>();
private Stack<String> heredocIdentifier = new Stack<String>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private Stack<CurlyType> leftCurlyStack = new Stack<CurlyType>();
private Stack<String> heredocIdentifier = new Stack<String>();
private Stack<CurlyType> leftCurlyStack = new Stack<>();
private Stack<String> heredocIdentifier = new Stack<>();

Comment on lines +18 to +23
import org.antlr.v4.runtime.Lexer;
import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.TokenStream;
import org.antlr.v4.runtime.*;
import org.antlr.v4.runtime.atn.ATN;
import org.antlr.v4.runtime.atn.ATNDeserializer;
import org.antlr.v4.runtime.atn.LexerATNSimulator;
import org.antlr.v4.runtime.atn.PredictionContextCache;
import org.antlr.v4.runtime.atn.*;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import org.antlr.v4.runtime.Lexer;
import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.TokenStream;
import org.antlr.v4.runtime.*;
import org.antlr.v4.runtime.atn.ATN;
import org.antlr.v4.runtime.atn.ATNDeserializer;
import org.antlr.v4.runtime.atn.LexerATNSimulator;
import org.antlr.v4.runtime.atn.PredictionContextCache;
import org.antlr.v4.runtime.atn.*;
import org.antlr.v4.runtime.atn.ATN;
import org.antlr.v4.runtime.atn.ATNDeserializer;
import org.antlr.v4.runtime.atn.LexerATNSimulator;
import org.antlr.v4.runtime.atn.PredictionContextCache;

Comment on lines +35 to +40
WS=1, UTF_8_BOM=2, MATCHES_REGEX_OPEN=3, LBRACE=4, RBRACE=5, LBRACK=6,
RBRACK=7, LPAREN=8, RPAREN=9, AT=10, DOT=11, DOT_DOT=12, ROOT=13, WILDCARD=14,
COLON=15, QUESTION=16, CONTAINS=17, TRUE=18, FALSE=19, NULL=20, Identifier=21,
StringLiteral=22, PositiveNumber=23, NegativeNumber=24, NumericLiteral=25,
COMMA=26, TICK=27, QUOTE=28, MATCHES=29, LOGICAL_OPERATOR=30, AND=31,
OR=32, EQUALITY_OPERATOR=33, EQ=34, NE=35, MATCHES_REGEX_CLOSE=36, S=37,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
WS=1, UTF_8_BOM=2, MATCHES_REGEX_OPEN=3, LBRACE=4, RBRACE=5, LBRACK=6,
RBRACK=7, LPAREN=8, RPAREN=9, AT=10, DOT=11, DOT_DOT=12, ROOT=13, WILDCARD=14,
COLON=15, QUESTION=16, CONTAINS=17, TRUE=18, FALSE=19, NULL=20, Identifier=21,
StringLiteral=22, PositiveNumber=23, NegativeNumber=24, NumericLiteral=25,
COMMA=26, TICK=27, QUOTE=28, MATCHES=29, LOGICAL_OPERATOR=30, AND=31,
OR=32, EQUALITY_OPERATOR=33, EQ=34, NE=35, MATCHES_REGEX_CLOSE=36, S=37,
WS=1, UTF_8_BOM=2, MATCHES_REGEX_OPEN=3, LBRACE=4, RBRACE=5, LBRACK=6,
RBRACK=7, LPAREN=8, RPAREN=9, AT=10, DOT=11, DOT_DOT=12, ROOT=13, WILDCARD=14,
COLON=15, QUESTION=16, CONTAINS=17, TRUE=18, FALSE=19, NULL=20, Identifier=21,
StringLiteral=22, PositiveNumber=23, NegativeNumber=24, NumericLiteral=25,
COMMA=26, TICK=27, QUOTE=28, MATCHES=29, LOGICAL_OPERATOR=30, AND=31,
OR=32, EQUALITY_OPERATOR=33, EQ=34, NE=35, MATCHES_REGEX_CLOSE=36, S=37,

Comment on lines +54 to +60
"WS", "UTF_8_BOM", "MATCHES_REGEX_OPEN", "LBRACE", "RBRACE", "LBRACK",
"RBRACK", "LPAREN", "RPAREN", "AT", "DOT", "DOT_DOT", "ROOT", "WILDCARD",
"COLON", "QUESTION", "CONTAINS", "TRUE", "FALSE", "NULL", "Identifier",
"StringLiteral", "PositiveNumber", "NegativeNumber", "NumericLiteral",
"COMMA", "TICK", "QUOTE", "MATCHES", "LOGICAL_OPERATOR", "AND", "OR",
"EQUALITY_OPERATOR", "EQ", "NE", "ESCAPE_SEQUENCE", "UNICODE", "HEX_DIGIT",
"SAFE_CODE_POINT", "EXPONENT_PART", "MINUS", "MATCHES_REGEX_CLOSE", "S",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"WS", "UTF_8_BOM", "MATCHES_REGEX_OPEN", "LBRACE", "RBRACE", "LBRACK",
"RBRACK", "LPAREN", "RPAREN", "AT", "DOT", "DOT_DOT", "ROOT", "WILDCARD",
"COLON", "QUESTION", "CONTAINS", "TRUE", "FALSE", "NULL", "Identifier",
"StringLiteral", "PositiveNumber", "NegativeNumber", "NumericLiteral",
"COMMA", "TICK", "QUOTE", "MATCHES", "LOGICAL_OPERATOR", "AND", "OR",
"EQUALITY_OPERATOR", "EQ", "NE", "ESCAPE_SEQUENCE", "UNICODE", "HEX_DIGIT",
"SAFE_CODE_POINT", "EXPONENT_PART", "MINUS", "MATCHES_REGEX_CLOSE", "S",
"WS", "UTF_8_BOM", "MATCHES_REGEX_OPEN", "LBRACE", "RBRACE", "LBRACK",
"RBRACK", "LPAREN", "RPAREN", "AT", "DOT", "DOT_DOT", "ROOT", "WILDCARD",
"COLON", "QUESTION", "CONTAINS", "TRUE", "FALSE", "NULL", "Identifier",
"StringLiteral", "PositiveNumber", "NegativeNumber", "NumericLiteral",
"COMMA", "TICK", "QUOTE", "MATCHES", "LOGICAL_OPERATOR", "AND", "OR",
"EQUALITY_OPERATOR", "EQ", "NE", "ESCAPE_SEQUENCE", "UNICODE", "HEX_DIGIT",
"SAFE_CODE_POINT", "EXPONENT_PART", "MINUS", "MATCHES_REGEX_CLOSE", "S",

Comment on lines +68 to +75
null, null, "'\\uFEFF'", null, "'{'", "'}'", "'['", "']'", "'('", "')'",
"'@'", "'.'", "'..'", "'$'", "'*'", "':'", "'?'", "'contains'", "'true'",
"'false'", "'null'", null, null, null, null, null, "','", "'''", "'\"'",
"'=~'", null, "'&&'", "'||'", null, "'=='", "'!='"
};
}
private static final String[] _LITERAL_NAMES = makeLiteralNames();
private static String[] makeSymbolicNames() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
null, null, "'\\uFEFF'", null, "'{'", "'}'", "'['", "']'", "'('", "')'",
"'@'", "'.'", "'..'", "'$'", "'*'", "':'", "'?'", "'contains'", "'true'",
"'false'", "'null'", null, null, null, null, null, "','", "'''", "'\"'",
"'=~'", null, "'&&'", "'||'", null, "'=='", "'!='"
};
}
private static final String[] _LITERAL_NAMES = makeLiteralNames();
private static String[] makeSymbolicNames() {
null, null, "'\\uFEFF'", null, "'{'", "'}'", "'['", "']'", "'('", "')'",
"'@'", "'.'", "'..'", "'$'", "'*'", "':'", "'?'", "'contains'", "'true'",
"'false'", "'null'", null, null, null, null, null, "','", "'''", "'\"'",
null, "WS", "UTF_8_BOM", "MATCHES_REGEX_OPEN", "LBRACE", "RBRACE", "LBRACK",
"RBRACK", "LPAREN", "RPAREN", "AT", "DOT", "DOT_DOT", "ROOT", "WILDCARD",
"COLON", "QUESTION", "CONTAINS", "TRUE", "FALSE", "NULL", "Identifier",
"StringLiteral", "PositiveNumber", "NegativeNumber", "NumericLiteral",
"COMMA", "TICK", "QUOTE", "MATCHES", "LOGICAL_OPERATOR", "AND", "OR",

* <p>The default implementation does nothing.</p>
*/
@Override public void visitErrorNode(ErrorNode node) { }
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants