Exemplo n.º 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);
            }
        }
Exemplo n.º 2
0
        private static void  parseBinaryOp(ASTNode node, int[] ops, int associativity)
        {
            if (node is ASTNodeAbstractExpr)
            {
                ASTNodeAbstractExpr           absNode = (ASTNodeAbstractExpr)node;
                ASTNodeAbstractExpr.Partition part    = absNode.partition(ops, 0, absNode.content.Count);

                if (part.separators.Count == 0)
                {
                    //no occurrences of op
                }
                else
                {
                    ASTNodeBinaryOp binOp = new ASTNodeBinaryOp();
                    binOp.associativity = associativity;
                    binOp.exprs         = part.pieces;
                    binOp.ops           = part.separators;

                    absNode.condense(binOp, 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'"
                parseBinaryOp((ASTNode)e.Current, ops, associativity);
            }
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 4
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.º 5
0
        private static void  parsePathExpr(ASTNode node)
        {
            if (node is ASTNodeAbstractExpr)
            {
                ASTNodeAbstractExpr absNode = (ASTNodeAbstractExpr)node;
                int[] pathOps = new int[] { Token.SLASH, Token.DBL_SLASH };
                ASTNodeAbstractExpr.Partition part = absNode.partition(pathOps, 0, absNode.content.Count);

                if (part.separators.Count == 0)
                {
                    //filter expression or standalone step
                    if (isStep(absNode))
                    {
                        ASTNodePathStep step = parseStep(absNode);
                        ASTNodeLocPath  path = new ASTNodeLocPath();
                        path.clauses.Add(step);
                        absNode.condense(path, 0, absNode.content.Count);
                    }
                    else
                    {
                        //filter expr
                        ASTNodeFilterExpr filt = parseFilterExp(absNode);
                        if (filt != null)
                        {
                            absNode.condense(filt, 0, absNode.content.Count);
                        }
                    }
                }
                else
                {
                    //path expression (but first clause may be filter expr)
                    ASTNodeLocPath path = new ASTNodeLocPath();
                    path.separators = part.separators;

                    if (part.separators.Count == 1 && absNode.content.Count == 1 && vectInt(part.separators, 0) == Token.SLASH)
                    {
                        //empty absolute path
                    }
                    else
                    {
                        for (int i = 0; i < part.pieces.Count; i++)
                        {
                            ASTNodeAbstractExpr x = (ASTNodeAbstractExpr)part.pieces[i];
                            if (isStep(x))
                            {
                                ASTNodePathStep step = parseStep(x);
                                path.clauses.Add(step);
                            }
                            else
                            {
                                if (i == 0)
                                {
                                    if (x.content.Count == 0)
                                    {
                                        //absolute path expr; first clause is null
                                        /* do nothing */
                                    }
                                    else
                                    {
                                        //filter expr
                                        ASTNodeFilterExpr filt = parseFilterExp(x);
                                        if (filt != null)
                                        {
                                            path.clauses.Add(filt);
                                        }
                                        else
                                        {
                                            path.clauses.Add(x);
                                        }
                                    }
                                }
                                else
                                {
                                    throw new XPathSyntaxException("Unexpected beginning of path");
                                }
                            }
                        }
                    }
                    absNode.condense(path, 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'"
                parsePathExpr((ASTNode)e.Current);
            }
        }