LoadStatement: Keep the location of the path argument.
--
MOS_MIGRATED_REVID=102743954
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/Parser.java b/src/main/java/com/google/devtools/build/lib/syntax/Parser.java
index 9efd28e..7d2311c 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/Parser.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/Parser.java
@@ -670,6 +670,24 @@
}
}
+ /**
+ * Parse a String literal value, e.g. "str".
+ */
+ private StringLiteral parseStringLiteral() {
+ Preconditions.checkState(token.kind == TokenKind.STRING);
+ int end = token.right;
+ char quoteChar = lexer.charAt(token.left);
+ StringLiteral literal =
+ setLocation(new StringLiteral((String) token.value, quoteChar), token.left, end);
+
+ nextToken();
+ if (token.kind == TokenKind.STRING) {
+ reportError(lexer.createLocation(end, token.left),
+ "Implicit string concatenation is forbidden, use the + operator");
+ }
+ return literal;
+ }
+
// primary ::= INTEGER
// | STRING
// | STRING '.' IDENTIFIER funcall_suffix
@@ -691,17 +709,7 @@
return literal;
}
case STRING: {
- String value = (String) token.value;
- int end = token.right;
- char quoteChar = lexer.charAt(start);
- nextToken();
- if (token.kind == TokenKind.STRING) {
- reportError(lexer.createLocation(end, token.left),
- "Implicit string concatenation is forbidden, use the + operator");
- }
- StringLiteral literal = new StringLiteral(value, quoteChar);
- setLocation(literal, start, end);
- return literal;
+ return parseStringLiteral();
}
case IDENTIFIER: {
Identifier ident = parseIdent();
@@ -1103,10 +1111,7 @@
return;
}
- Token pathToken = token;
- String path = (String) token.value;
-
- nextToken();
+ StringLiteral path = parseStringLiteral();
expect(TokenKind.COMMA);
Map<Identifier, String> symbols = new HashMap<>();
@@ -1130,7 +1135,7 @@
try {
stmt.validatePath();
} catch (EvalException e) {
- syntaxError(pathToken, e.getMessage());
+ reportError(path.getLocation(), e.getMessage());
}
list.add(setLocation(stmt, start, token.left));