Search in sources :

Example 6 with XPathExpr

use of org.eclipse.wst.xml.xpath2.processor.internal.ast.XPathExpr in project webtools.sourceediting by eclipse.

the class StaticNameResolver method visit.

/**
 * Validate an xpath expression.
 *
 * @param e
 *            is the expression.
 * @return null.
 */
public Object visit(XPathExpr e) {
    XPathExpr xp = e;
    boolean firstStep = true;
    while (xp != null) {
        if (firstStep && xp.slashes() != 0)
            _rootUsed = true;
        firstStep = false;
        StepExpr se = xp.expr();
        if (se != null)
            se.accept(this);
        xp = xp.next();
    }
    return null;
}
Also used : StepExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.StepExpr) XPathExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.XPathExpr)

Example 7 with XPathExpr

use of org.eclipse.wst.xml.xpath2.processor.internal.ast.XPathExpr in project webtools.sourceediting by eclipse.

the class DefaultEvaluator method visit.

/**
 * visit XPath expression
 *
 * @param e
 *            is the XPath expression.
 * @return a new function
 */
public Object visit(XPathExpr e) {
    XPathExpr xp = e;
    ResultSequence rs = null;
    Focus original_focus = focus();
    // do all the steps
    while (xp != null) {
        StepExpr se = xp.expr();
        if (se != null) {
            // this is not the first step
            if (rs != null) {
                // results...
                if (rs.size() == 0)
                    break;
                // nodes!
                for (Iterator i = rs.iterator(); i.hasNext(); ) {
                    AnyType item = (AnyType) i.next();
                    if (!(item instanceof NodeType)) {
                        report_error(TypeError.step_conatins_atoms(null));
                        // unreach
                        return null;
                    }
                }
                // check if we got a //
                if (xp.slashes() == 2) {
                    rs = descendant_or_self_node(rs);
                    if (rs.size() == 0)
                        break;
                }
                // make result of previous step the new
                // focus
                set_focus(new Focus(rs));
                // do the step for all item in context
                rs = do_step(se);
            } else // this is first step...
            // note... we may be called from upstream...
            // like in the expression sorbo/*[2] ... we may
            // be called to evaluate the 2... the caller
            // will iterate through the whole outer focus
            // for us
            {
                // XXX ???
                if (xp.slashes() == 1) {
                    rs = root_self_node();
                    set_focus(new Focus(rs));
                    rs = do_step(se);
                } else if (xp.slashes() == 2) {
                    rs = root_self_node();
                    rs = descendant_or_self_node(rs);
                    set_focus(new Focus(rs));
                    rs = do_step(se);
                } else
                    rs = (ResultSequence) se.accept(this);
            }
        } else // the expression is "/"
        {
            assert xp.slashes() == 1;
            rs = root_self_node();
        }
        xp = xp.next();
    }
    // restore focus
    set_focus(original_focus);
    return rs;
}
Also used : ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) Focus(org.eclipse.wst.xml.xpath2.processor.internal.Focus) NodeType(org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType) StepExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.StepExpr) ListIterator(java.util.ListIterator) Iterator(java.util.Iterator) AnyType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType) XPathExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.XPathExpr)

Example 8 with XPathExpr

use of org.eclipse.wst.xml.xpath2.processor.internal.ast.XPathExpr in project webtools.sourceediting by eclipse.

the class DefaultEvaluator method do_predicate.

// do the predicate for all items in focus
private ResultSequence do_predicate(Collection exprs) {
    ResultBuffer rs = new ResultBuffer();
    Focus focus = focus();
    int original_cp = focus.position();
    // check if predicate is single numeric constant
    if (exprs.size() == 1) {
        Expr expr = (Expr) exprs.iterator().next();
        if (expr instanceof XPathExpr) {
            XPathExpr xpe = (XPathExpr) expr;
            if (xpe.next() == null && xpe.slashes() == 0 && xpe.expr() instanceof FilterExpr) {
                FilterExpr fex = (FilterExpr) xpe.expr();
                if (fex.primary() instanceof IntegerLiteral) {
                    int pos = (((IntegerLiteral) fex.primary()).value().int_value()).intValue();
                    if (pos <= focus.last() && pos > 0) {
                        focus.set_position(pos);
                        rs.add(focus.context_item());
                    }
                    focus.set_position(original_cp);
                    return rs.getSequence();
                }
            }
        }
    }
    // go through all elements
    while (true) {
        // do the predicate
        // XXX saxon doesn't allow for predicates to have
        // commas... but XPath 2.0 spec seems to do
        ResultSequence res = do_expr(exprs.iterator());
        // in the sequence
        if (predicate_truth(res))
            rs.add(focus().context_item());
        if (!focus.advance_cp())
            break;
    }
    // restore
    focus.set_position(original_cp);
    return rs.getSequence();
}
Also used : QuantifiedExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.QuantifiedExpr) IfExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.IfExpr) OrExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.OrExpr) TreatAsExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.TreatAsExpr) ForExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.ForExpr) ParExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.ParExpr) DivExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.DivExpr) SubExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.SubExpr) CastExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.CastExpr) RangeExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.RangeExpr) InstOfExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.InstOfExpr) IntersectExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.IntersectExpr) IDivExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.IDivExpr) AddExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.AddExpr) CmpExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.CmpExpr) PipeExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.PipeExpr) BinExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.BinExpr) MulExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.MulExpr) XPathExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.XPathExpr) Expr(org.eclipse.wst.xml.xpath2.processor.internal.ast.Expr) MinusExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.MinusExpr) FilterExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.FilterExpr) CastableExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.CastableExpr) PlusExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.PlusExpr) AndExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.AndExpr) StepExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.StepExpr) CntxItemExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.CntxItemExpr) ExceptExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.ExceptExpr) UnionExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.UnionExpr) ModExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.ModExpr) FilterExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.FilterExpr) ResultBuffer(org.eclipse.wst.xml.xpath2.api.ResultBuffer) Focus(org.eclipse.wst.xml.xpath2.processor.internal.Focus) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) IntegerLiteral(org.eclipse.wst.xml.xpath2.processor.internal.ast.IntegerLiteral) XPathExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.XPathExpr)

