#[derive(Debug)] pub struct WithLocation { pub value: T, pub start: usize, pub end: usize, } impl WithLocation { pub fn new(value: T, start: usize, end: usize) -> WithLocation { WithLocation { value: value, start: start, end: end, } } pub fn map U>(self, f: F) -> WithLocation { WithLocation { value: f(self.value), start: self.start, end: self.end, } } pub fn join_map(self, other: WithLocation, f: F) -> WithLocation where F: FnOnce(WithLocation, WithLocation) -> V { let start = self.start; let end = other.end; WithLocation { value: f(self, other), start: start, end: end, } } } #[derive(Debug)] pub struct Program(pub Box>); #[derive(Debug)] pub enum UnaryOp { Pos, Neg, Not, } #[derive(Debug)] pub enum BinOp { Add, Sub, Mul, Div, FloorDiv, Eq, Neq, Gt, Lt, Ge, Le, And, Or, } #[derive(Debug)] pub enum Expression { Let(Vec>, Box>), UnaryOp(UnaryOp, Box>), BinOp(BinOp, Box>, Box>), Number(u64), String(String), Name(String), Nil, } #[derive(Debug)] pub struct VarDec { pub name: WithLocation, pub type_: Option, pub value: Box>, } impl VarDec { pub fn new(name: WithLocation, type_: Option, value: Box>) -> VarDec { VarDec { name: name, type_: type_, value: value, } } }