Search in sources :

Example 1 with ArrayComprehension

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

the class Parser method arrayComprehension.

/**
 * Parse a JavaScript 1.7 Array comprehension.
 * @param result the first expression after the opening left-bracket
 * @param pos start of LB token that begins the array comprehension
 * @return the array comprehension or an error node
 */
private AstNode arrayComprehension(AstNode result, int pos) throws IOException {
    List<ArrayComprehensionLoop> loops = new ArrayList<ArrayComprehensionLoop>();
    while (peekToken() == Token.FOR) {
        loops.add(arrayComprehensionLoop());
    }
    int ifPos = -1;
    ConditionData data = null;
    if (peekToken() == Token.IF) {
        consumeToken();
        ifPos = ts.tokenBeg - pos;
        data = condition();
    }
    mustMatchToken(Token.RB, "msg.no.bracket.arg");
    ArrayComprehension pn = new ArrayComprehension(pos, ts.tokenEnd - pos);
    pn.setResult(result);
    pn.setLoops(loops);
    if (data != null) {
        pn.setIfPosition(ifPos);
        pn.setFilter(data.condition);
        pn.setFilterLp(data.lp - pos);
        pn.setFilterRp(data.rp - pos);
    }
    return pn;
}
Also used : ArrayComprehensionLoop(org.mozilla.javascript.ast.ArrayComprehensionLoop) ArrayList(java.util.ArrayList) ArrayComprehension(org.mozilla.javascript.ast.ArrayComprehension)

Aggregations

ArrayList (java.util.ArrayList)1 ArrayComprehension (org.mozilla.javascript.ast.ArrayComprehension)1 ArrayComprehensionLoop (org.mozilla.javascript.ast.ArrayComprehensionLoop)1