summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lexer.rs13
-rw-r--r--src/lib.rs53
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 {
39 return false; 39 return false;
40 } 40 }
41 match c { 41 match c {
42 'a'..'z' | 'A'..'Z' | '0'..'9' => true, 42 'a'..'z' | 'A'..'Z' | '0'..'9' | '_' | '-' => true,
43 _ => false 43 _ => false
44 } 44 }
45} 45}
@@ -157,9 +157,14 @@ impl<'a> Lexer<'a> {
157 157
158 fn parse_token(&mut self) -> Option<Symbol<'a>> { 158 fn parse_token(&mut self) -> Option<Symbol<'a>> {
159 self.skip_ws(); 159 self.skip_ws();
160 if let Some(chr) = self.cur() && chr == '"' { 160 match self.cur() {
161 // Literal string 161 Some('"') => {
162 return self.parse_literal_str(); 162 return self.parse_literal_str();
163 }
164 Some('=') => {
165 return Some(Symbol::Equals);
166 }
167 _ => {}
163 } 168 }
164 let start = self.cur_index(); 169 let start = self.cur_index();
165 170
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}