Example #1
0
        public SortSpec Parse(string sortSpec)
        {
            this.input = sortSpec;

            string[] parts  = input.Split(',');
            var      fields = new List <SortSpecField>();

            foreach (var part in parts)
            {
                RqlFunctionCallExpression funcExp = null;

                try
                {
                    funcExp = new RqlParser().Parse(part) as RqlFunctionCallExpression;
                }
                catch (RqlParseException e)
                {
                    throw new SortSpecParserException("Sort specification must be of the form field(...)", e);
                }

                if (funcExp.Arguments.Count != 1)
                {
                    throw new SortSpecParserException("Sort specifications must have exactly one argument");
                }

                RqlConstantExpression constExp = funcExp.Arguments[0] as RqlConstantExpression;

                if (constExp == null || !(constExp.Value is Int32))
                {
                    throw new SortSpecParserException("Sort specification value must be an integer");
                }

                var value = (int)constExp.Value;

                if (value != 1 && value != -1)
                {
                    throw new SortSpecParserException("Sort specification value must be 1 or -1");
                }

                fields.Add(new SortSpecField(funcExp.Name, value == 1 ? SortSpecSortOrder.Ascending : SortSpecSortOrder.Descending));
            }

            return(new SortSpec(fields));
        }
Example #2
0
        public FieldSpec Parse(string fieldSpec)
        {
            this.input = fieldSpec;

            string[] parts  = input.Split(',');
            var      fields = new List <FieldSpecField>();

            foreach (var part in parts)
            {
                RqlFunctionCallExpression funcExp = null;

                try
                {
                    funcExp = new RqlParser().Parse(part) as RqlFunctionCallExpression;
                }
                catch (RqlParseException e)
                {
                    throw new FieldSpecParserException("Field specification must be of the form field(...)", e);
                }

                if (funcExp.Arguments.Count != 1)
                {
                    throw new FieldSpecParserException("Field specifications must have exactly one argument");
                }

                RqlConstantExpression constExp = funcExp.Arguments[0] as RqlConstantExpression;

                if (constExp == null || !(constExp.Value is Int32))
                {
                    throw new FieldSpecParserException("Field specification must be an integer");
                }

                var value = (int)constExp.Value;

                if (value != 0 && value != 1)
                {
                    throw new FieldSpecParserException("Field specification value must be 0 or 1");
                }

                fields.Add(new FieldSpecField(funcExp.Name, value == 1 ? FieldSpecPresence.Included : FieldSpecPresence.Excluded));
            }

            return(new FieldSpec(fields));
        }
Example #3
0
 protected virtual RqlExpression VisitConstant(RqlConstantExpression node)
 {
     return node;
 }
Example #4
0
        protected override RqlExpression VisitConstant(RqlConstantExpression node)
        {
            s += FormatSimpleConstant(node.Type, node.Value);

            return node;
        }
Example #5
0
 protected virtual RqlExpression VisitConstant(RqlConstantExpression node)
 {
     return(node);
 }