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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
use {
    std::{
        rc::Rc,
        ops::Deref,
        ops::DerefMut,
    },
    crate::live_id::LiveId
};

#[derive(Clone, Debug, PartialEq)]
pub struct TokenWithLen {
    pub len: usize,
    pub token: FullToken,
}

impl Deref for TokenWithLen {
    type Target = FullToken;
    fn deref(&self) -> &Self::Target {&self.token}
}

impl DerefMut for TokenWithLen {
    fn deref_mut(&mut self) -> &mut Self::Target {&mut self.token}
}

#[derive(Clone, Debug, PartialEq)]
pub enum FullToken {
    Punct(LiveId),
    Ident(LiveId),
    
    Open(Delim),
    Close(Delim),

    String(Rc<String>),
    Bool(bool),
    Color(u32),
    Float(f64),
    Int(i64),
    
    OtherNumber,
    Lifetime,
    Comment,
    Whitespace,
    Unknown,
}

impl FullToken {
    pub fn is_whitespace(&self)-> bool {
        matches!(self, FullToken::Whitespace)
    }

    pub fn is_comment(&self) -> bool {
        matches!(self, FullToken::Comment)
    }
    
    pub fn is_ws_or_comment(&self)->bool{
        matches!(self, FullToken::Whitespace | FullToken::Comment)
    }
        
    pub fn is_open(&self) -> bool {
        matches!(self, FullToken::Open(_))
    }
    
    pub fn is_close(&self) -> bool {
        matches!(self, FullToken::Close(_))
    }
    
    pub fn is_open_delim(&self, delim: Delim) -> bool {
        match self {
            FullToken::Open(d) => *d == delim,
            _ => false
        }
    }
    
    pub fn is_close_delim(&self, delim: Delim) -> bool {
        match self {
            FullToken::Close(d) => *d == delim,
            _ => false
        }
    }
    
    pub fn is_int(&self) -> bool {
        matches!(self, FullToken::Int(_))
    }
    
    pub fn is_float(&self) -> bool {
        matches!(self, FullToken::Float(_))
    }
    
        
    pub fn is_color(&self) -> bool {
        matches!(self, FullToken::Color(_))
    }

    pub fn is_parsed_number(&self) -> bool {
        matches!(self, FullToken::Int(_) | FullToken::Float(_))
    }


    pub fn is_bool(&self) -> bool {
        matches!(self, FullToken::Bool(_))
    }
    
    pub fn is_value_type(&self) -> bool {
        matches!(
            self,
            FullToken::Color(_)
                | FullToken::Bool(_)
                | FullToken::Int(_)
                | FullToken::Float(_)
        )
    }
    
    pub fn is_ident(&self) -> bool {
        matches!(self, FullToken::Ident(_))
    }
    
    pub fn is_punct(&self) -> bool {
        matches!(self, FullToken::Punct(_))
    }
    
    pub fn is_punct_id(&self, id: LiveId) -> bool {
        match self {
            FullToken::Punct(v) => *v == id,
            _ => false
        }
    }
}

#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub enum Delim {
    Paren,
    Bracket,
    Brace,
}