Exemplo n.º 1
0
        //i == index of token beginning func call (func name)
        private static void  condenseFuncCall(ASTNodeAbstractExpr node, int funcStart)
        {
            ASTNodeFunctionCall funcCall = new ASTNodeFunctionCall((XPathQName)node.getToken(funcStart).val);

            int funcEnd = node.indexOfBalanced(funcStart + 1, Token.RPAREN, Token.LPAREN, Token.RPAREN);

            if (funcEnd == -1)
            {
                throw new XPathSyntaxException("Mismatched brackets or parentheses");                 //mismatched parens
            }

            ASTNodeAbstractExpr.Partition args = node.partitionBalanced(Token.COMMA, funcStart + 1, Token.LPAREN, Token.RPAREN);
            if (args.pieces.Count == 1 && ((ASTNodeAbstractExpr)args.pieces[0]).content.Count == 0)
            {
                //no arguments
            }
            else
            {
                //process arguments
                funcCall.args = args.pieces;
            }

            node.condense(funcCall, funcStart, funcEnd + 1);
        }
Exemplo n.º 2
0
        //please kill me
        private static ASTNodePathStep parseStep(ASTNodeAbstractExpr node)
        {
            ASTNodePathStep step = new ASTNodePathStep();

            if (node.content.Count == 1 && node.getTokenType(0) == Token.DOT)
            {
                step.axisType     = ASTNodePathStep.AXIS_TYPE_NULL;
                step.nodeTestType = ASTNodePathStep.NODE_TEST_TYPE_ABBR_DOT;
            }
            else if (node.content.Count == 1 && node.getTokenType(0) == Token.DBL_DOT)
            {
                step.axisType     = ASTNodePathStep.AXIS_TYPE_NULL;
                step.nodeTestType = ASTNodePathStep.NODE_TEST_TYPE_ABBR_DBL_DOT;
            }
            else
            {
                int i = 0;
                if (node.content.Count > 0 && node.getTokenType(0) == Token.AT)
                {
                    step.axisType = ASTNodePathStep.AXIS_TYPE_ABBR;
                    i            += 1;
                }
                else if (node.content.Count > 1 && node.getTokenType(0) == Token.QNAME && node.getTokenType(1) == Token.DBL_COLON)
                {
                    int axisVal = ASTNodePathStep.validateAxisName(((XPathQName)node.getToken(0).val).ToString());
                    if (axisVal == -1)
                    {
                        throw new XPathSyntaxException("Invalid Axis: " + ((XPathQName)node.getToken(0).val).ToString());
                    }
                    step.axisType = ASTNodePathStep.AXIS_TYPE_EXPLICIT;
                    step.axisVal  = axisVal;
                    i            += 2;
                }
                else
                {
                    step.axisType = ASTNodePathStep.AXIS_TYPE_NULL;
                }

                if (node.content.Count > i && node.getTokenType(i) == Token.WILDCARD)
                {
                    step.nodeTestType = ASTNodePathStep.NODE_TEST_TYPE_WILDCARD;
                }
                else if (node.content.Count > i && node.getTokenType(i) == Token.NSWILDCARD)
                {
                    step.nodeTestType      = ASTNodePathStep.NODE_TEST_TYPE_NSWILDCARD;
                    step.nodeTestNamespace = ((System.String)node.getToken(i).val);
                }
                else if (node.content.Count > i && node.getTokenType(i) == Token.QNAME)
                {
                    step.nodeTestType  = ASTNodePathStep.NODE_TEST_TYPE_QNAME;
                    step.nodeTestQName = (XPathQName)node.getToken(i).val;
                }
                else if (node.content.Count > i && node.content[i] is ASTNodeFunctionCall)
                {
                    if (!ASTNodePathStep.validateNodeTypeTest((ASTNodeFunctionCall)node.content[i]))
                    {
                        throw new XPathSyntaxException();
                    }
                    step.nodeTestType = ASTNodePathStep.NODE_TEST_TYPE_FUNC;
                    step.nodeTestFunc = (ASTNodeFunctionCall)node.content[i];
                }
                else
                {
                    throw new XPathSyntaxException();
                }
                i += 1;

                while (i < node.content.Count)
                {
                    if (node.content[i] is ASTNodePredicate)
                    {
                        step.predicates.Add(node.content[i]);
                    }
                    else
                    {
                        throw new XPathSyntaxException();
                    }
                    i++;
                }
            }

            return(step);
        }