// This is an auto-generated file. Any changes made to this file may be overwritten. // This file was created at: 2024-09-18 09:28:21 #![allow(dead_code)] use std::fmt::Debug; use std::any::Any; use crate::token::Token; pub trait ExprVisitor { fn visit_binary_expr(&mut self, expr: &BinaryExpr) -> Result<(), Box>; fn visit_unary_expr(&mut self, expr: &UnaryExpr) -> Result<(), Box>; fn visit_call_expr(&mut self, expr: &CallExpr) -> Result<(), Box>; fn visit_get_expr(&mut self, expr: &GetExpr) -> Result<(), Box>; fn visit_primary_expr(&mut self, expr: &PrimaryExpr) -> Result<(), Box>; fn visit_function_expr(&mut self, expr: &FunctionExpr) -> Result<(), Box>; } pub trait StmtVisitor { fn visit_expr_stmt(&mut self, stmt: &ExprStmt) -> Result<(), Box>; fn visit_assign_stmt(&mut self, stmt: &AssignStmt) -> Result<(), Box>; fn visit_set_stmt(&mut self, stmt: &SetStmt) -> Result<(), Box>; fn visit_block_stmt(&mut self, stmt: &BlockStmt) -> Result<(), Box>; fn visit_return_stmt(&mut self, stmt: &ReturnStmt) -> Result<(), Box>; fn visit_if_stmt(&mut self, stmt: &IfStmt) -> Result<(), Box>; } pub trait Expr: Debug + Any { fn accept(&self, visitor: &mut dyn ExprVisitor) -> Result<(), Box>; fn as_any(self: Box) -> Box; fn as_any_ref(&self) -> &dyn Any; } pub type ExprP = Box; #[derive(Debug)] pub struct BinaryExpr { pub lhs: ExprP, pub op: Token, pub rhs: ExprP, } impl Expr for BinaryExpr { fn accept(&self, visitor: &mut dyn ExprVisitor) -> Result<(), Box>{ visitor.visit_binary_expr(self) } fn as_any(self: Box) -> Box { self } fn as_any_ref(&self) -> &dyn Any { self } } #[derive(Debug)] pub struct UnaryExpr { pub op: Token, pub expr: ExprP, } impl Expr for UnaryExpr { fn accept(&self, visitor: &mut dyn ExprVisitor) -> Result<(), Box>{ visitor.visit_unary_expr(self) } fn as_any(self: Box) -> Box { self } fn as_any_ref(&self) -> &dyn Any { self } } #[derive(Debug)] pub struct CallExpr { pub expr: ExprP, pub args: Vec, pub rparen: Token, } impl Expr for CallExpr { fn accept(&self, visitor: &mut dyn ExprVisitor) -> Result<(), Box>{ visitor.visit_call_expr(self) } fn as_any(self: Box) -> Box { self } fn as_any_ref(&self) -> &dyn Any { self } } #[derive(Debug)] pub struct GetExpr { pub expr: ExprP, pub name: Token, } impl Expr for GetExpr { fn accept(&self, visitor: &mut dyn ExprVisitor) -> Result<(), Box>{ visitor.visit_get_expr(self) } fn as_any(self: Box) -> Box { self } fn as_any_ref(&self) -> &dyn Any { self } } #[derive(Debug)] pub struct PrimaryExpr { pub token: Token, } impl Expr for PrimaryExpr { fn accept(&self, visitor: &mut dyn ExprVisitor) -> Result<(), Box>{ visitor.visit_primary_expr(self) } fn as_any(self: Box) -> Box { self } fn as_any_ref(&self) -> &dyn Any { self } } #[derive(Debug)] pub struct FunctionExpr { pub lparen: Token, pub params: Vec<(Token , Option)>, pub return_type: Option, pub body: Vec, pub rbrace: Token, } impl Expr for FunctionExpr { fn accept(&self, visitor: &mut dyn ExprVisitor) -> Result<(), Box>{ visitor.visit_function_expr(self) } fn as_any(self: Box) -> Box { self } fn as_any_ref(&self) -> &dyn Any { self } } pub trait Stmt: Debug + Any { fn accept(&self, visitor: &mut dyn StmtVisitor) -> Result<(), Box>; fn as_any(self: Box) -> Box; fn as_any_ref(&self) -> &dyn Any; } pub type StmtP = Box; #[derive(Debug)] pub struct ExprStmt { pub expr: ExprP, } impl Stmt for ExprStmt { fn accept(&self, visitor: &mut dyn StmtVisitor) -> Result<(), Box>{ visitor.visit_expr_stmt(self) } fn as_any(self: Box) -> Box { self } fn as_any_ref(&self) -> &dyn Any { self } } #[derive(Debug)] pub struct AssignStmt { pub lhs: Token, pub rhs: ExprP, } impl Stmt for AssignStmt { fn accept(&self, visitor: &mut dyn StmtVisitor) -> Result<(), Box>{ visitor.visit_assign_stmt(self) } fn as_any(self: Box) -> Box { self } fn as_any_ref(&self) -> &dyn Any { self } } #[derive(Debug)] pub struct SetStmt { pub expr: ExprP, pub name: Token, pub rhs: ExprP, } impl Stmt for SetStmt { fn accept(&self, visitor: &mut dyn StmtVisitor) -> Result<(), Box>{ visitor.visit_set_stmt(self) } fn as_any(self: Box) -> Box { self } fn as_any_ref(&self) -> &dyn Any { self } } #[derive(Debug)] pub struct BlockStmt { pub lbrace: Token, pub stmts: Vec, pub rbrace: Token, } impl Stmt for BlockStmt { fn accept(&self, visitor: &mut dyn StmtVisitor) -> Result<(), Box>{ visitor.visit_block_stmt(self) } fn as_any(self: Box) -> Box { self } fn as_any_ref(&self) -> &dyn Any { self } } #[derive(Debug)] pub struct ReturnStmt { pub return_kw: Token, pub expr: Option, } impl Stmt for ReturnStmt { fn accept(&self, visitor: &mut dyn StmtVisitor) -> Result<(), Box>{ visitor.visit_return_stmt(self) } fn as_any(self: Box) -> Box { self } fn as_any_ref(&self) -> &dyn Any { self } } #[derive(Debug)] pub struct IfStmt { pub if_kw: Token, pub condition: ExprP, pub then_branch: BlockStmt, pub else_branch: Vec, } impl Stmt for IfStmt { fn accept(&self, visitor: &mut dyn StmtVisitor) -> Result<(), Box>{ visitor.visit_if_stmt(self) } fn as_any(self: Box) -> Box { self } fn as_any_ref(&self) -> &dyn Any { self } }