Example #1
0
        private Filter <T> Combine(Filter <T> right, Filter <T> top)
        {
            if (right == null)
            {
                return(top);
            }
            if (top == null)
            {
                return(right);
            }

            if (right is FilterKeyword <T> )
            {
                FilterKeyword <T> keyword = (FilterKeyword <T>)right;
                if (top is FilterKeyword <T> )
                {
                    // easy case, we are parsing a string of words, so combine them back into a single literal to match.
                    FilterKeyword <T> keyword2 = (FilterKeyword <T>)top;
                    keyword.Keyword = new FilterLiteral(keyword.Keyword.Literal + " " + keyword2.Keyword.Literal);
                    return(right);
                }
            }

            // everything else is some sort of parse error, so this is error recover code...
            return(right);
        }
Example #2
0
        private Filter <T> Reduce(QuickFilterToken token)
        {
            while (stack.Count > 0)
            {
                Filter <T> top = stack.Pop();

                if (stack.Count == 0)
                {
                    return(top);
                }

                Filter <T> op = stack.Peek();
                if (token > op.Precidence)
                {
                    return(top);
                }

                op = stack.Pop();

                // now combine "top" and "op"
                if (op is FilterKeyword <T> )
                {
                    FilterKeyword <T> keyword = (FilterKeyword <T>)op;
                    op = Combine(keyword, top);
                }
                else if (op is FilterAnd <T> )
                {
                    FilterAnd <T> and = (FilterAnd <T>)op;
                    and.Right = Combine(and.Right, top);
                }
                else if (op is FilterOr <T> )
                {
                    FilterOr <T> or = (FilterOr <T>)op;
                    or.Right = Combine(or.Right, top);
                }
                else if (op is FilterNot <T> )
                {
                    FilterNot <T> not = (FilterNot <T>)op;
                    not.Right = Combine(not.Right, top);
                }
                else if (op is FilterParens <T> )
                {
                    FilterParens <T> parens = (FilterParens <T>)op;
                    parens.Expression = Combine(parens.Expression, top);
                }
                stack.Push(op);
            }
            return(null);
        }