From 414681bc8b8ccbff81c0878fbf3ff193f7f55e0f Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Thu, 4 Jun 2026 22:21:50 -0700 Subject: Lexer is done for now. Now for the scaffold. ALso the parser is next up. But I want to get some frontend done so it won't whine at me so much. The lexer has a lot more to go, I'm sure, but right now it does all the basics that I need it to do. --- src/lexer.rs | 13 +++++++++---- src/lib.rs | 53 +++++++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 56 insertions(+), 10 deletions(-) diff --git a/src/lexer.rs b/src/lexer.rs index 46651c4..e80e461 100644 --- a/src/lexer.rs +++ b/src/lexer.rs @@ -39,7 +39,7 @@ fn is_valid_token_char( c: char ) -> bool { return false; } match c { - 'a'..'z' | 'A'..'Z' | '0'..'9' => true, + 'a'..'z' | 'A'..'Z' | '0'..'9' | '_' | '-' => true, _ => false } } @@ -157,9 +157,14 @@ impl<'a> Lexer<'a> { fn parse_token(&mut self) -> Option> { self.skip_ws(); - if let Some(chr) = self.cur() && chr == '"' { - // Literal string - return self.parse_literal_str(); + match self.cur() { + Some('"') => { + return self.parse_literal_str(); + } + Some('=') => { + return Some(Symbol::Equals); + } + _ => {} } let start = self.cur_index(); diff --git a/src/lib.rs b/src/lib.rs index 57f777e..16bef07 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,23 +1,30 @@ use std::path::{PathBuf,Path}; use std::collections::HashMap; use core::error::Error; +use std::time::SystemTime; mod lexer; pub struct Tx { - fragments: HashMap, + fragments: HashMap, + sources: Vec, } +#[derive(PartialEq,Eq,Debug,Clone)] enum FragmentSource { File { path: PathBuf, - loaded: usize, - } + loaded: SystemTime, + }, + Static, + External { + key: String, + }, } struct Fragment { name: String, - source: FragmentSource, + source: usize, sections: HashMap, } @@ -43,14 +50,48 @@ impl Tx { pub fn new() -> Self { Self { fragments: HashMap::new(), + sources: vec![Frament::Static], } } - pub fn load(path: &Path) -> Result<(),Box::> { + fn id_source(&mut self, src: &FragmentSource ) -> usize { + for idx in 0..self.sources.len() { + if self.sources[idx] == src { + return idx; + } + } + + // Nothing found, add a new one + let idx = self.sources.len(); + self.sources.push( src.clone() ); + idx + } + + pub fn load_file(&mut self, path: &Path) -> Result<(),Box::> { + let time = if let Ok(meta) = path.metadata() { + if let Ok(t) = meta.modified() { + t + } else if let Ok(t) = meta.created() { + t + } else { + SystemTime::now() + } + } else { + SystemTime.now() + }; + + let mut file = File::open( path )?; + + let mut ll = lexer::Lexer( &String::from_utf8( file.read()? )? ); + Ok(()) + } + + pub fn load_static(&mut self, data: &str) -> Result<(),Box::> { + Ok(()) } - pub fn parse(data: String) -> Result<(),Box::> { + pub fn load_external(&mut self, key: &str, data: &str) -> Result<(),Box::> { Ok(()) } } -- cgit v1.2.3