Beispiel #1
0
            protected override string BuildCondition(QConditionNode node)
            {
                string     lvalue    = BuildValue(node.LValue);
                string     rvalue    = BuildValue(node.RValue);
                Conditions condition = (node.Condition | Conditions.Not) ^ Conditions.Not;
                string     res       = null;

                for (int i = 0; i < enumConditions.Length; i++)
                {
                    if (enumConditions[i] == condition)
                    {
                        res = stringConditions[i];
                        break;                         // first match
                    }
                }
                if (res == null)
                {
                    throw new ArgumentException("Invalid conditions set", condition.ToString());
                }
                if ((node.Condition & Conditions.Not) == Conditions.Not)
                {
                    res = "!" + res;
                }
                if ((node.Condition & Conditions.Null) == Conditions.Null)
                {
                    rvalue = "null";
                }
                string result = String.Format("{0}{1}{2}", lvalue, res, rvalue);

                if (!String.IsNullOrEmpty(node.Name))
                {
                    result = String.Format("(<{0}> {1})", node.Name, result);
                }
                return(result);
            }
Beispiel #2
0
        protected QNode ParseCondition(string input, int startIdx, out int endIdx)
        {
            IQueryValue leftValue = ParseInternal(input, startIdx, out endIdx);

            int        nextEndIdx;
            Conditions conditions = Conditions.Equal;

            LexemType nextLexemType = GetLexemType(input, endIdx, out nextEndIdx);

            if (!GetCondition(nextLexemType, input, endIdx, ref nextEndIdx, ref conditions))
            {
                throw new RelexParseException(
                          String.Format("Invalid syntax (position: {0}, expression: {1})", startIdx, input));
            }

            IQueryValue rightValue = ParseInternal(input, nextEndIdx, out endIdx);
            QNode       node;

            if (IsNullValue(rightValue))
            {
                if ((conditions & Conditions.Equal) != 0)
                {
                    node = new QConditionNode(leftValue, Conditions.Null | (conditions & ~Conditions.Equal), null);
                }
                else
                {
                    throw new RelexParseException(
                              String.Format("Invalid syntax - such condition cannot be used with 'null' (position: {0}, expression: {1})", startIdx, input));
                }
            }
            else
            {
                node = new QConditionNode(leftValue, conditions, rightValue);
            }

            return(node);
        }