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
pub mod strmatcher;
pub mod general;
pub mod literals;
pub mod keywords;
pub mod comments;
pub use general::*;
use std::error::Error;
use crate::lexer::Token;
trait WordChar {
fn is_word_alphanumeric(&self) -> bool;
fn is_word_alphabetic(&self) -> bool;
fn is_word_ascii_alphanumeric(&self) -> bool;
fn is_word_ascii_alphabetic(&self) -> bool;
}
impl WordChar for char {
fn is_word_alphanumeric(&self) -> bool {
*self == '_' || self.is_alphanumeric()
}
fn is_word_alphabetic(&self) -> bool {
*self == '_' || self.is_alphabetic()
}
fn is_word_ascii_alphanumeric(&self) -> bool {
*self == '_' || self.is_ascii_alphanumeric()
}
fn is_word_ascii_alphabetic(&self) -> bool {
*self == '_' || self.is_ascii_alphabetic()
}
}
#[derive(Clone, Copy)]
pub enum MatchResult {
IncompleteMatch,
CompleteMatch,
NoMatch,
}
impl MatchResult {
pub fn is_match(&self) -> bool {
match self {
MatchResult::IncompleteMatch | MatchResult::CompleteMatch => true,
MatchResult::NoMatch => false,
}
}
pub fn is_complete_match(&self) -> bool { matches!(self, MatchResult::CompleteMatch) }
pub fn is_incomplete_match(&self) -> bool { matches!(self, MatchResult::IncompleteMatch) }
}
type TokenError = Box<dyn Error + 'static>;
pub trait LexerRule: __LexerRule_Clone {
fn reset(&mut self);
fn current_state(&self) -> MatchResult;
fn try_match(&mut self, prev: Option<char>, next: char) -> MatchResult;
fn get_token(&self) -> Result<Token, TokenError>;
}
#[allow(non_camel_case_types)]
pub trait __LexerRule_Clone {
fn __clone_box(&self) -> Box<dyn LexerRule>;
}
impl<T> __LexerRule_Clone for T where T: 'static + LexerRule + Clone {
fn __clone_box(&self) -> Box<dyn LexerRule> { Box::new(self.clone()) }
}
impl Clone for Box<dyn LexerRule> {
fn clone(&self) -> Box<dyn LexerRule> { self.__clone_box() }
}