aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java
diff options
context:
space:
mode:
authorGravatar Laurent Le Brun <laurentlb@google.com>2015-10-21 13:13:35 +0000
committerGravatar Han-Wen Nienhuys <hanwen@google.com>2015-10-21 14:39:29 +0000
commit4d7fae3bfcc579676d7b2454ab8a38743aa4c635 (patch)
tree74983fbbd3eb9c330f958923d7ab695656de5d23 /src/main/java
parent5d9b8a0dcf89190edc190f439c383d7bdbae658f (diff)
Lexer: Handle triple quoted raw strings (e.g. r"""abc""").
-- MOS_MIGRATED_REVID=105956734
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/syntax/Lexer.java19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/Lexer.java b/src/main/java/com/google/devtools/build/lib/syntax/Lexer.java
index 2f739493b3..f656f28002 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/Lexer.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/Lexer.java
@@ -312,7 +312,7 @@ public final class Lexer {
*
* @return the string-literal token.
*/
- private Token escapedStringLiteral(char quot) {
+ private Token escapedStringLiteral(char quot, boolean isRaw) {
boolean inTriplequote = skipTripleQuote(quot);
int oldPos = pos - 1;
@@ -336,6 +336,14 @@ public final class Lexer {
error("unterminated string literal at eof", oldPos, pos);
return new Token(TokenKind.STRING, oldPos, pos, literal.toString());
}
+ if (isRaw) {
+ // Insert \ and the following character.
+ // As in Python, it means that a raw string can never end with a single \.
+ literal.append('\\');
+ literal.append(buffer[pos]);
+ pos++;
+ break;
+ }
c = buffer[pos];
pos++;
switch (c) {
@@ -428,7 +436,7 @@ public final class Lexer {
// Don't even attempt to parse triple-quotes here.
if (skipTripleQuote(quot)) {
pos -= 2;
- return escapedStringLiteral(quot);
+ return escapedStringLiteral(quot, isRaw);
}
// first quick optimistic scan for a simple non-escaped string
@@ -446,11 +454,10 @@ public final class Lexer {
// skip the next character
pos++;
break;
- } else {
- // oops, hit an escape, need to start over & build a new string buffer
- pos = oldPos + 1;
- return escapedStringLiteral(quot);
}
+ // oops, hit an escape, need to start over & build a new string buffer
+ pos = oldPos + 1;
+ return escapedStringLiteral(quot, false);
case '\'':
case '"':
if (c == quot) {