Java Code Examples for org.mozilla.javascript.ast.AstNode#setLength()

The following examples show how to use org.mozilla.javascript.ast.AstNode#setLength() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Parser.java    From JsDroidCmd with Mozilla Public License 2.0 6 votes vote down vote up
private void autoInsertSemicolon(AstNode pn) throws IOException {
    int ttFlagged = peekFlaggedToken();
    int pos = pn.getPosition();
    switch (ttFlagged & CLEAR_TI_MASK) {
      case Token.SEMI:
          // Consume ';' as a part of expression
          consumeToken();
          // extend the node bounds to include the semicolon.
          pn.setLength(ts.tokenEnd - pos);
          break;
      case Token.ERROR:
      case Token.EOF:
      case Token.RC:
          // Autoinsert ;
          warnMissingSemi(pos, nodeEnd(pn));
          break;
      default:
          if ((ttFlagged & TI_AFTER_EOL) == 0) {
              // Report error if no EOL or autoinsert ; otherwise
              reportError("msg.no.semi.stmt");
          } else {
              warnMissingSemi(pos, nodeEnd(pn));
          }
          break;
    }
}
 
Example 2
Source File: Parser.java    From JsDroidCmd with Mozilla Public License 2.0 5 votes vote down vote up
private AstNode statements(AstNode parent) throws IOException {
    if (currentToken != Token.LC  // assertion can be invalid in bad code
        && !compilerEnv.isIdeMode()) codeBug();
    int pos = ts.tokenBeg;
    AstNode block = parent != null ? parent : new Block(pos);
    block.setLineno(ts.lineno);

    int tt;
    while ((tt = peekToken()) > Token.EOF && tt != Token.RC) {
        block.addChild(statement());
    }
    block.setLength(ts.tokenBeg - pos);
    return block;
}
 
Example 3
Source File: Parser.java    From JsDroidCmd with Mozilla Public License 2.0 4 votes vote down vote up
private AstNode let(boolean isStatement, int pos)
    throws IOException
{
    LetNode pn = new LetNode(pos);
    pn.setLineno(ts.lineno);
    if (mustMatchToken(Token.LP, "msg.no.paren.after.let"))
        pn.setLp(ts.tokenBeg - pos);
    pushScope(pn);
    try {
        VariableDeclaration vars = variables(Token.LET, ts.tokenBeg, isStatement);
        pn.setVariables(vars);
        if (mustMatchToken(Token.RP, "msg.no.paren.let")) {
            pn.setRp(ts.tokenBeg - pos);
        }
        if (isStatement && peekToken() == Token.LC) {
            // let statement
            consumeToken();
            int beg = ts.tokenBeg;  // position stmt at LC
            AstNode stmt = statements();
            mustMatchToken(Token.RC, "msg.no.curly.let");
            stmt.setLength(ts.tokenEnd - beg);
            pn.setLength(ts.tokenEnd - pos);
            pn.setBody(stmt);
            pn.setType(Token.LET);
        } else {
            // let expression
            AstNode expr = expr();
            pn.setLength(getNodeEnd(expr) - pos);
            pn.setBody(expr);
            if (isStatement) {
                // let expression in statement context
                ExpressionStatement es =
                        new ExpressionStatement(pn, !insideFunction());
                es.setLineno(pn.getLineno());
                return es;
            }
        }
    } finally {
        popScope();
    }
    return pn;
}