コード例 #1
0
 public StringExpression ToStringExpression(Expression expression)
 {
     var result = expression.Compile();
     var newExp = new StringExpression(result.Result.ToString());
     newExp.Operator = expression.Operator;
     return newExp;
 }
コード例 #2
0
 public void Remove(Expression item)
 {
     if (item == Current)
     {
         Current = item.Prev ?? item.Next;
     }
     _expressions.Remove(item);
 }
コード例 #3
0
 public void Add(Expression expression)
 {
     _expressions.Add(expression);
     if (Current != null)
     {
         Current.Next = expression;
         expression.Prev = Current;
     }
     Current = expression;
 }
コード例 #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;
 }
コード例 #5
0
 private void BuildGroupExpression(IEnumerable<Token> tokens, Expression parent)
 {
     if (parent == null)
     {
         _graph.Add(new GroupExpression());
         BuildUp(tokens, _graph.Current);
     }
     else
     {
         BuildUp(tokens, parent);
     }
 }
コード例 #6
0
 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;
 }
コード例 #7
0
 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);
     }
 }
コード例 #8
0
 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);
     }
 }
コード例 #9
0
 public override Expression AddChild(Expression child)
 {
     return base.AddChild(child);
 }
コード例 #10
0
 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++;
     }
 }
コード例 #11
0
 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;
     }
 }
コード例 #12
0
 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);
     }
 }
コード例 #13
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;
 }