}
@Override
public Expr parse(MagpieParser parser, Expr left, Token token) {
// Parse the argument, if any.
Expr arg = null;
if (parser.match(TokenType.LEFT_PAREN)) {
arg = parser.groupExpression(TokenType.RIGHT_PAREN);
}
// Pass the block, if any.
if (parser.match(TokenType.WITH)) {
// Parse the parameter list if given.
Pattern blockType;
if (parser.lookAhead(TokenType.LEFT_PAREN)) {
blockType = parser.parseFunctionType();
} else {
// Else just assume a single "it" parameter.
blockType = Pattern.variable(Name.IT);
}
// Parse the block and wrap it in a function.
Expr block = parser.parseExpressionOrBlock();
// TODO(bob): Parse doc comment.
block = Expr.fn(block.getPosition(), "", blockType, block);
// Add it to the argument list.
arg = appendField(arg, block);
}