@@ -166,6 +166,24 @@ PARSER_END(CCJSqlParser)
166
166
TOKEN_MGR_DECLS : {
167
167
public FeatureConfiguration configuration = new FeatureConfiguration();
168
168
169
+ // Identify the index of the quoting/escaping tokens
170
+ public int charLiteralIndex = -1;
171
+ public int squaredBracketOpenIndex = -1;
172
+ {
173
+ for (int i=0;i<CCJSqlParserConstants.tokenImage.length;i++) {
174
+ if ( CCJSqlParserConstants.tokenImage[i].equals("<S_CHAR_LITERAL>") ) {
175
+ charLiteralIndex = i;
176
+ break;
177
+ }
178
+ }
179
+ for (int i=0;i<CCJSqlParserConstants.tokenImage.length;i++) {
180
+ if (CCJSqlParserConstants.tokenImage[i].equals("\"[\"")) {
181
+ squaredBracketOpenIndex = i;
182
+ break;
183
+ }
184
+ }
185
+ }
186
+
169
187
public void CommonTokenAction(Token t)
170
188
{
171
189
t.absoluteBegin = getCurrentTokenAbsolutePosition();
@@ -741,31 +759,22 @@ TOKEN:
741
759
if ( !configuration.getAsBoolean(Feature.allowBackslashEscapeCharacter)
742
760
&& matchedToken.image.contains("\\'") ) {
743
761
matchedToken.image = "'" + image.substring( 0, image.indexOf("\\'") + 1 ) + "'";
744
- for (int i=0;i<CCJSqlParserConstants.tokenImage.length;i++) {
745
- if ( CCJSqlParserConstants.tokenImage[i].equals("<S_CHAR_LITERAL>") ) {
746
- matchedToken.kind = i;
747
- }
748
- }
762
+ // `charLiteralIndex` defined in TokenManagerDeclaration above
763
+ matchedToken.kind = charLiteralIndex;
749
764
input_stream.backup(image.length() + 1 - matchedToken.image.length());
750
765
} else if ( configuration.getAsBoolean(Feature.allowBackslashEscapeCharacter) && matchedToken.image.contains("\\''") ) {
751
766
matchedToken.image = "'" + image.substring( 0, image.lastIndexOf("\\'") + 3);
752
- for (int i=0;i<CCJSqlParserConstants.tokenImage.length;i++) {
753
- if ( CCJSqlParserConstants.tokenImage[i].equals("<S_CHAR_LITERAL>") ) {
754
- matchedToken.kind = i;
755
- }
756
- }
767
+ // `charLiteralIndex` defined in TokenManagerDeclaration above
768
+ matchedToken.kind = charLiteralIndex;
757
769
input_stream.backup(image.length() + 1 - matchedToken.image.length() );
758
770
}
759
771
}
760
772
| < S_QUOTED_IDENTIFIER: "\"" ( "\"\"" | ~["\n","\r","\""])* "\"" | "$$" (~["$"])* "$$" | ("`" (~["\n","\r","`"])+ "`") | ( "[" (~["\n","\r","]"])* "]" ) >
761
773
{
762
774
if ( !configuration.getAsBoolean(Feature.allowSquareBracketQuotation) && matchedToken.image.charAt(0) == '[' ) {
763
775
matchedToken.image = "[";
764
- for (int i=0;i<CCJSqlParserConstants.tokenImage.length;i++) {
765
- if (CCJSqlParserConstants.tokenImage[i].equals("\"[\"")) {
766
- matchedToken.kind = i;
767
- }
768
- }
776
+ // `squaredBracketOpenIndex` defined in TokenManagerDeclaration above
777
+ matchedToken.kind = squaredBracketOpenIndex;
769
778
input_stream.backup(image.length() - 1);
770
779
}
771
780
}
0 commit comments