makepad_live_compiler/
span.rs

1use{
2    std::fmt,
3    crate::{
4   //     makepad_live_tokenizer::Position,
5        live_token::LiveTokenId,
6        live_ptr::LiveFileId
7    }
8};
9
10#[derive(Clone, Copy, Default, Eq, Ord, PartialOrd, PartialEq)]
11pub struct TextPos {
12    pub line: u32,
13    pub column: u32
14}
15/*
16impl From<TextPos> for Position {
17    fn from(text_pos: TextPos) -> Position {
18        Position{
19            line:text_pos.line as usize,
20            column:text_pos.column as usize
21        }
22    }*/
23
24#[derive(Clone, Copy, Default, Eq, Ord, PartialOrd, PartialEq)]
25pub struct TextSpan {
26    pub file_id: LiveFileId,
27    pub start: TextPos,
28    pub end: TextPos
29}
30
31#[derive(Clone, Copy, Default, Debug,  Eq, Ord, PartialOrd, PartialEq)]
32pub struct TokenSpan {
33    pub token_id: LiveTokenId,
34    pub len: usize
35}
36
37impl From<LiveTokenId> for TokenSpan {
38    fn from(val: LiveTokenId) -> Self {
39        TokenSpan { token_id: val, len: 1 }
40    }
41}
42
43impl fmt::Display for TextSpan {
44    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
45        write!(f, "Span(start:{}, end:{}, file_id:{})", self.start, self.end, self.file_id.to_index())
46    }
47}
48
49impl fmt::Debug for TextSpan {
50    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
51        write!(f, "Span(start:{}, end:{}, file_id:{})", self.start, self.end, self.file_id.to_index())
52    }
53}
54
55impl fmt::Display for TextPos {
56    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
57        write!(f, "{}:{}", self.line, self.column)
58    }
59}
60
61impl fmt::Debug for TextPos {
62    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
63        write!(f, "{}:{}", self.line, self.column)
64    }
65}
66