use of org.mozilla.javascript.ast.UnaryExpression in project st-js by st-js.
the class RhinoJavaScriptBuilder method unary.
/**
* {@inheritDoc}
*/
@Override
public AstNode unary(UnaryOperator operator, AstNode operand) {
UnaryExpression u = new UnaryExpression();
u.setIsPostfix(operator.isPostfix());
u.setOperator(operator.getJavaScript());
u.setOperand(operand);
return u;
}
use of org.mozilla.javascript.ast.UnaryExpression in project HL4A by HL4A.
the class Parser method unaryExpr.
private AstNode unaryExpr() throws IOException {
AstNode node;
int tt = peekToken();
int line = ts.lineno;
switch(tt) {
case Token.VOID:
case Token.NOT:
case Token.BITNOT:
case Token.TYPEOF:
consumeToken();
node = new UnaryExpression(tt, ts.tokenBeg, unaryExpr());
node.setLineno(line);
return node;
case Token.ADD:
consumeToken();
// Convert to special POS token in parse tree
node = new UnaryExpression(Token.POS, ts.tokenBeg, unaryExpr());
node.setLineno(line);
return node;
case Token.SUB:
consumeToken();
// Convert to special NEG token in parse tree
node = new UnaryExpression(Token.NEG, ts.tokenBeg, unaryExpr());
node.setLineno(line);
return node;
case Token.INC:
case Token.DEC:
consumeToken();
UnaryExpression expr = new UnaryExpression(tt, ts.tokenBeg, memberExpr(true));
expr.setLineno(line);
checkBadIncDec(expr);
return expr;
case Token.DELPROP:
consumeToken();
node = new UnaryExpression(tt, ts.tokenBeg, unaryExpr());
node.setLineno(line);
return node;
case Token.ERROR:
consumeToken();
return makeErrorNode();
case Token.LT:
// XML stream encountered in expression.
if (compilerEnv.isXmlAvailable()) {
consumeToken();
return memberExprTail(true, xmlInitializer());
}
default:
AstNode pn = memberExpr(true);
// Don't look across a newline boundary for a postfix incop.
tt = peekTokenOrEOL();
if (!(tt == Token.INC || tt == Token.DEC)) {
return pn;
}
consumeToken();
UnaryExpression uexpr = new UnaryExpression(tt, ts.tokenBeg, pn, true);
uexpr.setLineno(line);
checkBadIncDec(uexpr);
return uexpr;
}
}
use of org.mozilla.javascript.ast.UnaryExpression in project HL4A by HL4A.
the class Parser method defaultXmlNamespace.
private AstNode defaultXmlNamespace() throws IOException {
if (currentToken != Token.DEFAULT)
codeBug();
consumeToken();
mustHaveXML();
setRequiresActivation();
int lineno = ts.lineno, pos = ts.tokenBeg;
if (!(matchToken(Token.NAME) && "xml".equals(ts.getString()))) {
reportError("msg.bad.namespace");
}
if (!(matchToken(Token.NAME) && "namespace".equals(ts.getString()))) {
reportError("msg.bad.namespace");
}
if (!matchToken(Token.ASSIGN)) {
reportError("msg.bad.namespace");
}
AstNode e = expr();
UnaryExpression dxmln = new UnaryExpression(pos, getNodeEnd(e) - pos);
dxmln.setOperator(Token.DEFAULTNAMESPACE);
dxmln.setOperand(e);
dxmln.setLineno(lineno);
ExpressionStatement es = new ExpressionStatement(dxmln, true);
return es;
}
Aggregations