diff options
Diffstat (limited to 'src/lexer.rs')
| -rw-r--r-- | src/lexer.rs | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/lexer.rs b/src/lexer.rs index d6806d8..46651c4 100644 --- a/src/lexer.rs +++ b/src/lexer.rs | |||
| @@ -34,6 +34,16 @@ pub struct Lexer<'a> { | |||
| 34 | row: u32, | 34 | row: u32, |
| 35 | } | 35 | } |
| 36 | 36 | ||
| 37 | fn is_valid_token_char( c: char ) -> bool { | ||
| 38 | if c.is_whitespace() { | ||
| 39 | return false; | ||
| 40 | } | ||
| 41 | match c { | ||
| 42 | 'a'..'z' | 'A'..'Z' | '0'..'9' => true, | ||
| 43 | _ => false | ||
| 44 | } | ||
| 45 | } | ||
| 46 | |||
| 37 | impl<'a> Lexer<'a> { | 47 | impl<'a> Lexer<'a> { |
| 38 | pub fn new( data: &'a str ) -> Lexer<'a> { | 48 | pub fn new( data: &'a str ) -> Lexer<'a> { |
| 39 | let mut chars = data.char_indices(); | 49 | let mut chars = data.char_indices(); |
| @@ -153,7 +163,7 @@ impl<'a> Lexer<'a> { | |||
| 153 | } | 163 | } |
| 154 | let start = self.cur_index(); | 164 | let start = self.cur_index(); |
| 155 | 165 | ||
| 156 | while self.next().is_some_and(|ch| !ch.is_whitespace() ) && | 166 | while self.next().is_some_and(|ch| is_valid_token_char(ch) ) && |
| 157 | !self.is_end_tag() {} | 167 | !self.is_end_tag() {} |
| 158 | let end = self.cur_index(); | 168 | let end = self.cur_index(); |
| 159 | let s = &self.data[start..end]; | 169 | let s = &self.data[start..end]; |
