makepad_live_tokenizer/
full_token.rs1use {
2 std::{
3 rc::Rc,
4 ops::Deref,
5 ops::DerefMut,
6 },
7 crate::live_id::LiveId
8};
9
10#[derive(Clone, Debug, PartialEq)]
11pub struct TokenWithLen {
12 pub len: usize,
13 pub token: FullToken,
14}
15
16impl Deref for TokenWithLen {
17 type Target = FullToken;
18 fn deref(&self) -> &Self::Target {&self.token}
19}
20
21impl DerefMut for TokenWithLen {
22 fn deref_mut(&mut self) -> &mut Self::Target {&mut self.token}
23}
24
25#[derive(Clone, Debug, PartialEq)]
26pub enum FullToken {
27 Punct(LiveId),
28 Ident(LiveId),
29
30 Open(Delim),
31 Close(Delim),
32
33 String(Rc<String>),
34 Bool(bool),
35 Color(u32),
36 Float(f64),
37 Int(i64),
38
39 OtherNumber,
40 Lifetime,
41 Comment,
42 Whitespace,
43 Unknown,
44}
45
46impl FullToken {
47 pub fn is_whitespace(&self)-> bool {
48 matches!(self, FullToken::Whitespace)
49 }
50
51 pub fn is_comment(&self) -> bool {
52 matches!(self, FullToken::Comment)
53 }
54
55 pub fn is_ws_or_comment(&self)->bool{
56 matches!(self, FullToken::Whitespace | FullToken::Comment)
57 }
58
59 pub fn is_open(&self) -> bool {
60 matches!(self, FullToken::Open(_))
61 }
62
63 pub fn is_close(&self) -> bool {
64 matches!(self, FullToken::Close(_))
65 }
66
67 pub fn is_open_delim(&self, delim: Delim) -> bool {
68 match self {
69 FullToken::Open(d) => *d == delim,
70 _ => false
71 }
72 }
73
74 pub fn is_close_delim(&self, delim: Delim) -> bool {
75 match self {
76 FullToken::Close(d) => *d == delim,
77 _ => false
78 }
79 }
80
81 pub fn is_int(&self) -> bool {
82 matches!(self, FullToken::Int(_))
83 }
84
85 pub fn is_float(&self) -> bool {
86 matches!(self, FullToken::Float(_))
87 }
88
89
90 pub fn is_color(&self) -> bool {
91 matches!(self, FullToken::Color(_))
92 }
93
94 pub fn is_parsed_number(&self) -> bool {
95 matches!(self, FullToken::Int(_) | FullToken::Float(_))
96 }
97
98
99 pub fn is_bool(&self) -> bool {
100 matches!(self, FullToken::Bool(_))
101 }
102
103 pub fn is_value_type(&self) -> bool {
104 matches!(
105 self,
106 FullToken::Color(_)
107 | FullToken::Bool(_)
108 | FullToken::Int(_)
109 | FullToken::Float(_)
110 )
111 }
112
113 pub fn is_ident(&self) -> bool {
114 matches!(self, FullToken::Ident(_))
115 }
116
117 pub fn is_punct(&self) -> bool {
118 matches!(self, FullToken::Punct(_))
119 }
120
121 pub fn is_punct_id(&self, id: LiveId) -> bool {
122 match self {
123 FullToken::Punct(v) => *v == id,
124 _ => false
125 }
126 }
127}
128
129#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
130pub enum Delim {
131 Paren,
132 Bracket,
133 Brace,
134}