-
Notifications
You must be signed in to change notification settings - Fork 469
Add support to HCL grammar for escaped backslash #6117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support to HCL grammar for escaped backslash #6117
Conversation
| 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.*; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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; |
| 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, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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, |
| "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", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| "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", |
| 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", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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", |
| private Stack<CurlyType> leftCurlyStack = new Stack<CurlyType>(); | ||
| private Stack<String> heredocIdentifier = new Stack<String>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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<>(); |
| 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.*; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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; |
| 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, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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, |
| "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", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| "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", |
| 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() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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) { } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| } | |
| } |
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