Add test infrastructure for JS source map parser and generator
This commit is contained in:
@@ -708,88 +708,98 @@ public class Parser extends Observable {
|
||||
}
|
||||
|
||||
private Node expr(TokenStream ts, boolean inForInit) throws IOException, JavaScriptException {
|
||||
CodePosition position = getNextTokenPosition(ts);
|
||||
Node pn = assignExpr(ts, inForInit);
|
||||
while (ts.matchToken(TokenStream.COMMA)) {
|
||||
pn = nf.createBinary(TokenStream.COMMA, pn, assignExpr(ts, inForInit), pn.getPosition());
|
||||
pn = nf.createBinary(TokenStream.COMMA, pn, assignExpr(ts, inForInit), position);
|
||||
}
|
||||
return pn;
|
||||
}
|
||||
|
||||
private Node assignExpr(TokenStream ts, boolean inForInit) throws IOException, JavaScriptException {
|
||||
CodePosition position = getNextTokenPosition(ts);
|
||||
Node pn = condExpr(ts, inForInit);
|
||||
|
||||
if (ts.matchToken(TokenStream.ASSIGN)) {
|
||||
// omitted: "invalid assignment left-hand side" check.
|
||||
pn = nf.createBinary(TokenStream.ASSIGN, ts.getOp(), pn, assignExpr(ts, inForInit), pn.getPosition());
|
||||
pn = nf.createBinary(TokenStream.ASSIGN, ts.getOp(), pn, assignExpr(ts, inForInit), position);
|
||||
}
|
||||
|
||||
return pn;
|
||||
}
|
||||
|
||||
private Node condExpr(TokenStream ts, boolean inForInit) throws IOException, JavaScriptException {
|
||||
CodePosition position = getNextTokenPosition(ts);
|
||||
Node pn = orExpr(ts, inForInit);
|
||||
|
||||
if (ts.matchToken(TokenStream.HOOK)) {
|
||||
Node ifTrue = assignExpr(ts, false);
|
||||
mustMatchToken(ts, TokenStream.COLON, "msg.no.colon.cond");
|
||||
Node ifFalse = assignExpr(ts, inForInit);
|
||||
return nf.createTernary(pn, ifTrue, ifFalse, pn.getPosition());
|
||||
return nf.createTernary(pn, ifTrue, ifFalse, position);
|
||||
}
|
||||
|
||||
return pn;
|
||||
}
|
||||
|
||||
private Node orExpr(TokenStream ts, boolean inForInit) throws IOException, JavaScriptException {
|
||||
CodePosition position = getNextTokenPosition(ts);
|
||||
Node pn = andExpr(ts, inForInit);
|
||||
while (ts.matchToken(TokenStream.OR)) {
|
||||
pn = nf.createBinary(TokenStream.OR, pn, andExpr(ts, inForInit), pn.getPosition());
|
||||
pn = nf.createBinary(TokenStream.OR, pn, andExpr(ts, inForInit), position);
|
||||
}
|
||||
|
||||
return pn;
|
||||
}
|
||||
|
||||
private Node andExpr(TokenStream ts, boolean inForInit) throws IOException, JavaScriptException {
|
||||
CodePosition position = getNextTokenPosition(ts);
|
||||
Node pn = bitOrExpr(ts, inForInit);
|
||||
while (ts.matchToken(TokenStream.AND)) {
|
||||
pn = nf.createBinary(TokenStream.AND, pn, bitOrExpr(ts, inForInit), pn.getPosition());
|
||||
pn = nf.createBinary(TokenStream.AND, pn, bitOrExpr(ts, inForInit), position);
|
||||
}
|
||||
|
||||
return pn;
|
||||
}
|
||||
|
||||
private Node bitOrExpr(TokenStream ts, boolean inForInit) throws IOException, JavaScriptException {
|
||||
CodePosition position = getNextTokenPosition(ts);
|
||||
Node pn = bitXorExpr(ts, inForInit);
|
||||
while (ts.matchToken(TokenStream.BITOR)) {
|
||||
pn = nf.createBinary(TokenStream.BITOR, pn, bitXorExpr(ts, inForInit), pn.getPosition());
|
||||
pn = nf.createBinary(TokenStream.BITOR, pn, bitXorExpr(ts, inForInit), position);
|
||||
}
|
||||
return pn;
|
||||
}
|
||||
|
||||
private Node bitXorExpr(TokenStream ts, boolean inForInit) throws IOException, JavaScriptException {
|
||||
CodePosition position = getNextTokenPosition(ts);
|
||||
Node pn = bitAndExpr(ts, inForInit);
|
||||
while (ts.matchToken(TokenStream.BITXOR)) {
|
||||
pn = nf.createBinary(TokenStream.BITXOR, pn, bitAndExpr(ts, inForInit), pn.getPosition());
|
||||
pn = nf.createBinary(TokenStream.BITXOR, pn, bitAndExpr(ts, inForInit), position);
|
||||
}
|
||||
return pn;
|
||||
}
|
||||
|
||||
private Node bitAndExpr(TokenStream ts, boolean inForInit) throws IOException, JavaScriptException {
|
||||
CodePosition position = getNextTokenPosition(ts);
|
||||
Node pn = eqExpr(ts, inForInit);
|
||||
while (ts.matchToken(TokenStream.BITAND)) {
|
||||
pn = nf.createBinary(TokenStream.BITAND, pn, eqExpr(ts, inForInit), pn.getPosition());
|
||||
pn = nf.createBinary(TokenStream.BITAND, pn, eqExpr(ts, inForInit), position);
|
||||
}
|
||||
return pn;
|
||||
}
|
||||
|
||||
private Node eqExpr(TokenStream ts, boolean inForInit) throws IOException, JavaScriptException {
|
||||
CodePosition position = getNextTokenPosition(ts);
|
||||
Node pn = relExpr(ts, inForInit);
|
||||
while (ts.matchToken(TokenStream.EQOP)) {
|
||||
pn = nf.createBinary(TokenStream.EQOP, ts.getOp(), pn, relExpr(ts, inForInit), pn.getPosition());
|
||||
pn = nf.createBinary(TokenStream.EQOP, ts.getOp(), pn, relExpr(ts, inForInit), position);
|
||||
}
|
||||
return pn;
|
||||
}
|
||||
|
||||
private Node relExpr(TokenStream ts, boolean inForInit) throws IOException, JavaScriptException {
|
||||
CodePosition position = getNextTokenPosition(ts);
|
||||
Node pn = shiftExpr(ts);
|
||||
while (ts.matchToken(TokenStream.RELOP)) {
|
||||
int op = ts.getOp();
|
||||
@@ -798,26 +808,28 @@ public class Parser extends Observable {
|
||||
break;
|
||||
}
|
||||
|
||||
pn = nf.createBinary(TokenStream.RELOP, op, pn, shiftExpr(ts), pn.getPosition());
|
||||
pn = nf.createBinary(TokenStream.RELOP, op, pn, shiftExpr(ts), position);
|
||||
}
|
||||
return pn;
|
||||
}
|
||||
|
||||
private Node shiftExpr(TokenStream ts) throws IOException, JavaScriptException {
|
||||
CodePosition position = getNextTokenPosition(ts);
|
||||
Node pn = addExpr(ts);
|
||||
while (ts.matchToken(TokenStream.SHOP)) {
|
||||
pn = nf.createBinary(TokenStream.SHOP, ts.getOp(), pn, addExpr(ts), pn.getPosition());
|
||||
pn = nf.createBinary(TokenStream.SHOP, ts.getOp(), pn, addExpr(ts), position);
|
||||
}
|
||||
return pn;
|
||||
}
|
||||
|
||||
private Node addExpr(TokenStream ts) throws IOException, JavaScriptException {
|
||||
CodePosition position = getNextTokenPosition(ts);
|
||||
int tt;
|
||||
Node pn = mulExpr(ts);
|
||||
|
||||
while ((tt = ts.getToken()) == TokenStream.ADD || tt == TokenStream.SUB) {
|
||||
// flushNewLines
|
||||
pn = nf.createBinary(tt, pn, mulExpr(ts), pn.getPosition());
|
||||
pn = nf.createBinary(tt, pn, mulExpr(ts), position);
|
||||
}
|
||||
ts.ungetToken(tt);
|
||||
|
||||
@@ -825,13 +837,14 @@ public class Parser extends Observable {
|
||||
}
|
||||
|
||||
private Node mulExpr(TokenStream ts) throws IOException, JavaScriptException {
|
||||
CodePosition position = getNextTokenPosition(ts);
|
||||
int tt;
|
||||
|
||||
Node pn = unaryExpr(ts);
|
||||
|
||||
while ((tt = ts.peekToken()) == TokenStream.MUL || tt == TokenStream.DIV || tt == TokenStream.MOD) {
|
||||
tt = ts.getToken();
|
||||
pn = nf.createBinary(tt, pn, unaryExpr(ts), pn.getPosition());
|
||||
pn = nf.createBinary(tt, pn, unaryExpr(ts), position);
|
||||
}
|
||||
|
||||
return pn;
|
||||
@@ -1133,6 +1146,13 @@ public class Parser extends Observable {
|
||||
return null; // should never reach here
|
||||
}
|
||||
|
||||
private static CodePosition getNextTokenPosition(TokenStream ts) throws IOException, JavaScriptException {
|
||||
int tt = ts.getToken();
|
||||
CodePosition result = ts.tokenPosition;
|
||||
ts.ungetToken(tt);
|
||||
return result;
|
||||
}
|
||||
|
||||
private int lastExprEndLine; // Hack to handle function expr termination.
|
||||
private final IRFactory nf;
|
||||
private boolean ok; // Did the parse encounter an error?
|
||||
|
||||
Reference in New Issue
Block a user