Tholp's bespoke website generator

add !filename and !filename_cannonical, ProjectContext::file_for_index_cannonical

Tholp1 34f76f44 f01552d0

+65 -6
+2 -2
src/macros/insert.rs
··· 20 20 _scope: &[Token], 21 21 ) -> Vec<Token> { 22 22 let origin_file = context 23 - .file_for_index(origin_index) 23 + .file_for_index_cannonical(origin_index) 24 24 .expect("Macro 'Insert' was given a bad origin index") 25 25 .clone(); 26 26 if args.len() != 1 { ··· 67 67 } 68 68 69 69 if !ok { 70 - println!("[ERROR] \"{:?}\": Insert was unable to find the file \"{}\" relative to its origin or in project root.", origin_file.to_str(), arg); 70 + println!("[ERROR] {:?}: Insert was unable to find the file \"{}\" relative to its origin or in project root.", origin_file.to_str().unwrap(), arg); 71 71 exit(1); 72 72 } 73 73
+11 -1
src/macros/mod.rs
··· 6 6 7 7 use insert::macro_insert; 8 8 use simple_blocks::{macro_comment, macro_repeat, macro_section, macro_skip}; 9 - use simple_macros::{macro_clear, macro_time}; 9 + use simple_macros::{macro_clear, macro_filename, macro_filename_cannonical, macro_time}; 10 10 use template::macro_template; 11 11 12 12 pub static MACRO_LIST: &'static [Macro<'_>] = &[ ··· 24 24 Macro { 25 25 symbol: "time", 26 26 expand: macro_time, 27 + has_scope: false, 28 + }, 29 + Macro { 30 + symbol: "filename", 31 + expand: macro_filename, 32 + has_scope: false, 33 + }, 34 + Macro { 35 + symbol: "filename_cannonical", 36 + expand: macro_filename_cannonical, 27 37 has_scope: false, 28 38 }, 29 39 // Scoped
+39
src/macros/simple_macros.rs
··· 1 + // This file for implementations of short macros, im qualifying that as less than 30ish lines 1 2 use std::process::exit; 2 3 3 4 use chrono::{DateTime, Local}; ··· 48 49 49 50 return split_to_tokens(t.format(&args[0]).to_string(), origin_index); 50 51 } 52 + 53 + pub fn macro_filename( 54 + _file: &mut InputFile, 55 + origin_index: usize, 56 + _origin_line: usize, 57 + context: &mut ProjectContext, 58 + _args: &Vec<String>, 59 + _scope: &[Token], 60 + ) -> Vec<Token> { 61 + return split_to_tokens( 62 + context 63 + .file_for_index(origin_index) 64 + .unwrap() 65 + .to_str() 66 + .unwrap() 67 + .into(), 68 + origin_index, 69 + ); 70 + } 71 + 72 + pub fn macro_filename_cannonical( 73 + _file: &mut InputFile, 74 + origin_index: usize, 75 + _origin_line: usize, 76 + context: &mut ProjectContext, 77 + _args: &Vec<String>, 78 + _scope: &[Token], 79 + ) -> Vec<Token> { 80 + return split_to_tokens( 81 + context 82 + .file_for_index_cannonical(origin_index) 83 + .unwrap() 84 + .to_str() 85 + .unwrap() 86 + .into(), 87 + origin_index, 88 + ); 89 + }
+1 -1
src/main.rs
··· 249 249 if !matched_macro { 250 250 println!( 251 251 "[WARN] {:?}:{}; Token written as a function but no such function exists \"{}\"", 252 - file.file_input, 252 + context.file_for_index(file.tokens[file.working_index].origin_file).unwrap(), 253 253 file.tokens[file.working_index].line_number, 254 254 file.tokens[file.working_index].contents.trim() 255 255 );
+12 -2
src/projectparse.rs
··· 5 5 iter::{FilterMap, Map}, 6 6 os::unix::process, 7 7 path::{Path, PathBuf}, 8 + process::exit, 8 9 string, 9 10 }; 10 11 use toml::{ser, Table}; ··· 169 170 170 171 pub trait FileIndexing { 171 172 fn index_of_file(&mut self, f: &PathBuf) -> usize; 172 - fn file_for_index(&self, i: usize) -> Option<&PathBuf>; 173 + fn file_for_index(&self, i: usize) -> Option<PathBuf>; 174 + fn file_for_index_cannonical(&self, i: usize) -> Option<&PathBuf>; 173 175 } 174 176 175 177 impl FileIndexing for ProjectContext { ··· 186 188 return self.filemap.len() - 1; 187 189 } 188 190 189 - fn file_for_index(&self, i: usize) -> Option<&PathBuf> { 191 + fn file_for_index(&self, i: usize) -> Option<PathBuf> { 192 + if i >= self.filemap.len() { 193 + return None; 194 + } 195 + let path = self.filemap[i].strip_prefix(&self.input_folder.canonicalize().unwrap()); 196 + return Some(path.unwrap().to_path_buf()); 197 + } 198 + 199 + fn file_for_index_cannonical(&self, i: usize) -> Option<&PathBuf> { 190 200 if i >= self.filemap.len() { 191 201 return None; 192 202 }