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); }
public void Add(Expression expression) { _expressions.Add(expression); if (Current != null) { Current.Next = expression; expression.Prev = Current; } Current = expression; }
public virtual Expression AddChild(Expression child) { if (_children.Any()) { var last = _children.Last(); child.Prev = last; last.Next = child; } _children.Add(child); return child; }
private void BuildGroupExpression(IEnumerable<Token> tokens, Expression parent) { if (parent == null) { _graph.Add(new GroupExpression()); BuildUp(tokens, _graph.Current); } else { BuildUp(tokens, parent); } }
public override Expression AddChild(Expression child) { if (Children.Count() == 0) { var group = base.AddChild(new FunctionArgumentExpression()); group.AddChild(child); } else { Children.Last().AddChild(child); } return child; }
private void BuildFunctionExpression(IEnumerable<Token> tokens, Expression parent, string funcName) { if (parent == null) { _graph.Add(new FunctionExpression(funcName, _parsingContext)); BuildUp(tokens, _graph.Current); } else { var func = new FunctionExpression(funcName, _parsingContext); parent.AddChild(func); BuildUp(tokens, func); } }
private void BuildEnumerableExpression(IEnumerable<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 override Expression AddChild(Expression child) { return base.AddChild(child); }
private void BuildUp(IEnumerable<Token> tokens, Expression parent) { while (_tokenIndex < tokens.Count()) { var token = tokens.ElementAt(_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) { _tokenIndex++; BuildFunctionExpression(tokens, parent, token.Value); } else if (token.TokenType == TokenType.OpeningEnumerable) { _tokenIndex++; BuildEnumerableExpression(tokens, parent); } else if (token.TokenType == TokenType.OpeningBracket) { _tokenIndex++; BuildGroupExpression(tokens, parent); if (parent is FunctionExpression) { return; } } else if (token.TokenType == TokenType.ClosingBracket || token.TokenType == TokenType.ClosingEnumerable) { break; } else if (token.TokenType == TokenType.Negator) { _negateNextExpression = true; } else { CreateAndAppendExpression(parent, token); } _tokenIndex++; } }
private void SetOperatorOnExpression(Expression parent, IOperator op) { if (parent == null) { _graph.Current.Operator = op; } else { var candidate = parent.Children.Last(); if (candidate is FunctionArgumentExpression) { candidate = candidate.Children.Last(); } candidate.Operator = op; } }
private void CreateAndAppendExpression(Expression parent, Token token) { if (IsWaste(token)) return; if (parent != null && token.TokenType == TokenType.Comma) { 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 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; }