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/lib.rs | 53 +++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 47 insertions(+), 6 deletions(-) (limited to 'src/lib.rs') 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