Ejemplo n.º 1
0
        private static ASTNodeFilterExpr parseFilterExp(ASTNodeAbstractExpr node)
        {
            ASTNodeFilterExpr filt = new ASTNodeFilterExpr();
            int i;

            for (i = node.content.Count - 1; i >= 0; i--)
            {
                if (node.content[i] is ASTNodePredicate)
                {
                    filt.predicates.Insert(0, node.content[i]);
                }
                else
                {
                    break;
                }
            }

            if (filt.predicates.Count == 0)
            {
                return(null);
            }

            filt.expr = node.extract(0, i + 1);
            return(filt);
        }
Ejemplo n.º 2
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);
            }
        }