From 86b4532769c22cca2ed7068a60f3326beaad34af Mon Sep 17 00:00:00 2001 From: juliexxia Date: Thu, 4 Jan 2018 15:28:55 -0800 Subject: 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 --- .../build/lib/query2/engine/QueryParser.java | 25 ++++++++++++---------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'src/main/java') 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 * ')' * */ -final class QueryParser { +public final class QueryParser { private Lexer.Token token; // current lookahead token private final List 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 functions = new HashMap<>(); + for (QueryFunction queryFunction : env.getFunctions()) { + functions.put(queryFunction.getName(), queryFunction); + } + return parse(query, functions); + } + + public static QueryExpression parse(String query, HashMap 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 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 tokens, HashMap functions) { + this.functions = functions; this.tokens = tokens; this.tokenIterator = tokens.iterator(); nextToken(); -- cgit v1.2.3