gtk_ui_builder/parser/
tokenize_error.rs1use std::io::{Error, ErrorKind};
2
3#[derive(Debug, Clone, PartialEq, Eq)]
4pub enum TokenizeError {
5 IncorrectChar {
6 message: String,
7 wrong_string: String,
8 offset: usize
9 },
10 IncorrectString {
11 message: String,
12 begin: usize,
13 end: usize,
14 wrong_string: String
15 },
16 IncorrectBrackets {
17 message: String,
18 begin: usize,
19 end: usize,
20 wrong_string: String
21 }
22}
23
24impl TokenizeError {
25 pub fn get_message(&self) -> &str {
26 match self {
27 Self::IncorrectChar { message, .. } => message,
28 Self::IncorrectString { message, .. } => message,
29 Self::IncorrectBrackets { message, .. } => message
30 }.as_str()
31 }
32
33 pub fn offset(mut self, num: usize) -> Self {
34 match &mut self {
35 TokenizeError::IncorrectChar { offset, .. } => *offset += num,
36
37 TokenizeError::IncorrectString { begin, end, .. } |
38 TokenizeError::IncorrectBrackets { begin, end, .. } => {
39 *begin += num;
40 *end += num;
41 }
42 }
43
44 self
45 }
46}
47
48impl Into<Error> for TokenizeError {
49 fn into(self) -> Error {
50 Error::new(ErrorKind::Other, self.get_message())
51 }
52}