aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/query2/engine/Lexer.java
diff options
context:
space:
mode:
authorGravatar Michajlo Matijkiw <michajlo@google.com>2016-11-01 21:35:04 +0000
committerGravatar Laszlo Csomor <laszlocsomor@google.com>2016-11-02 08:29:42 +0000
commit2be2f4cdd2a50f65b3adfd0007d25f5c22dacf83 (patch)
treefceb04b3a8484248d3137bfbb47d3f1bda2c362a /src/main/java/com/google/devtools/build/lib/query2/engine/Lexer.java
parentf4a968c43541ef6ddfbdca7830232f33fb1bfdc6 (diff)
Have query Lexer operated directly on String
No need for the char[] in the middle, prevents us from accidentally modifying input, or sucking up ram on huge queries. -- MOS_MIGRATED_REVID=137872573
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/query2/engine/Lexer.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/query2/engine/Lexer.java26
1 files changed, 13 insertions, 13 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/query2/engine/Lexer.java b/src/main/java/com/google/devtools/build/lib/query2/engine/Lexer.java
index ef5343b9f1..d9aaf35e0d 100644
--- a/src/main/java/com/google/devtools/build/lib/query2/engine/Lexer.java
+++ b/src/main/java/com/google/devtools/build/lib/query2/engine/Lexer.java
@@ -119,20 +119,20 @@ public final class Lexer {
* Entry point to the lexer. Returns the list of tokens for the specified
* input, or throws QueryException.
*/
- public static List<Token> scan(char[] buffer) throws QueryException {
- Lexer lexer = new Lexer(buffer);
+ public static List<Token> scan(String input) throws QueryException {
+ Lexer lexer = new Lexer(input);
lexer.tokenize();
return lexer.tokens;
}
// Input buffer and position
- private char[] buffer;
+ private String input;
private int pos;
private final List<Token> tokens = new ArrayList<>();
- private Lexer(char[] buffer) {
- this.buffer = buffer;
+ private Lexer(String input) {
+ this.input = input;
this.pos = 0;
}
@@ -150,8 +150,8 @@ public final class Lexer {
*/
private Token quotedWord(char quot) throws QueryException {
int oldPos = pos - 1;
- while (pos < buffer.length) {
- char c = buffer[pos++];
+ while (pos < input.length()) {
+ char c = input.charAt(pos++);
switch (c) {
case '\'':
case '"':
@@ -174,8 +174,8 @@ public final class Lexer {
// (e.g. cc_.*). Keep consistent with TargetLiteral.toString()!
private String scanWord() {
int oldPos = pos - 1;
- while (pos < buffer.length) {
- switch (buffer[pos]) {
+ while (pos < input.length()) {
+ switch (input.charAt(pos)) {
case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
case 'g': case 'h': case 'i': case 'j': case 'k': case 'l':
case 'm': case 'n': case 'o': case 'p': case 'q': case 'r':
@@ -218,8 +218,8 @@ public final class Lexer {
* the constructor.
*/
private void tokenize() throws QueryException {
- while (pos < buffer.length) {
- char c = buffer[pos];
+ while (pos < input.length()) {
+ char c = input.charAt(pos);
pos++;
switch (c) {
case '(': {
@@ -271,11 +271,11 @@ public final class Lexer {
addToken(new Token(TokenKind.EOF));
- this.buffer = null; // release buffer now that we have our tokens
+ this.input = null; // release buffer now that we have our tokens
}
private String bufferSlice(int start, int end) {
- return new String(this.buffer, start, end - start);
+ return this.input.substring(start, end);
}
}