@@ -6974,22 +6974,37 @@ TOKEN:
69746974 // lexUnicodeEscapeString(). Backslashes do not escape its quotes.
69756975 | "U&'" ("''" | ~["'"])* "'"
69766976 ( ([" ", "\t", "\r", "\n"])* "UESCAPE" ([" ", "\t", "\r", "\n"])* "'" ~["'"] "'" )?
6977+ // Databricks raw literal, see below
6978+ | "R\"" (~["\""])* "\""
69776979 ) >
69786980 {
6979- // The longest match may run past the closing quote of the active rules. A backslash
6980- // escapes the next character only with backslash escapes or in a PostgreSQL E'' string;
6981- // otherwise the literal ends at the first quote that is not doubled, so LIKE ... ESCAPE '\\'
6982- // still works.
6983- boolean backslashEscapes = configuration.getAsBoolean(Feature.allowBackslashEscapeCharacter)
6984- || (AbstractJSqlParser.Dialect.POSTGRESQL.name().equals(configuration.getValue(Feature.dialect))
6985- && matchedToken.image.regionMatches(true, 0, "E'", 0, 2));
6986- int end = closingSingleQuote(matchedToken.image, backslashEscapes);
6987- if (end > 0 && end < matchedToken.image.length()) {
6988- matchedToken.image = image.substring(0, end);
6989- input_stream.backup(image.length() - end);
6990- }
6991- if (isUnicodeEscapeString(matchedToken.image)) {
6992- lexUnicodeEscapeString(matchedToken);
6981+ // A Databricks raw literal R'...' or R"..." has no escapes at all: it ends at the first
6982+ // closing quote, also after a backslash.
6983+ boolean databricks = AbstractJSqlParser.Dialect.DATABRICKS.name().equals(configuration.getValue(Feature.dialect));
6984+ if (matchedToken.image.regionMatches(true, 0, "R\"", 0, 2)) {
6985+ // Other dialects read the identifier R before a quoted name
6986+ if (!databricks) {
6987+ truncateIdentifierToken(matchedToken, 1);
6988+ matchedToken.kind = S_IDENTIFIER;
6989+ }
6990+ } else {
6991+ // The longest match may run past the closing quote of the active rules. A backslash
6992+ // escapes the next character only with backslash escapes or in a PostgreSQL E'' string;
6993+ // otherwise the literal ends at the first quote that is not doubled, so LIKE ... ESCAPE '\\'
6994+ // still works.
6995+ boolean backslashEscapes = configuration.getAsBoolean(Feature.allowBackslashEscapeCharacter)
6996+ || (AbstractJSqlParser.Dialect.POSTGRESQL.name().equals(configuration.getValue(Feature.dialect))
6997+ && matchedToken.image.regionMatches(true, 0, "E'", 0, 2));
6998+ int end = databricks && matchedToken.image.regionMatches(true, 0, "R'", 0, 2)
6999+ ? matchedToken.image.indexOf('\'', 2) + 1
7000+ : closingSingleQuote(matchedToken.image, backslashEscapes);
7001+ if (end > 0 && end < matchedToken.image.length()) {
7002+ matchedToken.image = image.substring(0, end);
7003+ input_stream.backup(image.length() - end);
7004+ }
7005+ if (isUnicodeEscapeString(matchedToken.image)) {
7006+ lexUnicodeEscapeString(matchedToken);
7007+ }
69937008 }
69947009 }
69957010| < S_QUOTED_IDENTIFIER: "\"" ( "\"\"" | ~["\""])* "\""
0 commit comments