コード例 #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));
        }
コード例 #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));
        }
コード例 #3
0
 protected virtual RqlExpression VisitConstant(RqlConstantExpression node)
 {
     return node;
 }
コード例 #4
0
ファイル: RqlParserTests.cs プロジェクト: jlyonsmith/Rql
        protected override RqlExpression VisitConstant(RqlConstantExpression node)
        {
            s += FormatSimpleConstant(node.Type, node.Value);

            return node;
        }
コード例 #5
0
ファイル: RqlExpressionVisitor.cs プロジェクト: ximbor/Rql
 protected virtual RqlExpression VisitConstant(RqlConstantExpression node)
 {
     return(node);
 }