use of org.mozilla.javascript.ast.AstNode in project HL4A by HL4A.
the class Parser method doLoop.
private DoLoop doLoop() throws IOException {
if (currentToken != Token.DO)
codeBug();
consumeToken();
int pos = ts.tokenBeg, end;
DoLoop pn = new DoLoop(pos);
pn.setLineno(ts.lineno);
enterLoop(pn);
try {
AstNode body = statement();
mustMatchToken(Token.WHILE, "msg.no.while.do");
pn.setWhilePosition(ts.tokenBeg - pos);
ConditionData data = condition();
pn.setCondition(data.condition);
pn.setParens(data.lp - pos, data.rp - pos);
end = getNodeEnd(body);
pn.setBody(body);
} finally {
exitLoop();
}
// world, see bug 238945
if (matchToken(Token.SEMI)) {
end = ts.tokenEnd;
}
pn.setLength(end - pos);
return pn;
}
use of org.mozilla.javascript.ast.AstNode 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;
}
use of org.mozilla.javascript.ast.AstNode in project HL4A by HL4A.
the class Parser method bitXorExpr.
private AstNode bitXorExpr() throws IOException {
AstNode pn = bitAndExpr();
while (matchToken(Token.BITXOR)) {
int opPos = ts.tokenBeg;
pn = new InfixExpression(Token.BITXOR, pn, bitAndExpr(), opPos);
}
return pn;
}
use of org.mozilla.javascript.ast.AstNode in project HL4A by HL4A.
the class Parser method statement.
private AstNode statement() throws IOException {
int pos = ts.tokenBeg;
try {
AstNode pn = statementHelper();
if (pn != null) {
if (compilerEnv.isStrictMode() && !pn.hasSideEffects()) {
int beg = pn.getPosition();
beg = Math.max(beg, lineBeginningFor(beg));
addStrictWarning(pn instanceof EmptyStatement ? "msg.extra.trailing.semi" : "msg.no.side.effects", "", beg, nodeEnd(pn) - beg);
}
return pn;
}
} catch (ParserException e) {
// an ErrorNode was added to the ErrorReporter
}
// error: skip ahead to a probable statement boundary
guessingStatementEnd: for (; ; ) {
int tt = peekTokenOrEOL();
consumeToken();
switch(tt) {
case Token.ERROR:
case Token.EOF:
case Token.EOL:
case Token.SEMI:
break guessingStatementEnd;
}
}
// something different here.
return new EmptyStatement(pos, ts.tokenBeg - pos);
}
use of org.mozilla.javascript.ast.AstNode in project HL4A by HL4A.
the class Parser method destructuringObject.
boolean destructuringObject(ObjectLiteral node, int variableType, String tempName, Node parent, List<String> destructuringNames) {
boolean empty = true;
int setOp = variableType == Token.CONST ? Token.SETCONST : Token.SETNAME;
for (ObjectProperty prop : node.getElements()) {
int lineno = 0;
// tokenStream isn't set. Deal with it.
if (ts != null) {
lineno = ts.lineno;
}
AstNode id = prop.getLeft();
Node rightElem = null;
if (id instanceof Name) {
Node s = Node.newString(((Name) id).getIdentifier());
rightElem = new Node(Token.GETPROP, createName(tempName), s);
} else if (id instanceof StringLiteral) {
Node s = Node.newString(((StringLiteral) id).getValue());
rightElem = new Node(Token.GETPROP, createName(tempName), s);
} else if (id instanceof NumberLiteral) {
Node s = createNumber((int) ((NumberLiteral) id).getNumber());
rightElem = new Node(Token.GETELEM, createName(tempName), s);
} else {
throw codeBug();
}
rightElem.setLineno(lineno);
AstNode value = prop.getRight();
if (value.getType() == Token.NAME) {
String name = ((Name) value).getIdentifier();
parent.addChildToBack(new Node(setOp, createName(Token.BINDNAME, name, null), rightElem));
if (variableType != -1) {
defineSymbol(variableType, name, true);
destructuringNames.add(name);
}
} else {
parent.addChildToBack(destructuringAssignmentHelper(variableType, value, rightElem, currentScriptOrFn.getNextTempName()));
}
empty = false;
}
return empty;
}
Aggregations