summaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
authorMike Buland <mike@xagasoft.com>2026-06-04 22:21:50 -0700
committerMike Buland <mike@xagasoft.com>2026-06-04 22:21:50 -0700
commit414681bc8b8ccbff81c0878fbf3ff193f7f55e0f (patch)
tree8d09ec9e8516f5daf8b01d8f273210398a8e2305 /src/lib.rs
parent4c223b1c4ebfa7a14933229dd4537c825d9ea063 (diff)
downloadcrimtag-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.rs53
1 files changed, 47 insertions, 6 deletions
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 @@
1use std::path::{PathBuf,Path}; 1use std::path::{PathBuf,Path};
2use std::collections::HashMap; 2use std::collections::HashMap;
3use core::error::Error; 3use core::error::Error;
4use std::time::SystemTime;
4 5
5mod lexer; 6mod lexer;
6 7
7pub struct Tx { 8pub 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)]
11enum FragmentSource { 14enum 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
18struct Fragment { 25struct 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}