Example #1
0
        private static void  parseBalanced(ASTNode node, SubNodeFactory snf, int lToken, int rToken)
        {
            if (node is ASTNodeAbstractExpr)
            {
                ASTNodeAbstractExpr absNode = (ASTNodeAbstractExpr)node;

                int i = 0;
                while (i < absNode.content.Count)
                {
                    int type = absNode.getTokenType(i);
                    if (type == rToken)
                    {
                        throw new XPathSyntaxException("Unbalanced brackets or parentheses!");                         //unbalanced
                    }
                    else if (type == lToken)
                    {
                        int j = absNode.indexOfBalanced(i, rToken, lToken, rToken);
                        if (j == -1)
                        {
                            throw new XPathSyntaxException("mismatched brackets or parentheses!");                             //mismatched
                        }

                        absNode.condense(snf.newNode(absNode.extract(i + 1, j)), i, j + 1);
                    }
                    i++;
                }
            }

            //UPGRADE_TODO: Method 'java.util.Enumeration.hasMoreElements' was converted to 'System.Collections.IEnumerator.MoveNext' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilEnumerationhasMoreElements'"
            for (System.Collections.IEnumerator e = node.Children.GetEnumerator(); e.MoveNext();)
            {
                //UPGRADE_TODO: Method 'java.util.Enumeration.nextElement' was converted to 'System.Collections.IEnumerator.Current' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilEnumerationnextElement'"
                parseBalanced((ASTNode)e.Current, snf, lToken, rToken);
            }
        }
Example #2
0
        //find and condense all function calls in the current level, then do the same in lower levels
        private static void  parseFuncCalls(ASTNode node)
        {
            if (node is ASTNodeAbstractExpr)
            {
                ASTNodeAbstractExpr absNode = (ASTNodeAbstractExpr)node;

                int i = 0;
                while (i < absNode.content.Count - 1)
                {
                    if (absNode.getTokenType(i + 1) == Token.LPAREN && absNode.getTokenType(i) == Token.QNAME)
                    {
                        condenseFuncCall(absNode, i);
                    }
                    i++;
                }
            }

            //UPGRADE_TODO: Method 'java.util.Enumeration.hasMoreElements' was converted to 'System.Collections.IEnumerator.MoveNext' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilEnumerationhasMoreElements'"
            for (System.Collections.IEnumerator e = node.Children.GetEnumerator(); e.MoveNext();)
            {
                //UPGRADE_TODO: Method 'java.util.Enumeration.nextElement' was converted to 'System.Collections.IEnumerator.Current' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilEnumerationnextElement'"
                parseFuncCalls((ASTNode)e.Current);
            }
        }
Example #3
0
        private static void  parseUnaryOp(ASTNode node, int op)
        {
            if (node is ASTNodeAbstractExpr)
            {
                ASTNodeAbstractExpr absNode = (ASTNodeAbstractExpr)node;

                if (absNode.content.Count > 0 && absNode.getTokenType(0) == op)
                {
                    ASTNodeUnaryOp unOp = new ASTNodeUnaryOp();
                    unOp.op   = op;
                    unOp.expr = (absNode.content.Count > 1?absNode.extract(1, absNode.content.Count):new ASTNodeAbstractExpr());
                    absNode.condense(unOp, 0, absNode.content.Count);
                }
            }

            //UPGRADE_TODO: Method 'java.util.Enumeration.hasMoreElements' was converted to 'System.Collections.IEnumerator.MoveNext' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilEnumerationhasMoreElements'"
            for (System.Collections.IEnumerator e = node.Children.GetEnumerator(); e.MoveNext();)
            {
                //UPGRADE_TODO: Method 'java.util.Enumeration.nextElement' was converted to 'System.Collections.IEnumerator.Current' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilEnumerationnextElement'"
                parseUnaryOp((ASTNode)e.Current, op);
            }
        }
Example #4
0
 //true if 'node' is potentially a step, as opposed to a filter expr
 private static bool isStep(ASTNodeAbstractExpr node)
 {
     if (node.content.Count > 0)
     {
         int type = node.getTokenType(0);
         if (type == Token.QNAME || type == Token.WILDCARD || type == Token.NSWILDCARD || type == Token.AT || type == Token.DOT || type == Token.DBL_DOT)
         {
             return(true);
         }
         else if (node.content[0] is ASTNodeFunctionCall)
         {
             System.String name = ((ASTNodeFunctionCall)node.content[0]).name.ToString();
             return(name.Equals("node") || name.Equals("text") || name.Equals("comment") || name.Equals("processing-instruction"));
         }
         else
         {
             return(false);
         }
     }
     else
     {
         return(false);
     }
 }
Example #5
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);
        }