public CallOperator(StandaloneMetric caller, MetricExpression callee) : base(caller, callee) { if (caller == null || callee == null) { throw new ArgumentNullException(); } _caller = caller; _callee = callee; }
public static MetricExpression ParseExpression(string expression) { var parser = new MetricExpressionParser(); MetricExpression metricExpression = parser.Parse(expression); if (metricExpression == null) { throw new InvalidOperationException( string.Format( "Parse expression {0} failed. \nError message: {1}", expression, parser.LastErrorMessage)); } return(metricExpression); }
public SelectionOperator(MetricExpression host, int fieldIndex) : base(host) { if (fieldIndex < 0) { throw new ArgumentException("fieldIndex must not be negative"); } if (fieldIndex >= host.FieldNames.Length) { throw new ArgumentException("fieldIndex is greater than host's total fields"); } _fieldIndex = fieldIndex; _fieldNames = new string[1] { host.FieldNames[fieldIndex] }; }
public MetricExpression Parse(string expression) { // reset status and internal data structures. Reset(); // parse all tokens out and put it in queue. Tokenizer _tokenizer = new Tokenizer(expression); Token token = null; do { if (!_tokenizer.GetNextToken(out token)) { LastErrorMessage = "Parse token failed: " + _tokenizer.LastErrorMessage; return(null); } if (token != null) { _tokens.Enqueue(token); } } while (token != null); // use recursive descending parsing MetricExpression metric = Parse(); if (metric != null) { token = PeekNextToken(); if (token != null) { LastErrorMessage = string.Format("Unexpected token {0} left after parsing at {1}", token.Type, token.StartPosition); return(null); } } return(metric); }
protected MetricBinaryOperator(MetricExpression operand1, MetricExpression operand2) { Operand1 = operand1; Operand2 = operand2; }
private MetricExpression Parse() { // parse the first part, such as MA[20] var metric = ParseMetric(); if (metric == null) { return(null); } // parse the call operation part, such as (MA[20]) MetricExpression callee = null; var token = PeekNextToken(); if (token != null && token.Type == TokenType.LeftParenthese) { GetNextToken(); callee = Parse(); if (callee == null || !Expect(TokenType.RightParenthese, out token)) { return(null); } } // parse the selection part, such as .DIF var fieldIndex = -1; token = PeekNextToken(); if (token != null && token.Type == TokenType.Dot) { GetNextToken(); if (!Expect(TokenType.Identifier, out token)) { return(null); } var field = token.Value; // verify if the selection name is part of metric definition var metricType = metric.Metric.GetType(); var attribute = metricType.GetCustomAttribute <MetricAttribute>(); if (!attribute.NameToFieldIndexMap.ContainsKey(field)) { LastErrorMessage = string.Format("{0} is not a valid subfield of metric {1}", field, metricType.Name); return(null); } fieldIndex = attribute.NameToFieldIndexMap[field]; } MetricExpression retValue = metric; if (callee != null) { retValue = new CallOperator(metric, callee); } if (fieldIndex >= 0) { retValue = new SelectionOperator(retValue, fieldIndex); } return(retValue); }
protected MetricUnaryOperator(MetricExpression operand) { Operand = operand; }