diff options
| author | Mike Buland <mike@xagasoft.com> | 2026-06-04 22:21:50 -0700 |
|---|---|---|
| committer | Mike Buland <mike@xagasoft.com> | 2026-06-04 22:21:50 -0700 |
| commit | 414681bc8b8ccbff81c0878fbf3ff193f7f55e0f (patch) | |
| tree | 8d09ec9e8516f5daf8b01d8f273210398a8e2305 /src/lib.rs | |
| parent | 4c223b1c4ebfa7a14933229dd4537c825d9ea063 (diff) | |
| download | crimtag-414681bc8b8ccbff81c0878fbf3ff193f7f55e0f.tar.gz crimtag-414681bc8b8ccbff81c0878fbf3ff193f7f55e0f.tar.bz2 crimtag-414681bc8b8ccbff81c0878fbf3ff193f7f55e0f.tar.xz crimtag-414681bc8b8ccbff81c0878fbf3ff193f7f55e0f.zip | |
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.
Diffstat (limited to 'src/lib.rs')
| -rw-r--r-- | src/lib.rs | 53 |
1 files changed, 47 insertions, 6 deletions
| @@ -1,23 +1,30 @@ | |||
| 1 | use std::path::{PathBuf,Path}; | 1 | use std::path::{PathBuf,Path}; |
| 2 | use std::collections::HashMap; | 2 | use std::collections::HashMap; |
| 3 | use core::error::Error; | 3 | use core::error::Error; |
| 4 | use std::time::SystemTime; | ||
| 4 | 5 | ||
| 5 | mod lexer; | 6 | mod lexer; |
| 6 | 7 | ||
| 7 | pub struct Tx { | 8 | pub struct Tx { |
| 8 | fragments: HashMap<String, Fragment>, | 9 | fragments: HashMap<String, Fragment>, |
| 10 | sources: Vec<FragmentSource>, | ||
| 9 | } | 11 | } |
| 10 | 12 | ||
| 13 | #[derive(PartialEq,Eq,Debug,Clone)] | ||
| 11 | enum FragmentSource { | 14 | enum FragmentSource { |
| 12 | File { | 15 | File { |
| 13 | path: PathBuf, | 16 | path: PathBuf, |
| 14 | loaded: usize, | 17 | loaded: SystemTime, |
| 15 | } | 18 | }, |
| 19 | Static, | ||
| 20 | External { | ||
| 21 | key: String, | ||
| 22 | }, | ||
| 16 | } | 23 | } |
| 17 | 24 | ||
| 18 | struct Fragment { | 25 | struct Fragment { |
| 19 | name: String, | 26 | name: String, |
| 20 | source: FragmentSource, | 27 | source: usize, |
| 21 | sections: HashMap<String, Section>, | 28 | sections: HashMap<String, Section>, |
| 22 | } | 29 | } |
| 23 | 30 | ||
| @@ -43,14 +50,48 @@ impl Tx { | |||
| 43 | pub fn new() -> Self { | 50 | pub fn new() -> Self { |
| 44 | Self { | 51 | Self { |
| 45 | fragments: HashMap::new(), | 52 | fragments: HashMap::new(), |
| 53 | sources: vec![Frament::Static], | ||
| 46 | } | 54 | } |
| 47 | } | 55 | } |
| 48 | 56 | ||
| 49 | pub fn load(path: &Path) -> Result<(),Box::<dyn Error>> { | 57 | fn id_source(&mut self, src: &FragmentSource ) -> usize { |
| 58 | for idx in 0..self.sources.len() { | ||
| 59 | if self.sources[idx] == src { | ||
| 60 | return idx; | ||
| 61 | } | ||
| 62 | } | ||
| 63 | |||
| 64 | // Nothing found, add a new one | ||
| 65 | let idx = self.sources.len(); | ||
| 66 | self.sources.push( src.clone() ); | ||
| 67 | idx | ||
| 68 | } | ||
| 69 | |||
| 70 | pub fn load_file(&mut self, path: &Path) -> Result<(),Box::<dyn Error>> { | ||
| 71 | let time = if let Ok(meta) = path.metadata() { | ||
| 72 | if let Ok(t) = meta.modified() { | ||
| 73 | t | ||
| 74 | } else if let Ok(t) = meta.created() { | ||
| 75 | t | ||
| 76 | } else { | ||
| 77 | SystemTime::now() | ||
| 78 | } | ||
| 79 | } else { | ||
| 80 | SystemTime.now() | ||
| 81 | }; | ||
| 82 | |||
| 83 | let mut file = File::open( path )?; | ||
| 84 | |||
| 85 | let mut ll = lexer::Lexer( &String::from_utf8( file.read()? )? ); | ||
| 86 | Ok(()) | ||
| 87 | } | ||
| 88 | |||
| 89 | pub fn load_static(&mut self, data: &str) -> Result<(),Box::<dyn Error>> { | ||
| 90 | |||
| 50 | Ok(()) | 91 | Ok(()) |
| 51 | } | 92 | } |
| 52 | 93 | ||
| 53 | pub fn parse(data: String) -> Result<(),Box::<dyn Error>> { | 94 | pub fn load_external(&mut self, key: &str, data: &str) -> Result<(),Box::<dyn Error>> { |
| 54 | Ok(()) | 95 | Ok(()) |
| 55 | } | 96 | } |
| 56 | } | 97 | } |
