Search in sources :

Example 1 with EmptyStatement

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

the class Parser method statementHelper.

private AstNode statementHelper() throws IOException {
    // If the statement is set, then it's been told its label by now.
    if (currentLabel != null && currentLabel.getStatement() != null)
        currentLabel = null;
    AstNode pn = null;
    int tt = peekToken(), pos = ts.tokenBeg;
    switch(tt) {
        case Token.IF:
            return ifStatement();
        case Token.SWITCH:
            return switchStatement();
        case Token.WHILE:
            return whileLoop();
        case Token.DO:
            return doLoop();
        case Token.FOR:
            return forLoop();
        case Token.TRY:
            return tryStatement();
        case Token.THROW:
            pn = throwStatement();
            break;
        case Token.BREAK:
            pn = breakStatement();
            break;
        case Token.CONTINUE:
            pn = continueStatement();
            break;
        case Token.WITH:
            if (this.inUseStrictDirective) {
                reportError("msg.no.with.strict");
            }
            return withStatement();
        case Token.CONST:
        case Token.VAR:
            consumeToken();
            int lineno = ts.lineno;
            pn = variables(currentToken, ts.tokenBeg, true);
            pn.setLineno(lineno);
            break;
        case Token.LET:
            pn = letStatement();
            if (pn instanceof VariableDeclaration && peekToken() == Token.SEMI)
                break;
            return pn;
        case Token.RETURN:
        case Token.YIELD:
            pn = returnOrYield(tt, false);
            break;
        case Token.DEBUGGER:
            consumeToken();
            pn = new KeywordLiteral(ts.tokenBeg, ts.tokenEnd - ts.tokenBeg, tt);
            pn.setLineno(ts.lineno);
            break;
        case Token.LC:
            return block();
        case Token.ERROR:
            consumeToken();
            return makeErrorNode();
        case Token.SEMI:
            consumeToken();
            pos = ts.tokenBeg;
            pn = new EmptyStatement(pos, ts.tokenEnd - pos);
            pn.setLineno(ts.lineno);
            return pn;
        case Token.FUNCTION:
            consumeToken();
            return function(FunctionNode.FUNCTION_EXPRESSION_STATEMENT);
        case Token.DEFAULT:
            pn = defaultXmlNamespace();
            break;
        case Token.NAME:
            pn = nameOrLabel();
            if (pn instanceof ExpressionStatement)
                break;
            // LabeledStatement
            return pn;
        default:
            lineno = ts.lineno;
            pn = new ExpressionStatement(expr(), !insideFunction());
            pn.setLineno(lineno);
            break;
    }
    autoInsertSemicolon(pn);
    return pn;
}
Also used : KeywordLiteral(org.mozilla.javascript.ast.KeywordLiteral) ExpressionStatement(org.mozilla.javascript.ast.ExpressionStatement) EmptyStatement(org.mozilla.javascript.ast.EmptyStatement) VariableDeclaration(org.mozilla.javascript.ast.VariableDeclaration) AstNode(org.mozilla.javascript.ast.AstNode)

Example 2 with EmptyStatement

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

the class Parser method statement.

private AstNode statement() throws IOException {
    int pos = ts.tokenBeg;
    try {
        AstNode pn = statementHelper();
        if (pn != null) {
            if (compilerEnv.isStrictMode() && !pn.hasSideEffects()) {
                int beg = pn.getPosition();
                beg = Math.max(beg, lineBeginningFor(beg));
                addStrictWarning(pn instanceof EmptyStatement ? "msg.extra.trailing.semi" : "msg.no.side.effects", "", beg, nodeEnd(pn) - beg);
            }
            return pn;
        }
    } catch (ParserException e) {
    // an ErrorNode was added to the ErrorReporter
    }
    // error:  skip ahead to a probable statement boundary
    guessingStatementEnd: for (; ; ) {
        int tt = peekTokenOrEOL();
        consumeToken();
        switch(tt) {
            case Token.ERROR:
            case Token.EOF:
            case Token.EOL:
            case Token.SEMI:
                break guessingStatementEnd;
        }
    }
    // something different here.
    return new EmptyStatement(pos, ts.tokenBeg - pos);
}
Also used : EmptyStatement(org.mozilla.javascript.ast.EmptyStatement) AstNode(org.mozilla.javascript.ast.AstNode)

Aggregations

AstNode (org.mozilla.javascript.ast.AstNode)2 EmptyStatement (org.mozilla.javascript.ast.EmptyStatement)2 ExpressionStatement (org.mozilla.javascript.ast.ExpressionStatement)1 KeywordLiteral (org.mozilla.javascript.ast.KeywordLiteral)1 VariableDeclaration (org.mozilla.javascript.ast.VariableDeclaration)1