コード例 #1
0
 internal static Pattern Compile(Expression e)
 {
     if (e is ExprUNION)
     {
         return(new UnionPattern(Pattern.Compile(((ExprUNION)e).left), Pattern.Compile(((ExprUNION)e).right)));
     }
     if (e is ExprRoot)
     {
         return(new LocationPathPattern(new NodeTypeTest(Axes.Self, XPathNodeType.Root)));
     }
     if (e is NodeTest)
     {
         return(new LocationPathPattern((NodeTest)e));
     }
     if (e is ExprFilter)
     {
         return(new LocationPathPattern((ExprFilter)e));
     }
     if (e is ExprSLASH)
     {
         Pattern             prev = Pattern.Compile(((ExprSLASH)e).left);
         LocationPathPattern locationPathPattern = (LocationPathPattern)Pattern.Compile(((ExprSLASH)e).right);
         locationPathPattern.SetPreviousPattern(prev, false);
         return(locationPathPattern);
     }
     if (e is ExprSLASH2)
     {
         if (((ExprSLASH2)e).left is ExprRoot)
         {
             return(Pattern.Compile(((ExprSLASH2)e).right));
         }
         Pattern             prev2 = Pattern.Compile(((ExprSLASH2)e).left);
         LocationPathPattern locationPathPattern2 = (LocationPathPattern)Pattern.Compile(((ExprSLASH2)e).right);
         locationPathPattern2.SetPreviousPattern(prev2, true);
         return(locationPathPattern2);
     }
     else
     {
         if (e is XPathFunctionId)
         {
             ExprLiteral exprLiteral = ((XPathFunctionId)e).Id as ExprLiteral;
             return(new IdPattern(exprLiteral.Value));
         }
         if (e is XsltKey)
         {
             return(new KeyPattern((XsltKey)e));
         }
         return(null);
     }
 }
コード例 #2
0
        internal static Pattern Compile(Expression e)
        {
            if (e is ExprUNION)
            {
                return(new UnionPattern(
                           Compile(((ExprUNION)e).left),
                           Compile(((ExprUNION)e).right)
                           ));
            }

            if (e is ExprRoot)
            {
                return(new LocationPathPattern(
                           new NodeTypeTest(Axes.Self, XPathNodeType.Root)
                           ));
            }

            if (e is NodeTest)
            {
                return(new LocationPathPattern(
                           (NodeTest)e
                           ));
            }

            if (e is ExprFilter)
            {
                return(new LocationPathPattern(
                           (ExprFilter)e
                           ));
            }

            if (e is ExprSLASH)
            {
                Pattern             p0 = Compile(((ExprSLASH)e).left);
                LocationPathPattern p1
                    = (LocationPathPattern)Compile(((ExprSLASH)e).right);

                p1.SetPreviousPattern(p0, false);
                return(p1);
            }

            if (e is ExprSLASH2)
            {
                if (((ExprSLASH2)e).left is ExprRoot)
                {
                    return(Compile(((ExprSLASH2)e).right));
                }

                Pattern             p0 = Compile(((ExprSLASH2)e).left);
                LocationPathPattern p1
                    = (LocationPathPattern)Compile(((ExprSLASH2)e).right);

                p1.SetPreviousPattern(p0, true);
                return(p1);
            }

            if (e is XPathFunctionId)
            {
                ExprLiteral id = ((XPathFunctionId)e).Id as ExprLiteral;
                return(new IdPattern(id.Value));
            }

            if (e is XsltKey)
            {
                return(new KeyPattern((XsltKey)e));
            }

            return(null);            // throw Exception outer this method.
        }