use std::fmt::Display; use crate::lexer::{Literal, TokenType}; pub mod parser; pub mod printer; #[derive(Debug, Eq, PartialEq)] pub enum Stmt { Block(Vec), Expr(Expr), Val { ident: String, value: Expr, }, Var { ident: String, value: Expr, }, Assignment { ident: String, value: Expr, }, Function { ident: String, arguments: Vec, return_type: String, body: Vec, }, If { condition: Expr, body: Vec, }, For { binding: String, range: (Expr, Expr), body: Vec, }, While { condition: Expr, body: Vec, }, Return { value: Expr, }, } #[derive(Debug, Eq, PartialEq)] pub struct FunctionArgument { name: String, types: String, } #[derive(Debug, Eq, PartialEq)] pub enum Expr { Literal(Literal), Variable(String), Grouping(Box), Call { ident: String, arguments: Vec, }, Binary { operator: TokenType, lhs: Box, rhs: Box, }, Unary { operator: TokenType, expr: Box, }, } pub trait AstVisitor { fn visit_stmt(&mut self, stmt: &Stmt) -> T; fn visit_expr(&mut self, expr: &Expr) -> T; }