diff options
Diffstat (limited to 'src/ast.rs')
-rw-r--r-- | src/ast.rs | 18 |
1 files changed, 11 insertions, 7 deletions
@@ -1,32 +1,36 @@ #[derive(Debug)] pub struct WithLocation<T> { - value: T, - location: (usize, usize), + pub value: T, + pub start: usize, + pub end: usize, } impl<T> WithLocation<T> { pub fn new(value: T, start: usize, end: usize) -> WithLocation<T> { WithLocation { value: value, - location: (start, end), + start: start, + end: end, } } pub fn map<U, F: FnOnce(T) -> U>(self, f: F) -> WithLocation<U> { WithLocation { value: f(self.value), - location: self.location, + start: self.start, + end: self.end, } } pub fn join_map<U, V, F>(self, other: WithLocation<U>, f: F) -> WithLocation<V> where F: FnOnce(WithLocation<T>, WithLocation<U>) -> V { - let loc1 = self.location; - let loc2 = other.location; + let start = self.start; + let end = other.end; WithLocation { value: f(self, other), - location: (loc1.0, loc2.1), + start: start, + end: end, } } } |