1use html_escape;
2
3mod token_type;
4pub use token_type::TokenType;
5mod token_stream;
6pub use token_stream::TokenStream;
7mod token_blocks;
8pub use token_blocks::TokenBlocks;
9pub mod lex;
10
11#[derive(PartialEq, Default, Debug, Clone)]
15pub struct TokenImpl<T>
16where
17 T: TokenType,
18{
19 pub token_type: T,
21 pub value: String,
23 pub pos: (usize, usize),
26}
27
28impl<T> TokenImpl<T>
29where
30 T: TokenType,
31{
32 #[inline]
34 pub fn into<TO>(self) -> TokenImpl<TO>
35 where
36 TO: From<T> + TokenType,
37 {
38 TokenImpl {
39 token_type: self.token_type.into(),
40 value: self.value,
41 pos: self.pos,
42 }
43 }
44 #[inline]
45 pub fn to_html_text(&self) -> String {
47 html_escape::encode_text(&self.value).to_string()
48 }
49
50 pub fn to_html(&self) -> String {
54 let text = self.to_html_text();
55 match self.token_type.html_class() {
56 None => text,
57 Some(class_name) => {
58 format!(r#"<span class="{class_name}">{text}</span>"#)
59 }
60 }
61 }
62}