#[derive(Debug)] pub struct WithLocation { value: T, location: (usize, usize), } impl WithLocation { pub fn new(value: T, start: usize, end: usize) -> WithLocation { WithLocation { value: value, location: (start, end), } } pub fn map U>(self, f: F) -> WithLocation { WithLocation { value: f(self.value), location: self.location, } } pub fn join_map(self, other: WithLocation, f: F) -> WithLocation where F: FnOnce(WithLocation, WithLocation) -> V { let loc1 = self.location; let loc2 = other.location; WithLocation { value: f(self, other), location: (loc1.0, loc2.1), } } } #[derive(Debug)] pub struct Program(pub Box>); #[derive(Debug)] pub enum BinOp { Add, Sub, Mul, Div, FloorDiv, } #[derive(Debug)] pub enum Expression { BinOp(BinOp, Box>, Box>), Number(u64), Nil, }