diff options
author | David Li <li.davidm96@gmail.com> | 2017-11-04 08:34:52 -0400 |
---|---|---|
committer | David Li <li.davidm96@gmail.com> | 2017-11-04 08:34:52 -0400 |
commit | 35bf004cc923c1bd61a75fa0ff9b336644f0c8b0 (patch) | |
tree | 4a06430b9289a03f047a4650c51149078887ec5b /src/ast.rs | |
parent | 8b3f3271be72b89f557d84238f9e3df5c1ea418c (diff) |
Add location information to AST
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 { |