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
30
31
32
33
34
35
36
37
38
pub type IntType = i64;
pub type FloatType = f64;
pub enum Number {
Int(IntType),
Float(FloatType),
None,
}
#[derive(Debug, Copy, Clone, PartialEq)]
pub struct Source {
pub pos: usize,
pub length: usize,
pub line: usize,
pub col: usize,
}
impl Source {
pub fn new() -> Self {
Source {
pos: 0,
length: 0,
line: 0,
col: 0,
}
}
}
use std::ops;
impl ops::Sub<Source> for Source {
type Output = Source;
fn sub(self, rhs: Source) -> Source {
Source {
pos: rhs.pos,
length: self.pos + self.length - rhs.pos,
line: rhs.line,
col: rhs.col,
}
}
}