AST - Variable assignment

This commit is contained in:
Emmanuel BENOîT 2022-12-31 16:16:12 +01:00
parent c486b81cba
commit b5ff24ffad

View file

@ -22,6 +22,9 @@ pub enum StmtNode {
/// An AST node that represents an expression. /// An AST node that represents an expression.
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub enum ExprNode { pub enum ExprNode {
/// Assignment to a variable.
Assignment { name: Token, value: Box<ExprNode> },
/// Binary expression. /// Binary expression.
Binary { Binary {
left: Box<ExprNode>, left: Box<ExprNode>,
@ -79,6 +82,7 @@ impl AstDumper for StmtNode {
impl AstDumper for ExprNode { impl AstDumper for ExprNode {
fn dump(&self) -> String { fn dump(&self) -> String {
match self { match self {
Self::Assignment { name, value } => format!("( = {} {} )", name.lexeme, value.dump()),
Self::Binary { Self::Binary {
left, left,
operator, operator,