Search in sources :

Example 1 with ConditionalExpression

use of org.mozilla.javascript.ast.ConditionalExpression in project st-js by st-js.

the class RhinoJavaScriptBuilder method conditionalExpression.

/**
 * {@inheritDoc}
 */
@Override
public AstNode conditionalExpression(AstNode test, AstNode trueExpr, AstNode falseExpr) {
    ConditionalExpression c = new ConditionalExpression();
    c.setTestExpression(test);
    c.setTrueExpression(trueExpr);
    c.setFalseExpression(falseExpr);
    return c;
}
Also used : ConditionalExpression(org.mozilla.javascript.ast.ConditionalExpression)

Example 2 with ConditionalExpression

use of org.mozilla.javascript.ast.ConditionalExpression in project HL4A by HL4A.

the class Parser method condExpr.

private AstNode condExpr() throws IOException {
    AstNode pn = orExpr();
    if (matchToken(Token.HOOK)) {
        int line = ts.lineno;
        int qmarkPos = ts.tokenBeg, colonPos = -1;
        /*
             * Always accept the 'in' operator in the middle clause of a ternary,
             * where it's unambiguous, even if we might be parsing the init of a
             * for statement.
             */
        boolean wasInForInit = inForInit;
        inForInit = false;
        AstNode ifTrue;
        try {
            ifTrue = assignExpr();
        } finally {
            inForInit = wasInForInit;
        }
        if (mustMatchToken(Token.COLON, "msg.no.colon.cond"))
            colonPos = ts.tokenBeg;
        AstNode ifFalse = assignExpr();
        int beg = pn.getPosition(), len = getNodeEnd(ifFalse) - beg;
        ConditionalExpression ce = new ConditionalExpression(beg, len);
        ce.setLineno(line);
        ce.setTestExpression(pn);
        ce.setTrueExpression(ifTrue);
        ce.setFalseExpression(ifFalse);
        ce.setQuestionMarkPosition(qmarkPos - beg);
        ce.setColonPosition(colonPos - beg);
        pn = ce;
    }
    return pn;
}
Also used : ConditionalExpression(org.mozilla.javascript.ast.ConditionalExpression) AstNode(org.mozilla.javascript.ast.AstNode)

Aggregations

ConditionalExpression (org.mozilla.javascript.ast.ConditionalExpression)2 AstNode (org.mozilla.javascript.ast.AstNode)1