aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar fzaiser <fzaiser@google.com>2017-10-09 15:16:50 +0200
committerGravatar Marcel Hlopko <hlopko@google.com>2017-10-10 11:22:04 +0200
commitb5768af15f2949385b3d782199336d70e56e00e2 (patch)
treeac2eb5c63147cd8a27933f528f4475fcd771f94f /src
parent8880b7abceb78b22b56be53d02bf97d9e8cb74cb (diff)
Fix the location of load statements in Skylark.
Previously, the closing parenthesis was not included in the location. RELNOTES: none PiperOrigin-RevId: 171527078
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/google/devtools/build/lib/syntax/Parser.java4
-rw-r--r--src/test/java/com/google/devtools/build/lib/syntax/ParserTest.java10
2 files changed, 12 insertions, 2 deletions
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 6d457267ba..e59f3295af 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
@@ -1053,10 +1053,10 @@ public class Parser {
parseLoadSymbol(symbols);
}
- expect(TokenKind.RPAREN);
LoadStatement stmt = new LoadStatement(importString, symbols);
- list.add(setLocation(stmt, start, token.left));
+ list.add(setLocation(stmt, start, token.right));
+ expect(TokenKind.RPAREN);
expectAndRecover(TokenKind.NEWLINE);
}
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/ParserTest.java b/src/test/java/com/google/devtools/build/lib/syntax/ParserTest.java
index 20ea5c0b71..858e0cafe4 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/ParserTest.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/ParserTest.java
@@ -555,6 +555,16 @@ public class ParserTest extends EvaluationTestCase {
assertExpressionLocationCorrect("not True");
}
+ @Test
+ public void testLoadStatementPosition() throws Exception {
+ String input = "load(':foo.bzl', 'bar')";
+ LoadStatement stmt = (LoadStatement) parseFile(input).get(0);
+ assertThat(getText(input, stmt)).isEqualTo(input);
+ // Also try it with another token at the end (newline), which broke the location in the past.
+ stmt = (LoadStatement) parseFile(input + "\n").get(0);
+ assertThat(getText(input, stmt)).isEqualTo(input);
+ }
+
private void assertExpressionLocationCorrect(String exprStr) {
Expression expr = parseExpression(exprStr);
assertThat(getText(exprStr, expr)).isEqualTo(exprStr);