summaryrefslogtreecommitdiff
path: root/src/lexer.rs
diff options
context:
space:
mode:
authorMike Buland <mike@xagasoft.com>2026-06-04 15:58:26 -0700
committerMike Buland <mike@xagasoft.com>2026-06-04 15:58:26 -0700
commit4c223b1c4ebfa7a14933229dd4537c825d9ea063 (patch)
treeb771a810c2389ddf1a88be670105dc98e35abf38 /src/lexer.rs
parent057bd8cb2d4a1539701d65489fe647b96a538e98 (diff)
downloadcrimtag-4c223b1c4ebfa7a14933229dd4537c825d9ea063.tar.gz
crimtag-4c223b1c4ebfa7a14933229dd4537c825d9ea063.tar.bz2
crimtag-4c223b1c4ebfa7a14933229dd4537c825d9ea063.tar.xz
crimtag-4c223b1c4ebfa7a14933229dd4537c825d9ea063.zip
Minor change to token parsing.
Tokens now can only have a-z, A-Z, or 0-9 in them, we can add more later, _ and - maybe? but this lets us easily break on = and other things we may want.
Diffstat (limited to 'src/lexer.rs')
-rw-r--r--src/lexer.rs12
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
37fn 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
37impl<'a> Lexer<'a> { 47impl<'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];