Skylark parser: make the end position of location ranges inclusive.
Previously, the end line and column of a location were the position past the actual end of a location. This makes sense for the end offset, because one can use `input.substring(startOffset, endOffset)` to get the string belonging to an ASTNode.
However the line and column (as opposed to the offset) aren't used for that. Therefore I made the change that the end line and column now point to the last character in the location. This is also they way every compiler I know does it.
RELNOTES: none
PiperOrigin-RevId: 170723732
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 20923da..20ea5c0 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
@@ -20,6 +20,7 @@
import com.google.common.collect.ImmutableList;
import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.events.Location;
+import com.google.devtools.build.lib.events.Location.LineAndColumn;
import com.google.devtools.build.lib.syntax.DictionaryLiteral.DictionaryEntryLiteral;
import com.google.devtools.build.lib.syntax.Parser.ParsingLevel;
import com.google.devtools.build.lib.syntax.SkylarkImports.SkylarkImportSyntaxException;
@@ -356,7 +357,7 @@
assertLocation(5, 29, arg1val.getLocation());
assertThat(expr.substring(5, 28)).isEqualTo("[x for foo foo foo foo]");
- assertThat(arg1val.getLocation().getEndLineAndColumn().getColumn()).isEqualTo(30);
+ assertThat(arg1val.getLocation().getEndLineAndColumn().getColumn()).isEqualTo(29);
IntegerLiteral arg2 = (IntegerLiteral) e.getArguments().get(2).getValue();
assertThat((int) arg2.getValue()).isEqualTo(3);
@@ -480,6 +481,14 @@
}
@Test
+ public void testEndLineAndColumnIsInclusive() {
+ AssignmentStatement stmt =
+ (AssignmentStatement) parseStatement(ParsingLevel.LOCAL_LEVEL, "a = b");
+ assertThat(stmt.getLValue().getLocation().getEndLineAndColumn())
+ .isEqualTo(new LineAndColumn(1, 1));
+ }
+
+ @Test
public void testFuncallLocation() {
List<Statement> statements = parseFile("a(b);c = d\n");
Statement statement = statements.get(0);