示例#1
0
        protected virtual RqlExpression Visit(RqlExpression node)
        {
            if (node == null)
            {
                return(node);
            }

            switch (node.ExpressionType)
            {
            case RqlExpressionType.Constant:
                return(this.VisitConstant((RqlConstantExpression)node));

            case RqlExpressionType.Identifier:
                return(this.VisitIdentifier((RqlIdentifierExpression)node));

            case RqlExpressionType.FunctionCall:
                return(this.VisitFunctionCall((RqlFunctionCallExpression)node));

            case RqlExpressionType.Tuple:
                return(this.VisitTuple((RqlTupleExpression)node));

            default:
                throw new NotImplementedException();
            }
        }
示例#2
0
        private RqlTupleExpression ParseTuple(RqlToken leftParenToken)
        {
            var  constants = new List <RqlConstantExpression>();
            Type itemType  = null;

            while (true)
            {
                RqlToken token = tokenizer.Next();

                if (token.IsConstant)
                {
                    if (itemType == null)
                    {
                        itemType = token.Data.GetType();
                    }
                    else if (token.Data.GetType() != itemType)
                    {
                        throw new RqlParseException(token, "Tuple items must all be of the same type");
                    }

                    constants.Add(RqlExpression.Constant(token));
                }
                else
                {
                    throw new RqlParseException(token);
                }

                token = tokenizer.Next();

                if (token.IsComma)
                {
                    continue;
                }
                else if (token.IsRightParen)
                {
                    break;
                }
                else
                {
                    throw new RqlParseException(token);
                }
            }

            return(RqlExpression.Tuple(leftParenToken, constants));
        }
示例#3
0
        protected virtual RqlExpression Visit(RqlExpression node)
        {
            if (node == null)
                return node;

            switch (node.ExpressionType)
            {
            case RqlExpressionType.Constant:
                return this.VisitConstant((RqlConstantExpression)node);
            case RqlExpressionType.Identifier:
                return this.VisitIdentifier((RqlIdentifierExpression)node);
            case RqlExpressionType.FunctionCall:
                return this.VisitFunctionCall((RqlFunctionCallExpression)node);
            case RqlExpressionType.Tuple:
                return this.VisitTuple((RqlTupleExpression)node);
            default:
                throw new NotImplementedException();
            }
        }
示例#4
0
        private RqlExpression ParseExpression(RqlToken functionToken)
        {
            RqlToken token = tokenizer.Next();

            if (!token.IsLeftParen)
            {
                throw new RqlParseException(token);
            }

            var arguments = new List <RqlExpression>();

            while (true)
            {
                token = tokenizer.Next();

                RqlExpression argument = null;

                if (token.IsIdentifier)
                {
                    if (tokenizer.PeekNext().IsLeftParen)
                    {
                        argument = ParseExpression(token);
                    }
                    else
                    {
                        argument = RqlExpression.Identifier(token);
                    }
                }
                else if (token.IsConstant)
                {
                    argument = RqlExpression.Constant(token);
                }
                else if (token.IsLeftParen)
                {
                    argument = ParseTuple(token);
                }
                else
                {
                    throw new RqlParseException(token);
                }

                arguments.Add(argument);

                token = tokenizer.Next();

                if (token.IsComma)
                {
                    continue;
                }
                else if (token.IsRightParen)
                {
                    break;
                }
                else
                {
                    throw new RqlParseException(token);
                }
            }

            return(RqlExpression.FunctionCall(functionToken, arguments));
        }
示例#5
0
 public TestExpressionVisitor(RqlExpression exp)
 {
     this.exp = exp;
 }