assignment method
Implementation
AstNode assignment() {
AstNode expr = logicalOr();
if (match([
TokenType.assign,
TokenType.plusAssign,
TokenType.minusAssign,
TokenType.multiplyAssign,
TokenType.divideAssign,
TokenType.plusPlus,
TokenType.minusMinus
])) {
Token operator = previous();
AstNode value;
if (operator.type == TokenType.plusPlus ||
operator.type == TokenType.minusMinus) {
// For ++ and --, we don't need to parse another expression
value = const Literal(1);
} else {
value = assignment();
}
if (expr is Variable) {
return Assignment(expr.name, operator, value);
}
error(operator, "Invalid assignment target.");
}
return expr;
}