Search in sources :

Example 1 with KeywordLiteral

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

the class RhinoJavaScriptBuilder method keyword.

/**
 * {@inheritDoc}
 */
@Override
public AstNode keyword(Keyword token) {
    KeywordLiteral k = new KeywordLiteral();
    k.setType(token.getJavaScript());
    return k;
}
Also used : KeywordLiteral(org.mozilla.javascript.ast.KeywordLiteral)

Example 2 with KeywordLiteral

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

the class Parser method primaryExpr.

private AstNode primaryExpr() throws IOException {
    int ttFlagged = peekFlaggedToken();
    int tt = ttFlagged & CLEAR_TI_MASK;
    switch(tt) {
        case Token.FUNCTION:
            consumeToken();
            return function(FunctionNode.FUNCTION_EXPRESSION);
        case Token.LB:
            consumeToken();
            return arrayLiteral();
        case Token.LC:
            consumeToken();
            return objectLiteral();
        case Token.LET:
            consumeToken();
            return let(false, ts.tokenBeg);
        case Token.LP:
            consumeToken();
            return parenExpr();
        case Token.XMLATTR:
            consumeToken();
            mustHaveXML();
            return attributeAccess();
        case Token.NAME:
            consumeToken();
            return name(ttFlagged, tt);
        case Token.NUMBER:
            {
                consumeToken();
                String s = ts.getString();
                if (this.inUseStrictDirective && ts.isNumberOldOctal()) {
                    reportError("msg.no.old.octal.strict");
                }
                if (ts.isNumberBinary()) {
                    s = "0b" + s;
                }
                if (ts.isNumberOldOctal()) {
                    s = "0" + s;
                }
                if (ts.isNumberOctal()) {
                    s = "0o" + s;
                }
                if (ts.isNumberHex()) {
                    s = "0x" + s;
                }
                return new NumberLiteral(ts.tokenBeg, s, ts.getNumber());
            }
        case Token.STRING:
            consumeToken();
            return createStringLiteral();
        case Token.DIV:
        case Token.ASSIGN_DIV:
            consumeToken();
            // Got / or /= which in this context means a regexp
            ts.readRegExp(tt);
            int pos = ts.tokenBeg, end = ts.tokenEnd;
            RegExpLiteral re = new RegExpLiteral(pos, end - pos);
            re.setValue(ts.getString());
            re.setFlags(ts.readAndClearRegExpFlags());
            return re;
        case Token.NULL:
        case Token.THIS:
        case Token.FALSE:
        case Token.TRUE:
            consumeToken();
            pos = ts.tokenBeg;
            end = ts.tokenEnd;
            return new KeywordLiteral(pos, end - pos, tt);
        case Token.RESERVED:
            consumeToken();
            reportError("msg.reserved.id");
            break;
        case Token.ERROR:
            consumeToken();
            // the scanner or one of its subroutines reported the error.
            break;
        case Token.EOF:
            consumeToken();
            reportError("msg.unexpected.eof");
            break;
        default:
            consumeToken();
            reportError("msg.syntax");
            break;
    }
    // should only be reachable in IDE/error-recovery mode
    consumeToken();
    return makeErrorNode();
}
Also used : KeywordLiteral(org.mozilla.javascript.ast.KeywordLiteral) RegExpLiteral(org.mozilla.javascript.ast.RegExpLiteral) XmlString(org.mozilla.javascript.ast.XmlString) NumberLiteral(org.mozilla.javascript.ast.NumberLiteral)

Example 3 with KeywordLiteral

use of org.mozilla.javascript.ast.KeywordLiteral 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)

Aggregations

KeywordLiteral (org.mozilla.javascript.ast.KeywordLiteral)3 AstNode (org.mozilla.javascript.ast.AstNode)1 EmptyStatement (org.mozilla.javascript.ast.EmptyStatement)1 ExpressionStatement (org.mozilla.javascript.ast.ExpressionStatement)1 NumberLiteral (org.mozilla.javascript.ast.NumberLiteral)1 RegExpLiteral (org.mozilla.javascript.ast.RegExpLiteral)1 VariableDeclaration (org.mozilla.javascript.ast.VariableDeclaration)1 XmlString (org.mozilla.javascript.ast.XmlString)1