use of org.mozilla.javascript.ast.AstNode in project HL4A by HL4A.
the class Parser method shiftExpr.
private AstNode shiftExpr() throws IOException {
AstNode pn = addExpr();
for (; ; ) {
int tt = peekToken(), opPos = ts.tokenBeg;
switch(tt) {
case Token.LSH:
case Token.URSH:
case Token.RSH:
consumeToken();
pn = new InfixExpression(tt, pn, addExpr(), opPos);
continue;
}
break;
}
return pn;
}
use of org.mozilla.javascript.ast.AstNode in project HL4A by HL4A.
the class Parser method parseFunctionParams.
private void parseFunctionParams(FunctionNode fnNode) throws IOException {
if (matchToken(Token.RP)) {
fnNode.setRp(ts.tokenBeg - fnNode.getPosition());
return;
}
// Would prefer not to call createDestructuringAssignment until codegen,
// but the symbol definitions have to happen now, before body is parsed.
Map<String, Node> destructuring = null;
Set<String> paramNames = new HashSet<String>();
do {
int tt = peekToken();
if (tt == Token.LB || tt == Token.LC) {
AstNode expr = destructuringPrimaryExpr();
markDestructuring(expr);
fnNode.addParam(expr);
// variables from the destructuring assignment
if (destructuring == null) {
destructuring = new HashMap<String, Node>();
}
String pname = currentScriptOrFn.getNextTempName();
defineSymbol(Token.LP, pname, false);
destructuring.put(pname, expr);
} else {
if (mustMatchToken(Token.NAME, "msg.no.parm")) {
Name paramNameNode = createNameNode();
Comment jsdocNodeForName = getAndResetJsDoc();
if (jsdocNodeForName != null) {
paramNameNode.setJsDocNode(jsdocNodeForName);
}
fnNode.addParam(paramNameNode);
String paramName = ts.getString();
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 {
fnNode.addParam(makeErrorNode());
}
}
} while (matchToken(Token.COMMA));
if (destructuring != null) {
Node destructuringNode = new Node(Token.COMMA);
// Add assignment helper for each destructuring parameter
for (Map.Entry<String, Node> param : destructuring.entrySet()) {
Node assign = createDestructuringAssignment(Token.VAR, param.getValue(), createName(param.getKey()));
destructuringNode.addChildToBack(assign);
}
fnNode.putProp(Node.DESTRUCTURING_PARAMS, destructuringNode);
}
if (mustMatchToken(Token.RP, "msg.no.paren.after.parms")) {
fnNode.setRp(ts.tokenBeg - fnNode.getPosition());
}
}
use of org.mozilla.javascript.ast.AstNode in project HL4A by HL4A.
the class Parser method nameOrLabel.
/**
* Found a name in a statement context. If it's a label, we gather
* up any following labels and the next non-label statement into a
* {@link LabeledStatement} "bundle" and return that. Otherwise we parse
* an expression and return it wrapped in an {@link ExpressionStatement}.
*/
private AstNode nameOrLabel() throws IOException {
if (currentToken != Token.NAME)
throw codeBug();
int pos = ts.tokenBeg;
// set check for label and call down to primaryExpr
currentFlaggedToken |= TI_CHECK_LABEL;
AstNode expr = expr();
if (expr.getType() != Token.LABEL) {
AstNode n = new ExpressionStatement(expr, !insideFunction());
n.lineno = expr.lineno;
return n;
}
LabeledStatement bundle = new LabeledStatement(pos);
recordLabel((Label) expr, bundle);
bundle.setLineno(ts.lineno);
// look for more labels
AstNode stmt = null;
while (peekToken() == Token.NAME) {
currentFlaggedToken |= TI_CHECK_LABEL;
expr = expr();
if (expr.getType() != Token.LABEL) {
stmt = new ExpressionStatement(expr, !insideFunction());
autoInsertSemicolon(stmt);
break;
}
recordLabel((Label) expr, bundle);
}
// no more labels; now parse the labeled statement
try {
currentLabel = bundle;
if (stmt == null) {
stmt = statementHelper();
}
} finally {
currentLabel = null;
// remove the labels for this statement from the global set
for (Label lb : bundle.getLabels()) {
labelSet.remove(lb.getName());
}
}
// If stmt has parent assigned its position already is relative
// (See bug #710225)
bundle.setLength(stmt.getParent() == null ? getNodeEnd(stmt) - pos : getNodeEnd(stmt));
bundle.setStatement(stmt);
return bundle;
}
use of org.mozilla.javascript.ast.AstNode in project HL4A by HL4A.
the class Parser method letStatement.
private AstNode letStatement() throws IOException {
if (currentToken != Token.LET)
codeBug();
consumeToken();
int lineno = ts.lineno, pos = ts.tokenBeg;
AstNode pn;
if (peekToken() == Token.LP) {
pn = let(true, pos);
} else {
// else, e.g.: let x=6, y=7;
pn = variables(Token.LET, pos, true);
}
pn.setLineno(lineno);
return pn;
}
use of org.mozilla.javascript.ast.AstNode in project st-js by st-js.
the class RhinoJavaScriptBuilder method switchStatement.
/**
* {@inheritDoc}
*/
@Override
public AstNode switchStatement(AstNode expr, Iterable<AstNode> cases) {
SwitchStatement s = new SwitchStatement();
s.setExpression(expr);
for (AstNode c : cases) {
// the user must make sure it sends the correct types. TODO the code can check and build the correct type if
// needed
s.addCase((SwitchCase) c);
}
return s;
}
Aggregations