public StringExpression ToStringExpression(Expression expression) { var result = expression.Compile(); var newExp = new StringExpression(result.Result.ToString()); newExp.Operator = expression.Operator; return newExp; }
public void Remove(Expression item) { if (item == Current) { Current = item.Prev ?? item.Next; } _expressions.Remove(item); }
private void BuildUp(Token[] tokens, Expression parent) { while (_tokenIndex < tokens.Length) { var token = tokens[_tokenIndex]; IOperator op = null; if (token.TokenType == TokenType.Operator && OperatorsDict.Instance.TryGetValue(token.Value, out op)) { SetOperatorOnExpression(parent, op); } else if (token.TokenType == TokenType.Function) { BuildFunctionExpression(tokens, parent, token.Value); } else if (token.TokenType == TokenType.OpeningEnumerable) { _tokenIndex++; BuildEnumerableExpression(tokens, parent); } else if (token.TokenType == TokenType.OpeningParenthesis) { _tokenIndex++; BuildGroupExpression(tokens, parent); //if (parent is FunctionExpression) //{ // return; //} } else if (token.TokenType == TokenType.ClosingParenthesis || token.TokenType == TokenType.ClosingEnumerable) { break; } else if (token.TokenType == TokenType.Negator) { _negateNextExpression = true; } else if(token.TokenType == TokenType.Percent) { SetOperatorOnExpression(parent, Operator.Percent); if (parent == null) { _graph.Add(ConstantExpressions.Percent); } else { parent.AddChild(ConstantExpressions.Percent); } } else { CreateAndAppendExpression(ref parent, token); } _tokenIndex++; } }
public virtual Expression AddChild(Expression child) { if (_children.Any()) { var last = _children.Last(); child.Prev = last; last.Next = child; } _children.Add(child); return child; }
public Expression Add(Expression expression) { _expressions.Add(expression); if (Current != null) { Current.Next = expression; expression.Prev = Current; } Current = expression; return expression; }
public FunctionArgumentExpression(Expression function) : base(false) { _function = function; }
private void SetOperatorOnExpression(Expression parent, IOperator op) { if (parent == null) { _graph.Current.Operator = op; } else { Expression candidate; if (parent is FunctionArgumentExpression) { candidate = parent.Children.Last(); } else { candidate = parent.Children.Last(); if (candidate is FunctionArgumentExpression) { candidate = candidate.Children.Last(); } } candidate.Operator = op; } }
private void BuildGroupExpression(Token[] tokens, Expression parent) { if (parent == null) { _graph.Add(new GroupExpression(_negateNextExpression)); _negateNextExpression = false; BuildUp(tokens, _graph.Current); } else { if (parent.IsGroupedExpression || parent is FunctionArgumentExpression) { var newGroupExpression = new GroupExpression(_negateNextExpression); _negateNextExpression = false; parent.AddChild(newGroupExpression); BuildUp(tokens, newGroupExpression); } BuildUp(tokens, parent); } }
private void HandleFunctionArguments(Token[] tokens, Expression function) { _tokenIndex++; var token = tokens.ElementAt(_tokenIndex); if (token.TokenType != TokenType.OpeningParenthesis) { throw new ExcelErrorValueException(eErrorType.Value); } _tokenIndex++; BuildUp(tokens, function.Children.First()); }
private void BuildFunctionExpression(Token[] tokens, Expression parent, string funcName) { if (parent == null) { _graph.Add(new FunctionExpression(funcName, _parsingContext, _negateNextExpression)); _negateNextExpression = false; HandleFunctionArguments(tokens, _graph.Current); } else { var func = new FunctionExpression(funcName, _parsingContext, _negateNextExpression); _negateNextExpression = false; parent.AddChild(func); HandleFunctionArguments(tokens, func); } }
private void CreateAndAppendExpression(ref Expression parent, Token token) { if (IsWaste(token)) return; if (parent != null && (token.TokenType == TokenType.Comma || token.TokenType == TokenType.SemiColon)) { parent = parent.PrepareForNextChild(); return; } if (_negateNextExpression) { token.Negate(); _negateNextExpression = false; } var expression = _expressionFactory.Create(token); if (parent == null) { _graph.Add(expression); } else { parent.AddChild(expression); } }
private void BuildEnumerableExpression(Token[] tokens, Expression parent) { if (parent == null) { _graph.Add(new EnumerableExpression()); BuildUp(tokens, _graph.Current); } else { var enumerableExpression = new EnumerableExpression(); parent.AddChild(enumerableExpression); BuildUp(tokens, enumerableExpression); } }
public FunctionArgumentExpression(Expression function) { _function = function; }
private IEnumerable<Expression> RefreshList(Expression first) { var resultList = new List<Expression>(); var exp = first; resultList.Add(exp); while (exp.Next != null) { resultList.Add(exp.Next); exp = exp.Next; } _expressions = resultList; return resultList; }
public void Reset() { _expressions.Clear(); Current = null; }
public override Expression AddChild(Expression child) { Children.Last().AddChild(child); return child; }