diff options
Diffstat (limited to 'src/ast.rs')
-rw-r--r-- | src/ast.rs | 24 |
1 files changed, 23 insertions, 1 deletions
@@ -1,5 +1,27 @@ #[derive(Debug)] -pub struct Program(pub Box<Expression>); +pub struct WithLocation<T> { + value: T, + location: (usize, usize), +} + +impl<T> WithLocation<T> { + pub fn new(value: T, start: usize, end: usize) -> WithLocation<T> { + WithLocation { + value: value, + location: (start, end), + } + } + + pub fn map<U, F: FnOnce(T) -> U>(self, f: F) -> WithLocation<U> { + WithLocation { + value: f(self.value), + location: self.location, + } + } +} + +#[derive(Debug)] +pub struct Program(pub Box<WithLocation<Expression>>); #[derive(Debug)] pub enum Expression { |