Search in sources :

Example 6 with Expr

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

the class DefaultEvaluator method do_expr.

// basically the comma operator...
private ResultSequence do_expr(Iterator i) {
    ResultSequence rs = null;
    ResultBuffer buffer = null;
    while (i.hasNext()) {
        Expr e = (Expr) i.next();
        ResultSequence result = (ResultSequence) e.accept(this);
        if (rs == null && buffer == null)
            rs = result;
        else {
            if (buffer == null) {
                buffer = new ResultBuffer();
                buffer.concat(rs);
                rs = null;
            }
            buffer.concat(result);
        }
    }
    if (buffer != null) {
        return buffer.getSequence();
    } else if (rs != null) {
        return rs;
    } else
        return ResultBuffer.EMPTY;
}
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) ResultBuffer(org.eclipse.wst.xml.xpath2.api.ResultBuffer) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence)

Example 7 with Expr

use of org.eclipse.wst.xml.xpath2.processor.internal.ast.Expr in project webservices-axiom by apache.

the class PsychoPathTest method evaluate.

private static ResultSequence evaluate(String xpath) throws Exception {
    InputStream is = PsychoPathTest.class.getResourceAsStream("test.xml");
    try {
        OMFactory factory = OMAbstractFactory.getMetaFactory(OMAbstractFactory.FEATURE_DOM).getOMFactory();
        Document doc = (Document) OMXMLBuilderFactory.createOMBuilder(factory, is).getDocument();
        StaticContextBuilder scb = new StaticContextBuilder();
        XPath2Expression expr = new Engine().parseExpression(xpath, scb);
        return expr.evaluate(new DynamicContextBuilder(scb), new Object[] { doc });
    } finally {
        is.close();
    }
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) StaticContextBuilder(org.eclipse.wst.xml.xpath2.processor.util.StaticContextBuilder) InputStream(java.io.InputStream) DynamicContextBuilder(org.eclipse.wst.xml.xpath2.processor.util.DynamicContextBuilder) Document(org.w3c.dom.Document) XPath2Expression(org.eclipse.wst.xml.xpath2.api.XPath2Expression) Engine(org.eclipse.wst.xml.xpath2.processor.Engine)

Example 8 with Expr

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

the class DefaultEvaluator method do_for_each.

private void do_for_each(ListIterator iter, Expr finalexpr, ResultBuffer destination) {
    // we have more vars to bind...
    if (iter.hasNext()) {
        VarExprPair ve = (VarExprPair) iter.next();
        // evaluate binding sequence
        ResultSequence rs = (ResultSequence) ve.expr().accept(this);
        // XXX
        if (rs.empty()) {
            iter.previous();
            return;
        }
        QName varname = ve.varname();
        for (Iterator i = rs.iterator(); i.hasNext(); ) {
            AnyType item = (AnyType) i.next();
            pushScope(varname, item);
            do_for_each(iter, finalexpr, destination);
            popScope();
        }
        iter.previous();
    } else // we finally got to do the "last expression"
    {
        destination.concat((ResultSequence) finalexpr.accept(this));
    }
}
Also used : ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) QName(org.eclipse.wst.xml.xpath2.processor.internal.types.QName) ListIterator(java.util.ListIterator) Iterator(java.util.Iterator) AnyType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType) VarExprPair(org.eclipse.wst.xml.xpath2.processor.internal.ast.VarExprPair)

Example 9 with Expr

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

the class DefaultEvaluator method visit.

/**
 * visit castable expression
 *
 * @param cexp
 *            is the castable expression.
 * @return a new function
 */
public Object visit(CastableExpr cexp) {
    boolean castable = false;
    try {
        CastExpr ce = new CastExpr((Expr) cexp.left(), (SingleType) cexp.right());
        visit(ce);
        castable = true;
    } catch (Throwable t) {
        castable = false;
    }
    return ResultSequenceFactory.create_new(new XSBoolean(castable));
}
Also used : XSBoolean(org.eclipse.wst.xml.xpath2.processor.internal.types.XSBoolean) CastExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.CastExpr)

Example 10 with Expr

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

the class DefaultEvaluator method do_for_all.

// XXX ugly
// type: 0 = for [return == "correct"]
// 1 = for all [return false, return empty on true]
// 2 = there exists [return true, return empty on false]
private XSBoolean do_for_all(ListIterator iter, Expr finalexpr) {
    // we have more vars to bind...
    if (iter.hasNext()) {
        VarExprPair ve = (VarExprPair) iter.next();
        // evaluate binding sequence
        ResultSequence rs = (ResultSequence) ve.expr().accept(this);
        QName varname = ve.varname();
        try {
            for (Iterator i = rs.iterator(); i.hasNext(); ) {
                AnyType item = (AnyType) i.next();
                pushScope(varname, item);
                XSBoolean effbool = do_for_all(iter, finalexpr);
                popScope();
                // out what to do with it
                if (!effbool.value())
                    return XSBoolean.FALSE;
            }
        } finally {
            iter.previous();
        }
        return XSBoolean.TRUE;
    } else // we finally got to do the "last expression"
    {
        return effective_boolean_value((ResultSequence) finalexpr.accept(this));
    }
}
Also used : ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) QName(org.eclipse.wst.xml.xpath2.processor.internal.types.QName) XSBoolean(org.eclipse.wst.xml.xpath2.processor.internal.types.XSBoolean) ListIterator(java.util.ListIterator) Iterator(java.util.Iterator) AnyType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType) VarExprPair(org.eclipse.wst.xml.xpath2.processor.internal.ast.VarExprPair)

Aggregations

CastExpr (org.eclipse.wst.xml.xpath2.processor.internal.ast.CastExpr)14 AddExpr (org.eclipse.wst.xml.xpath2.processor.internal.ast.AddExpr)13 AndExpr (org.eclipse.wst.xml.xpath2.processor.internal.ast.AndExpr)13 CastableExpr (org.eclipse.wst.xml.xpath2.processor.internal.ast.CastableExpr)13 CmpExpr (org.eclipse.wst.xml.xpath2.processor.internal.ast.CmpExpr)13 CntxItemExpr (org.eclipse.wst.xml.xpath2.processor.internal.ast.CntxItemExpr)13 DivExpr (org.eclipse.wst.xml.xpath2.processor.internal.ast.DivExpr)13 ExceptExpr (org.eclipse.wst.xml.xpath2.processor.internal.ast.ExceptExpr)13 Expr (org.eclipse.wst.xml.xpath2.processor.internal.ast.Expr)13 FilterExpr (org.eclipse.wst.xml.xpath2.processor.internal.ast.FilterExpr)13 ForExpr (org.eclipse.wst.xml.xpath2.processor.internal.ast.ForExpr)13 IDivExpr (org.eclipse.wst.xml.xpath2.processor.internal.ast.IDivExpr)13 IfExpr (org.eclipse.wst.xml.xpath2.processor.internal.ast.IfExpr)13 InstOfExpr (org.eclipse.wst.xml.xpath2.processor.internal.ast.InstOfExpr)13 IntersectExpr (org.eclipse.wst.xml.xpath2.processor.internal.ast.IntersectExpr)13 MinusExpr (org.eclipse.wst.xml.xpath2.processor.internal.ast.MinusExpr)13 ModExpr (org.eclipse.wst.xml.xpath2.processor.internal.ast.ModExpr)13 MulExpr (org.eclipse.wst.xml.xpath2.processor.internal.ast.MulExpr)13 OrExpr (org.eclipse.wst.xml.xpath2.processor.internal.ast.OrExpr)13 ParExpr (org.eclipse.wst.xml.xpath2.processor.internal.ast.ParExpr)13