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;
}
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;
}
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();
}
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;
}
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;
}
Aggregations