summaryrefslogtreecommitdiff
path: root/src/ast.rs
blob: 3863ce9387979437015fd5da50f66ee2d8342301 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#[derive(Debug)]
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 {
    Number(u64),
}