Example #1
0
 public StringExpression ToStringExpression(Expression expression)
 {
     var result = expression.Compile();
     var newExp = new StringExpression(result.Result.ToString());
     newExp.Operator = expression.Operator;
     return newExp;
 }
Example #2
0
 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++;
     }
 }
Example #4
0
 public virtual Expression AddChild(Expression child)
 {
     if (_children.Any())
     {
         var last = _children.Last();
         child.Prev = last;
         last.Next = child;
     }
     _children.Add(child);
     return child;
 }
Example #5
0
 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;
 }
Example #7
0
 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;
     }
 }
Example #8
0
 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);
     }
 }
Example #9
0
 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());
 }
Example #10
0
 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);
     }
 }
Example #11
0
 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);
     }
 }
Example #12
0
 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;
 }
Example #14
0
 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;
 }
Example #15
0
 public void Reset()
 {
     _expressions.Clear();
     Current = null;
 }
Example #16
0
 public override Expression AddChild(Expression child)
 {
     Children.Last().AddChild(child);
     return child;
 }