-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(lexer): improve lexer structure
- Loading branch information
1 parent
322fcfc
commit b4f3562
Showing
4 changed files
with
247 additions
and
229 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
use std::collections::HashMap; | ||
|
||
use super::Terminal; | ||
|
||
/// Struct for storing terminal symbols with their respective "key". | ||
#[derive(Debug, Clone, Default)] | ||
pub struct LexMap { | ||
map: HashMap<&'static str, Terminal>, | ||
} | ||
|
||
impl LexMap { | ||
pub fn insert(&mut self, key: &'static str, value: Terminal) { | ||
self.map.insert(key, value); | ||
} | ||
|
||
pub fn can_match(&self, key: &str) -> bool { | ||
for map_key in self.map.keys() { | ||
if map_key.starts_with(key) { | ||
return true; | ||
} | ||
} | ||
false | ||
} | ||
|
||
pub fn get(&self, key: &str) -> Option<Terminal> { | ||
self.map.get(key).cloned() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.