Beispiel #1
0
 internal NodeSelectCriteria(QueryAxisType axis, NodeQName qname, QueryNodeType nodeType)
 {
     this.axis      = QueryDataModel.GetAxis(axis);
     this.qname     = qname;
     this.qnameType = qname.GetQNameType();
     this.type      = nodeType;
 }
 internal NodeSelectCriteria(QueryAxisType axis, NodeQName qname, QueryNodeType nodeType)
 {
     this.axis = QueryDataModel.GetAxis(axis);
     this.qname = qname;
     this.qnameType = qname.GetQNameType();
     this.type = nodeType;
 }
Beispiel #3
0
        NodeSelectCriteria ParseNodeTest(QueryAxisType axisType)
        {
            Fx.Assert(QueryAxisType.None != axisType, "");

            QueryAxis  axis = QueryDataModel.GetAxis(axisType);
            XPathToken token;
            NodeQName  qname = NodeQName.Empty;

            if (null != (token = this.NextTokenClass(XPathTokenID.NameTest)))
            {
                switch (token.TokenID)
                {
                default:
                    this.ThrowError(QueryCompileError.UnexpectedToken);
                    break;

                case XPathTokenID.Wildcard:
                    qname = new NodeQName(QueryDataModel.Wildcard, QueryDataModel.Wildcard);
                    break;

                case XPathTokenID.NameTest:
                    qname = this.QualifyName(token.Prefix, token.Name);
                    break;

                case XPathTokenID.NameWildcard:
                    qname = this.QualifyName(token.Prefix, QueryDataModel.Wildcard);
                    break;
                }
            }

            QueryNodeType nodeType = QueryNodeType.Any;

            if (qname.IsEmpty)
            {
                // Check for nodeTests
                if (null == (token = this.NextTokenClass(XPathTokenID.NodeType)))
                {
                    // Not a NodeTest either.
                    return(null);
                }

                switch (token.TokenID)
                {
                default:
                    this.ThrowError(QueryCompileError.UnsupportedNodeTest);
                    break;

                case XPathTokenID.Comment:
                    nodeType = QueryNodeType.Comment;
                    break;

                case XPathTokenID.Text:
                    nodeType = QueryNodeType.Text;
                    break;

                case XPathTokenID.Processing:
                    nodeType = QueryNodeType.Processing;
                    break;

                case XPathTokenID.Node:
                    nodeType = QueryNodeType.All;
                    break;
                }

                // Make sure the nodes being selected CAN actually be selected from this axis
                if (0 == (axis.ValidNodeTypes & nodeType))
                {
                    this.ThrowError(QueryCompileError.InvalidNodeType);
                }

                // Eat ()
                this.NextToken(XPathTokenID.LParen, QueryCompileError.InvalidNodeTest);
                this.NextToken(XPathTokenID.RParen, QueryCompileError.InvalidNodeTest);
            }
            else
            {
                nodeType = axis.PrincipalNodeType;
            }

            return(new NodeSelectCriteria(axisType, qname, nodeType));
        }
        private NodeSelectCriteria ParseNodeTest(QueryAxisType axisType)
        {
            QueryNodeType principalNodeType;
            QueryAxis     axis  = QueryDataModel.GetAxis(axisType);
            NodeQName     empty = NodeQName.Empty;
            XPathToken    token = this.NextTokenClass(XPathTokenID.NameTest);

            if (token != null)
            {
                switch (token.TokenID)
                {
                case XPathTokenID.Wildcard:
                    empty = new NodeQName(QueryDataModel.Wildcard, QueryDataModel.Wildcard);
                    goto Label_0085;

                case XPathTokenID.NameWildcard:
                    empty = this.QualifyName(token.Prefix, QueryDataModel.Wildcard);
                    goto Label_0085;

                case XPathTokenID.NameTest:
                    empty = this.QualifyName(token.Prefix, token.Name);
                    goto Label_0085;
                }
                this.ThrowError(QueryCompileError.UnexpectedToken);
            }
Label_0085:
            principalNodeType = QueryNodeType.Any;
            if (!empty.IsEmpty)
            {
                principalNodeType = axis.PrincipalNodeType;
            }
            else
            {
                token = this.NextTokenClass(XPathTokenID.NodeType);
                if (token == null)
                {
                    return(null);
                }
                switch (token.TokenID)
                {
                case XPathTokenID.Comment:
                    principalNodeType = QueryNodeType.Comment;
                    break;

                case XPathTokenID.Text:
                    principalNodeType = QueryNodeType.Text;
                    break;

                case XPathTokenID.Processing:
                    principalNodeType = QueryNodeType.Processing;
                    break;

                case XPathTokenID.Node:
                    principalNodeType = QueryNodeType.All;
                    break;

                default:
                    this.ThrowError(QueryCompileError.UnsupportedNodeTest);
                    break;
                }
                if (((byte)(axis.ValidNodeTypes & principalNodeType)) == 0)
                {
                    this.ThrowError(QueryCompileError.InvalidNodeType);
                }
                this.NextToken(XPathTokenID.LParen, QueryCompileError.InvalidNodeTest);
                this.NextToken(XPathTokenID.RParen, QueryCompileError.InvalidNodeTest);
            }
            return(new NodeSelectCriteria(axisType, empty, principalNodeType));
        }