Search in sources :

Example 1 with NumberLiteral

use of org.mozilla.javascript.ast.NumberLiteral in project hackpad by dropbox.

the class Node method newNumber.

public static Node newNumber(double number) {
    NumberLiteral n = new NumberLiteral();
    n.setNumber(number);
    return n;
}
Also used : NumberLiteral(org.mozilla.javascript.ast.NumberLiteral)

Example 2 with NumberLiteral

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

the class IRFactory method getPropKey.

private Object getPropKey(Node id) {
    Object key;
    if (id instanceof Name) {
        String s = ((Name) id).getIdentifier();
        decompiler.addName(s);
        key = ScriptRuntime.getIndexObject(s);
    } else if (id instanceof StringLiteral) {
        String s = ((StringLiteral) id).getValue();
        decompiler.addString(s);
        key = ScriptRuntime.getIndexObject(s);
    } else if (id instanceof NumberLiteral) {
        double n = ((NumberLiteral) id).getNumber();
        decompiler.addNumber(n);
        key = ScriptRuntime.getIndexObject(n);
    } else {
        throw Kit.codeBug();
    }
    return key;
}
Also used : StringLiteral(org.mozilla.javascript.ast.StringLiteral) XmlString(org.mozilla.javascript.ast.XmlString) NumberLiteral(org.mozilla.javascript.ast.NumberLiteral) Name(org.mozilla.javascript.ast.Name)

Example 3 with NumberLiteral

use of org.mozilla.javascript.ast.NumberLiteral 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 4 with NumberLiteral

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

the class RhinoJavaScriptBuilder method number.

/**
 * {@inheritDoc}
 */
@Override
public AstNode number(Number n) {
    NumberLiteral l = new NumberLiteral();
    l.setValue(n.toString());
    return l;
}
Also used : NumberLiteral(org.mozilla.javascript.ast.NumberLiteral)

Example 5 with NumberLiteral

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

the class Parser method objliteralProperty.

private AstNode objliteralProperty() throws IOException {
    AstNode pname;
    int tt = peekToken();
    switch(tt) {
        case Token.NAME:
            pname = createNameNode();
            break;
        case Token.STRING:
            pname = createStringLiteral();
            break;
        case Token.NUMBER:
            pname = new NumberLiteral(ts.tokenBeg, ts.getString(), ts.getNumber());
            break;
        default:
            if (compilerEnv.isReservedKeywordAsIdentifier() && TokenStream.isKeyword(ts.getString(), compilerEnv.getLanguageVersion(), inUseStrictDirective)) {
                // convert keyword to property name, e.g. ({if: 1})
                pname = createNameNode();
                break;
            }
            return null;
    }
    return pname;
}
Also used : AstNode(org.mozilla.javascript.ast.AstNode) NumberLiteral(org.mozilla.javascript.ast.NumberLiteral)

Aggregations

NumberLiteral (org.mozilla.javascript.ast.NumberLiteral)7 XmlString (org.mozilla.javascript.ast.XmlString)3 AstNode (org.mozilla.javascript.ast.AstNode)2 Name (org.mozilla.javascript.ast.Name)2 StringLiteral (org.mozilla.javascript.ast.StringLiteral)2 ErrorNode (org.mozilla.javascript.ast.ErrorNode)1 FunctionNode (org.mozilla.javascript.ast.FunctionNode)1 KeywordLiteral (org.mozilla.javascript.ast.KeywordLiteral)1 LetNode (org.mozilla.javascript.ast.LetNode)1 ObjectProperty (org.mozilla.javascript.ast.ObjectProperty)1 RegExpLiteral (org.mozilla.javascript.ast.RegExpLiteral)1 ScriptNode (org.mozilla.javascript.ast.ScriptNode)1