diff options
author | juliexxia <juliexxia@google.com> | 2018-01-04 15:28:55 -0800 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-01-04 15:31:17 -0800 |
commit | 86b4532769c22cca2ed7068a60f3326beaad34af (patch) | |
tree | 874250fb99d7d3289db5a5f0bd81bafcc405899a /src/main/java | |
parent | 1c5a1344bdf0853df9efc5d4574ee0b1f245c2a7 (diff) |
Restructure how universeScope is used when testing configured query to mimick impending changes to the configured query interface (CL/179872445) which will pull build targets out of the query expression.
Fill in testTopLevelTransitions on the way!
PiperOrigin-RevId: 180854150
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/query2/engine/QueryParser.java | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/query2/engine/QueryParser.java b/src/main/java/com/google/devtools/build/lib/query2/engine/QueryParser.java index b202bc326e..9ba285ee29 100644 --- a/src/main/java/com/google/devtools/build/lib/query2/engine/QueryParser.java +++ b/src/main/java/com/google/devtools/build/lib/query2/engine/QueryParser.java @@ -45,7 +45,7 @@ import java.util.Map; * | SET '(' WORD * ')' * </pre> */ -final class QueryParser { +public final class QueryParser { private Lexer.Token token; // current lookahead token private final List<Lexer.Token> tokens; @@ -56,23 +56,26 @@ final class QueryParser { * Scan and parse the specified query expression. */ static QueryExpression parse(String query, QueryEnvironment<?> env) throws QueryException { - QueryParser parser = new QueryParser(Lexer.scan(query), env); + HashMap<String, QueryFunction> functions = new HashMap<>(); + for (QueryFunction queryFunction : env.getFunctions()) { + functions.put(queryFunction.getName(), queryFunction); + } + return parse(query, functions); + } + + public static QueryExpression parse(String query, HashMap<String, QueryFunction> functions) + throws QueryException { + QueryParser parser = new QueryParser(Lexer.scan(query), functions); QueryExpression expr = parser.parseExpression(); if (parser.token.kind != TokenKind.EOF) { throw new QueryException("unexpected token '" + parser.token - + "' after query expression '" + expr + "'"); + + "' after query expression '" + expr + "'"); } return expr; } - private QueryParser(List<Lexer.Token> tokens, QueryEnvironment<?> env) { - // TODO(bazel-team): We only need QueryEnvironment#getFunctions, consider refactoring users of - // QueryParser#parse to instead just pass in the set of functions to make testing, among other - // things, simpler. - this.functions = new HashMap<>(); - for (QueryFunction queryFunction : env.getFunctions()) { - this.functions.put(queryFunction.getName(), queryFunction); - } + public QueryParser(List<Lexer.Token> tokens, HashMap<String, QueryFunction> functions) { + this.functions = functions; this.tokens = tokens; this.tokenIterator = tokens.iterator(); nextToken(); |