Allow users of Blaze Lexer to explicitly specify the line-number table of a file. -- MOS_MIGRATED_REVID=96039514
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 5f6c769..c4a58a9 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 @@ * 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 7867455..3bcf0a0 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 @@ * 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 @@ * 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 @@ 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 @@ */ // 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 @@ 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<>();