Search in sources :

Example 1 with BreakStatement

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

the class Parser method breakStatement.

private BreakStatement breakStatement() throws IOException {
    if (currentToken != Token.BREAK)
        codeBug();
    consumeToken();
    int lineno = ts.lineno, pos = ts.tokenBeg, end = ts.tokenEnd;
    Name breakLabel = null;
    if (peekTokenOrEOL() == Token.NAME) {
        breakLabel = createNameNode();
        end = getNodeEnd(breakLabel);
    }
    // matchJumpLabelName only matches if there is one
    LabeledStatement labels = matchJumpLabelName();
    // always use first label as target
    Jump breakTarget = labels == null ? null : labels.getFirstLabel();
    if (breakTarget == null && breakLabel == null) {
        if (loopAndSwitchSet == null || loopAndSwitchSet.size() == 0) {
            if (breakLabel == null) {
                reportError("msg.bad.break", pos, end - pos);
            }
        } else {
            breakTarget = loopAndSwitchSet.get(loopAndSwitchSet.size() - 1);
        }
    }
    BreakStatement pn = new BreakStatement(pos, end - pos);
    pn.setBreakLabel(breakLabel);
    // can be null if it's a bad break in error-recovery mode
    if (breakTarget != null)
        pn.setBreakTarget(breakTarget);
    pn.setLineno(lineno);
    return pn;
}
Also used : BreakStatement(org.mozilla.javascript.ast.BreakStatement) LabeledStatement(org.mozilla.javascript.ast.LabeledStatement) Jump(org.mozilla.javascript.ast.Jump) Name(org.mozilla.javascript.ast.Name)

Example 2 with BreakStatement

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

the class RhinoJavaScriptBuilder method breakStatement.

/**
 * {@inheritDoc}
 */
@Override
public AstNode breakStatement(AstNode label) {
    BreakStatement b = new BreakStatement();
    b.setBreakLabel(cast(label, Name.class));
    return b;
}
Also used : BreakStatement(org.mozilla.javascript.ast.BreakStatement) Name(org.mozilla.javascript.ast.Name)

Aggregations

BreakStatement (org.mozilla.javascript.ast.BreakStatement)2 Name (org.mozilla.javascript.ast.Name)2 Jump (org.mozilla.javascript.ast.Jump)1 LabeledStatement (org.mozilla.javascript.ast.LabeledStatement)1