use of org.mozilla.javascript.ast.InfixExpression in project st-js by st-js.
the class RhinoJavaScriptBuilder method binary.
/**
* {@inheritDoc}
*/
@Override
public AstNode binary(BinaryOperator operator, Iterable<AstNode> operands) {
// this is to deal with the COMMA operator who can have less than two operands
if (Iterables.isEmpty(operands)) {
return new EmptyExpression();
}
if (Iterables.size(operands) == 1) {
return operands.iterator().next();
}
InfixExpression list = new InfixExpression();
list.setOperator(operator.getJavaScript());
Iterator<AstNode> it = operands.iterator();
list.setLeft(it.next());
list.setRight(it.next());
while (it.hasNext()) {
InfixExpression tmpIncrements = new InfixExpression();
tmpIncrements.setOperator(operator.getJavaScript());
tmpIncrements.setLeft(list);
tmpIncrements.setRight(it.next());
list = tmpIncrements;
}
return list;
}
use of org.mozilla.javascript.ast.InfixExpression in project HL4A by HL4A.
the class Parser method arrowFunctionParams.
private void arrowFunctionParams(FunctionNode fnNode, AstNode params, Map<String, Node> destructuring, Set<String> paramNames) {
if (params instanceof ArrayLiteral || params instanceof ObjectLiteral) {
markDestructuring(params);
fnNode.addParam(params);
String pname = currentScriptOrFn.getNextTempName();
defineSymbol(Token.LP, pname, false);
destructuring.put(pname, params);
} else if (params instanceof InfixExpression && params.getType() == Token.COMMA) {
arrowFunctionParams(fnNode, ((InfixExpression) params).getLeft(), destructuring, paramNames);
arrowFunctionParams(fnNode, ((InfixExpression) params).getRight(), destructuring, paramNames);
} else if (params instanceof Name) {
fnNode.addParam(params);
String paramName = ((Name) params).getIdentifier();
defineSymbol(Token.LP, paramName);
if (this.inUseStrictDirective) {
if ("eval".equals(paramName) || "arguments".equals(paramName)) {
reportError("msg.bad.id.strict", paramName);
}
if (paramNames.contains(paramName))
addError("msg.dup.param.strict", paramName);
paramNames.add(paramName);
}
} else {
reportError("msg.no.parm", params.getPosition(), params.getLength());
fnNode.addParam(makeErrorNode());
}
}
use of org.mozilla.javascript.ast.InfixExpression in project HL4A by HL4A.
the class Parser method expr.
private AstNode expr() throws IOException {
AstNode pn = assignExpr();
int pos = pn.getPosition();
while (matchToken(Token.COMMA)) {
int opPos = ts.tokenBeg;
if (compilerEnv.isStrictMode() && !pn.hasSideEffects())
addStrictWarning("msg.no.side.effects", "", pos, nodeEnd(pn) - pos);
if (peekToken() == Token.YIELD)
reportError("msg.yield.parenthesized");
pn = new InfixExpression(Token.COMMA, pn, assignExpr(), opPos);
}
return pn;
}
use of org.mozilla.javascript.ast.InfixExpression in project HL4A by HL4A.
the class Parser method bitOrExpr.
private AstNode bitOrExpr() throws IOException {
AstNode pn = bitXorExpr();
while (matchToken(Token.BITOR)) {
int opPos = ts.tokenBeg;
pn = new InfixExpression(Token.BITOR, pn, bitXorExpr(), opPos);
}
return pn;
}
use of org.mozilla.javascript.ast.InfixExpression in project HL4A by HL4A.
the class Parser method propertyAccess.
/**
* Handles any construct following a "." or ".." operator.
* @param pn the left-hand side (target) of the operator. Never null.
* @return a PropertyGet, XmlMemberGet, or ErrorNode
*/
private AstNode propertyAccess(int tt, AstNode pn) throws IOException {
if (pn == null)
codeBug();
int memberTypeFlags = 0, lineno = ts.lineno, dotPos = ts.tokenBeg;
consumeToken();
if (tt == Token.DOTDOT) {
mustHaveXML();
memberTypeFlags = Node.DESCENDANTS_FLAG;
}
if (!compilerEnv.isXmlAvailable()) {
int maybeName = nextToken();
if (maybeName != Token.NAME && !(compilerEnv.isReservedKeywordAsIdentifier() && TokenStream.isKeyword(ts.getString(), compilerEnv.getLanguageVersion(), inUseStrictDirective))) {
reportError("msg.no.name.after.dot");
}
Name name = createNameNode(true, Token.GETPROP);
PropertyGet pg = new PropertyGet(pn, name, dotPos);
pg.setLineno(lineno);
return pg;
}
// right side of . or .. operator
AstNode ref = null;
int token = nextToken();
switch(token) {
case Token.THROW:
// needed for generator.throw();
saveNameTokenData(ts.tokenBeg, "throw", ts.lineno);
ref = propertyName(-1, "throw", memberTypeFlags);
break;
case Token.NAME:
// handles: name, ns::name, ns::*, ns::[expr]
ref = propertyName(-1, ts.getString(), memberTypeFlags);
break;
case Token.MUL:
// handles: *, *::name, *::*, *::[expr]
saveNameTokenData(ts.tokenBeg, "*", ts.lineno);
ref = propertyName(-1, "*", memberTypeFlags);
break;
case Token.XMLATTR:
// handles: '@attr', '@ns::attr', '@ns::*', '@ns::*',
// '@::attr', '@::*', '@*', '@*::attr', '@*::*'
ref = attributeAccess();
break;
case Token.RESERVED:
{
String name = ts.getString();
saveNameTokenData(ts.tokenBeg, name, ts.lineno);
ref = propertyName(-1, name, memberTypeFlags);
break;
}
default:
if (compilerEnv.isReservedKeywordAsIdentifier()) {
// allow keywords as property names, e.g. ({if: 1})
String name = Token.keywordToName(token);
if (name != null) {
saveNameTokenData(ts.tokenBeg, name, ts.lineno);
ref = propertyName(-1, name, memberTypeFlags);
break;
}
}
reportError("msg.no.name.after.dot");
return makeErrorNode();
}
boolean xml = ref instanceof XmlRef;
InfixExpression result = xml ? new XmlMemberGet() : new PropertyGet();
if (xml && tt == Token.DOT)
result.setType(Token.DOT);
int pos = pn.getPosition();
result.setPosition(pos);
result.setLength(getNodeEnd(ref) - pos);
result.setOperatorPosition(dotPos - pos);
result.setLineno(pn.getLineno());
// do this after setting position
result.setLeft(pn);
result.setRight(ref);
return result;
}
Aggregations