summaryrefslogtreecommitdiff
path: root/src/ast.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/ast.rs')
-rw-r--r--src/ast.rs24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/ast.rs b/src/ast.rs
index b5f2049..3863ce9 100644
--- a/src/ast.rs
+++ b/src/ast.rs
@@ -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 {