Exemplo n.º 1
0
        private FilterOperand GetLhs(FilterParser.Elem_opContext elem_opContext)
        {
            FilterOperand lhs = Evaluate(elem_opContext.elem_op()?[0]);

            if (lhs == null)
            {
                lhs = Evaluate(elem_opContext.attr_op().First());
            }
            return(lhs);
        }
Exemplo n.º 2
0
        private FilterOperand GetRhs(FilterParser.Elem_opContext elem_opContext)
        {
            FilterOperand rhs = Evaluate(elem_opContext.lit_op());

            if (rhs == null)
            {
                rhs = Evaluate(elem_opContext.attr_op().Last());
            }
            if (rhs == null)
            {
                var elem = elem_opContext.elem_op();
                if (elem?.Length == 2)
                {
                    rhs = Evaluate(elem_opContext.elem_op()?[1]);
                }
            }
            return(rhs);
        }
Exemplo n.º 3
0
        private ElementOperand Evaluate(FilterParser.Elem_opContext elem_opContext)
        {
            if (elem_opContext.BR_OPEN() != null ||
                elem_opContext.BR_CLOSE() != null)
            {
                elem_opContext = elem_opContext.elem_op()[0];
            }

            var comparison = elem_opContext.COMPARISON_OPERATOR();
            var or         = elem_opContext.OR();
            var and        = elem_opContext.AND();

            if (comparison != null || or != null || and != null)
            {
                // First is elem or attribute[0], second is lit or attribute[1]
                var lhs = GetLhs(elem_opContext);
                var rhs = GetRhs(elem_opContext);
                WhereClause.Push(and != null ? FilterOperator.And : or != null ? FilterOperator.Or :
                                 ToOperator(comparison), lhs, rhs);
                return(new ElementOperand {
                    Index = (uint)WhereClause.Elements.Count - 1
                });
            }

            var inlist = elem_opContext.IN();

            if (inlist != null)
            {
                var lhs  = GetLhs(elem_opContext);
                var list = Evaluate(elem_opContext.list);
                WhereClause.Push(FilterOperator.InList, lhs.YieldReturn().Concat(list).ToArray());
                return(new ElementOperand {
                    Index = (uint)WhereClause.Elements.Count - 1
                });
            }

            throw new Exception();
        }