use of org.mozilla.javascript.ast.AstNode in project HL4A by HL4A.
the class Parser method xmlElemRef.
/**
* Parse the [expr] portion of an xml element reference, e.g.
* @[expr], @*::[expr], or ns::[expr].
*/
private XmlElemRef xmlElemRef(int atPos, Name namespace, int colonPos) throws IOException {
int lb = ts.tokenBeg, rb = -1, pos = atPos != -1 ? atPos : lb;
AstNode expr = expr();
int end = getNodeEnd(expr);
if (mustMatchToken(Token.RB, "msg.no.bracket.index")) {
rb = ts.tokenBeg;
end = ts.tokenEnd;
}
XmlElemRef ref = new XmlElemRef(pos, end - pos);
ref.setNamespace(namespace);
ref.setColonPos(colonPos);
ref.setAtPos(atPos);
ref.setExpression(expr);
ref.setBrackets(lb, rb);
return ref;
}
use of org.mozilla.javascript.ast.AstNode in project HL4A by HL4A.
the class Parser method andExpr.
private AstNode andExpr() throws IOException {
AstNode pn = bitOrExpr();
if (matchToken(Token.AND)) {
int opPos = ts.tokenBeg;
pn = new InfixExpression(Token.AND, pn, andExpr(), opPos);
}
return pn;
}
use of org.mozilla.javascript.ast.AstNode in project HL4A by HL4A.
the class Parser method tryStatement.
private TryStatement tryStatement() throws IOException {
if (currentToken != Token.TRY)
codeBug();
consumeToken();
// Pull out JSDoc info and reset it before recursing.
Comment jsdocNode = getAndResetJsDoc();
int tryPos = ts.tokenBeg, lineno = ts.lineno, finallyPos = -1;
if (peekToken() != Token.LC) {
reportError("msg.no.brace.try");
}
AstNode tryBlock = statement();
int tryEnd = getNodeEnd(tryBlock);
List<CatchClause> clauses = null;
boolean sawDefaultCatch = false;
int peek = peekToken();
if (peek == Token.CATCH) {
while (matchToken(Token.CATCH)) {
int catchLineNum = ts.lineno;
if (sawDefaultCatch) {
reportError("msg.catch.unreachable");
}
int catchPos = ts.tokenBeg, lp = -1, rp = -1, guardPos = -1;
if (mustMatchToken(Token.LP, "msg.no.paren.catch"))
lp = ts.tokenBeg;
mustMatchToken(Token.NAME, "msg.bad.catchcond");
Name varName = createNameNode();
Comment jsdocNodeForName = getAndResetJsDoc();
if (jsdocNodeForName != null) {
varName.setJsDocNode(jsdocNodeForName);
}
String varNameString = varName.getIdentifier();
if (inUseStrictDirective) {
if ("eval".equals(varNameString) || "arguments".equals(varNameString)) {
reportError("msg.bad.id.strict", varNameString);
}
}
AstNode catchCond = null;
if (matchToken(Token.IF)) {
guardPos = ts.tokenBeg;
catchCond = expr();
} else {
sawDefaultCatch = true;
}
if (mustMatchToken(Token.RP, "msg.bad.catchcond"))
rp = ts.tokenBeg;
mustMatchToken(Token.LC, "msg.no.brace.catchblock");
Block catchBlock = (Block) statements();
tryEnd = getNodeEnd(catchBlock);
CatchClause catchNode = new CatchClause(catchPos);
catchNode.setVarName(varName);
catchNode.setCatchCondition(catchCond);
catchNode.setBody(catchBlock);
if (guardPos != -1) {
catchNode.setIfPosition(guardPos - catchPos);
}
catchNode.setParens(lp, rp);
catchNode.setLineno(catchLineNum);
if (mustMatchToken(Token.RC, "msg.no.brace.after.body"))
tryEnd = ts.tokenEnd;
catchNode.setLength(tryEnd - catchPos);
if (clauses == null)
clauses = new ArrayList<CatchClause>();
clauses.add(catchNode);
}
} else if (peek != Token.FINALLY) {
mustMatchToken(Token.FINALLY, "msg.try.no.catchfinally");
}
AstNode finallyBlock = null;
if (matchToken(Token.FINALLY)) {
finallyPos = ts.tokenBeg;
finallyBlock = statement();
tryEnd = getNodeEnd(finallyBlock);
}
TryStatement pn = new TryStatement(tryPos, tryEnd - tryPos);
pn.setTryBlock(tryBlock);
pn.setCatchClauses(clauses);
pn.setFinallyBlock(finallyBlock);
if (finallyPos != -1) {
pn.setFinallyPosition(finallyPos - tryPos);
}
pn.setLineno(lineno);
if (jsdocNode != null) {
pn.setJsDocNode(jsdocNode);
}
return pn;
}
use of org.mozilla.javascript.ast.AstNode in project HL4A by HL4A.
the class Parser method ifStatement.
private IfStatement ifStatement() throws IOException {
if (currentToken != Token.IF)
codeBug();
consumeToken();
int pos = ts.tokenBeg, lineno = ts.lineno, elsePos = -1;
ConditionData data = condition();
AstNode ifTrue = statement(), ifFalse = null;
if (matchToken(Token.ELSE)) {
elsePos = ts.tokenBeg - pos;
ifFalse = statement();
}
int end = getNodeEnd(ifFalse != null ? ifFalse : ifTrue);
IfStatement pn = new IfStatement(pos, end - pos);
pn.setCondition(data.condition);
pn.setParens(data.lp - pos, data.rp - pos);
pn.setThenPart(ifTrue);
pn.setElsePart(ifFalse);
pn.setElsePosition(elsePos);
pn.setLineno(lineno);
return pn;
}
use of org.mozilla.javascript.ast.AstNode in project HL4A by HL4A.
the class Parser method parenExpr.
private AstNode parenExpr() throws IOException {
boolean wasInForInit = inForInit;
inForInit = false;
try {
Comment jsdocNode = getAndResetJsDoc();
int lineno = ts.lineno;
int begin = ts.tokenBeg;
AstNode e = (peekToken() == Token.RP ? new EmptyExpression(begin) : expr());
if (peekToken() == Token.FOR) {
return generatorExpression(e, begin);
}
ParenthesizedExpression pn = new ParenthesizedExpression(e);
if (jsdocNode == null) {
jsdocNode = getAndResetJsDoc();
}
if (jsdocNode != null) {
pn.setJsDocNode(jsdocNode);
}
mustMatchToken(Token.RP, "msg.no.paren");
if (e.getType() == Token.EMPTY && peekToken() != Token.ARROW) {
reportError("msg.syntax");
return makeErrorNode();
}
pn.setLength(ts.tokenEnd - pn.getPosition());
pn.setLineno(lineno);
return pn;
} finally {
inForInit = wasInForInit;
}
}
Aggregations