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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
use parse_display::Display;
#[derive(Default, Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Display)]
#[display("{source_id}:{offset}")]
pub struct LexerPosition {
pub source_id: usize,
pub offset: usize,
}
impl LexerPosition {
pub fn new(source_id: usize, offset: usize) -> Self {
Self { source_id, offset }
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct NodeSpan {
pub source_id: usize,
pub start: usize,
pub end: usize,
}
impl NodeSpan {
pub fn new_start(source_id: usize) -> Self {
Self {
source_id,
start: 0,
end: 0,
}
}
pub fn new_end(source_id: usize, length: usize) -> Self {
Self {
source_id,
start: length,
end: length,
}
}
pub fn to_end_location(&self) -> Self {
Self {
source_id: self.source_id,
start: self.end,
end: self.end,
}
}
pub fn length(&self) -> usize {
self.end - self.start
}
}