Parses an expression into a tree @param expression The expression to parse (as a string) @param metric_queries A list to store the parsed metrics in @param data_query The time series query @return The parsed tree ready for evaluation @throws IllegalArgumentException if the expression was null, empty
(final String expression,
final List<String> metric_queries,
final TSQuery data_query)
| 41 | * be found. |
| 42 | */ |
| 43 | public static ExpressionTree parse(final String expression, |
| 44 | final List<String> metric_queries, |
| 45 | final TSQuery data_query) { |
| 46 | if (expression == null || expression.isEmpty()) { |
| 47 | throw new IllegalArgumentException("Expression may not be null or empty"); |
| 48 | } |
| 49 | if (expression.indexOf('(') == -1 || expression.indexOf(')') == -1) { |
| 50 | throw new IllegalArgumentException("Invalid Expression: " + expression); |
| 51 | } |
| 52 | |
| 53 | final ExpressionReader reader = new ExpressionReader(expression.toCharArray()); |
| 54 | // consume any whitespace ahead of the expression |
| 55 | reader.skipWhitespaces(); |
| 56 | |
| 57 | final String function_name = reader.readFuncName(); |
| 58 | final Expression root_expression = ExpressionFactory.getByName(function_name); |
| 59 | |
| 60 | final ExpressionTree root = new ExpressionTree(root_expression, data_query); |
| 61 | reader.skipWhitespaces(); |
| 62 | |
| 63 | if (reader.peek() == '(') { |
| 64 | reader.next(); |
| 65 | parse(reader, metric_queries, root, data_query); |
| 66 | } |
| 67 | |
| 68 | return root; |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Parses a list of string expressions into the proper trees, adding the |