aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Carmi Grushko <carmi@google.com>2015-06-15 20:46:52 +0000
committerGravatar Kristina Chodorow <kchodorow@google.com>2015-06-16 13:59:52 +0000
commita896a6cbb68c0adfff153ef7cb00f01e157c64a5 (patch)
treecc1c6bca38bee3c21127e7fa454a3b76d9d82084
parent1e833fea44f394e70d33465e74e1c4a8b4909a0c (diff)
Allow users of Blaze Lexer to explicitly specify the line-number table of a file.
-- MOS_MIGRATED_REVID=96039514
-rw-r--r--src/main/java/com/google/devtools/build/lib/syntax/Lexer.java14
-rw-r--r--src/main/java/com/google/devtools/build/lib/syntax/LineNumberTable.java10
2 files changed, 15 insertions, 9 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 5f6c769ebb..c4a58a9d2f 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
@@ -88,20 +88,26 @@ public final class Lexer {
* Constructs a lexer which tokenizes the contents of the specified
* InputBuffer. Any errors during lexing are reported on "handler".
*/
- public Lexer(ParserInputSource input, EventHandler eventHandler, boolean parsePython) {
+ public Lexer(ParserInputSource input, EventHandler eventHandler, boolean parsePython,
+ LineNumberTable lineNumberTable) {
this.buffer = input.getContent();
this.pos = 0;
this.parsePython = parsePython;
this.eventHandler = eventHandler;
- this.locationInfo =
- new LocationInfo(input.getPath(), LineNumberTable.create(buffer, input.getPath()));
+ this.locationInfo = new LocationInfo(input.getPath(), lineNumberTable);
indentStack.push(0);
tokenize();
}
public Lexer(ParserInputSource input, EventHandler eventHandler) {
- this(input, eventHandler, false);
+ this(input, eventHandler, /*parsePython=*/false,
+ LineNumberTable.create(input.getContent(), input.getPath()));
+ }
+
+ public Lexer(ParserInputSource input, EventHandler eventHandler, boolean parsePython) {
+ this(input, eventHandler, parsePython,
+ LineNumberTable.create(input.getContent(), input.getPath()));
}
/**
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/LineNumberTable.java b/src/main/java/com/google/devtools/build/lib/syntax/LineNumberTable.java
index 7867455d57..3bcf0a0166 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/LineNumberTable.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/LineNumberTable.java
@@ -35,7 +35,7 @@ import java.util.regex.Pattern;
* their buffer using {@link #create}. The client can then ask for the line and column given a
* position using ({@link #getLineAndColumn(int)}).
*/
-abstract class LineNumberTable implements Serializable {
+public abstract class LineNumberTable implements Serializable {
/**
* Returns the (line, column) pair for the specified offset.
@@ -67,7 +67,7 @@ abstract class LineNumberTable implements Serializable {
* offsets of newlines.
*/
@Immutable
- private static class Regular extends LineNumberTable {
+ public static class Regular extends LineNumberTable {
/**
* A mapping from line number (line >= 1) to character offset into the file.
@@ -76,7 +76,7 @@ abstract class LineNumberTable implements Serializable {
private final PathFragment path;
private final int bufferLength;
- private Regular(char[] buffer, PathFragment path) {
+ public Regular(char[] buffer, PathFragment path) {
// Compute the size.
int size = 2;
for (int i = 0; i < buffer.length; i++) {
@@ -154,7 +154,7 @@ abstract class LineNumberTable implements Serializable {
*/
// TODO(bazel-team): Use binary search instead of linear search.
@Immutable
- private static class HashLine extends LineNumberTable {
+ public static class HashLine extends LineNumberTable {
/**
* Represents a "#line" directive
@@ -185,7 +185,7 @@ abstract class LineNumberTable implements Serializable {
private final PathFragment defaultPath;
private final int bufferLength;
- private HashLine(char[] buffer, PathFragment defaultPath) {
+ public HashLine(char[] buffer, PathFragment defaultPath) {
CharSequence bufString = CharBuffer.wrap(buffer);
Matcher m = pattern.matcher(bufString);
List<SingleHashLine> unorderedTable = new ArrayList<>();