Example 9 with XPathExpr

use of org.eclipse.wst.xml.xpath2.processor.internal.ast.XPathExpr in project webtools.sourceediting by eclipse.

the class Normalizer method make_convert_operand.

private XPathExpr make_convert_operand(XPathExpr arg1, XPathExpr arg2) {
    Collection args = new ArrayList();
    args.add(arg1);
    args.add(arg2);
    return make_function(new QName("fs", "convert-operand", OpFunctionLibrary.XPATH_OP_NS), args);
}
Also used : QName(org.eclipse.wst.xml.xpath2.processor.internal.types.QName) ArrayList(java.util.ArrayList) Collection(java.util.Collection)

Example 10 with XPathExpr

use of org.eclipse.wst.xml.xpath2.processor.internal.ast.XPathExpr in project webtools.sourceediting by eclipse.

the class Normalizer method make_convert_binop.

// fs:fname( fs:convert-operand( fn:data(ARG1), 1.0E0 ),
// fs:convert-operand( fn:data(ARG2), 1.0E0 )
// )
private XPathExpr make_convert_binop(BinExpr e, XPathExpr convarg, QName name) {
    Collection args = normalize_bin_args(e);
    XPathExpr[] args_arr = new XPathExpr[2];
    int j = 0;
    for (Iterator i = args.iterator(); i.hasNext(); ) {
        args_arr[j] = (XPathExpr) i.next();
        j++;
    }
    Collection argsfname = new ArrayList();
    for (j = 0; j < 2; j++) {
        XPathExpr arg = make_convert_operand(args_arr[j], convarg);
        argsfname.add(arg);
    }
    return make_function(name, argsfname);
}
Also used : Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) Collection(java.util.Collection) XPathExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.XPathExpr)

Aggregations

XPathExpr (org.eclipse.wst.xml.xpath2.processor.internal.ast.XPathExpr)9 StepExpr (org.eclipse.wst.xml.xpath2.processor.internal.ast.StepExpr)6 ArrayList (java.util.ArrayList)5 Collection (java.util.Collection)3 Iterator (java.util.Iterator)2 ResultSequence (org.eclipse.wst.xml.xpath2.api.ResultSequence)2 Focus (org.eclipse.wst.xml.xpath2.processor.internal.Focus)2 AnyKindTest (org.eclipse.wst.xml.xpath2.processor.internal.ast.AnyKindTest)2 AxisStep (org.eclipse.wst.xml.xpath2.processor.internal.ast.AxisStep)2 FilterExpr (org.eclipse.wst.xml.xpath2.processor.internal.ast.FilterExpr)2 ForwardStep (org.eclipse.wst.xml.xpath2.processor.internal.ast.ForwardStep)2 ReverseStep (org.eclipse.wst.xml.xpath2.processor.internal.ast.ReverseStep)2 Step (org.eclipse.wst.xml.xpath2.processor.internal.ast.Step)2 StringReader (java.io.StringReader)1 ListIterator (java.util.ListIterator)1 Symbol (java_cup.runtime.Symbol)1 ResultBuffer (org.eclipse.wst.xml.xpath2.api.ResultBuffer)1 StaticError (org.eclipse.wst.xml.xpath2.processor.StaticError)1 XPathParserException (org.eclipse.wst.xml.xpath2.processor.XPathParserException)1 XPath (org.eclipse.wst.xml.xpath2.processor.ast.XPath)1