コード例 #1
0
ファイル: RqlParserTests.cs プロジェクト: jlyonsmith/Rql
        public void TestSimpleExpression()
        {
            //0000000000111111111122222222223333333333444444444455555555556666666666
                                   //0123456789012345678901234567890123456789012345678901234567890123456789
            string expressionText = "and(eq(field1,10),gte(field2,0),eq(field3,true),in(field4,(1,2,3,4)))";
            RqlExpression exp = new RqlParser().Parse(expressionText);

            Assert.IsInstanceOf<RqlExpression>(exp);
            Assert.AreEqual(expressionText, new TestExpressionVisitor(exp).ToString());
        }
コード例 #2
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));
        }
コード例 #3
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));
        }
コード例 #4
0
ファイル: FieldSpecParser.cs プロジェクト: jlyonsmith/Rql
        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);
        }
コード例 #5
0
ファイル: SortSpecParser.cs プロジェクト: jlyonsmith/Rql
        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);
        }