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
use{
std::fmt,
crate::{
live_token::LiveTokenId,
live_ptr::LiveFileId
}
};
#[derive(Clone, Copy, Default, Eq, Ord, PartialOrd, PartialEq)]
pub struct TextPos {
pub line: u32,
pub column: u32
}
#[derive(Clone, Copy, Default, Eq, Ord, PartialOrd, PartialEq)]
pub struct TextSpan {
pub file_id: LiveFileId,
pub start: TextPos,
pub end: TextPos
}
#[derive(Clone, Copy, Default, Debug, Eq, Ord, PartialOrd, PartialEq)]
pub struct TokenSpan {
pub token_id: LiveTokenId,
pub len: usize
}
impl Into<TokenSpan> for LiveTokenId{
fn into(self)->TokenSpan{
TokenSpan{token_id:self, len:1}
}
}
impl fmt::Display for TextSpan {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Span(start:{}, end:{}, file_id:{})", self.start, self.end, self.file_id.to_index())
}
}
impl fmt::Debug for TextSpan {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Span(start:{}, end:{}, file_id:{})", self.start, self.end, self.file_id.to_index())
}
}
impl fmt::Display for TextPos {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}:{}", self.line, self.column)
}
}
impl fmt::Debug for TextPos {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}:{}", self.line, self.column)
}
}