*
* @param newFlag if we're currently parsing a 'new' expression
* @return an expression
*/
private Expression parseMemberExpression(boolean newFlag) throws CompilerException {
Expression expression;
// new expressions are right associative
if (nextToken == Token.KEYWORD_NEW) {
Expression name;
readToken(Token.KEYWORD_NEW);
name = parseMemberExpression(true);
if (nextToken == Token.OPERATOR_OPENPAREN) {
Expression[] arguments = parseArgumentList();
expression = new NewExpression(name, arguments);
} else {
expression = new NewExpression(name, null);
}
} else if (nextToken == Token.KEYWORD_FUNCTION) {
expression = parseFunctionLiteral(false);
} else {
expression = parsePrimaryExpression();
}
// call expressions are left associative
while (true) {
if (!newFlag && nextToken == Token.OPERATOR_OPENPAREN) {
Expression[] arguments = parseArgumentList();
expression = new CallExpression(expression, arguments);
} else if (nextToken == Token.OPERATOR_OPENSQUARE) {
readToken(Token.OPERATOR_OPENSQUARE);
Expression property = parseExpression(true);
readToken(Token.OPERATOR_CLOSESQUARE);
expression = new PropertyExpression(expression, property);
} else if (nextToken == Token.OPERATOR_DOT) {
// transform x.bar to x["bar"]
readToken(Token.OPERATOR_DOT);