Tholp's bespoke website generator

add !filename and !filename_cannonical, ProjectContext::file_for_index_cannonical

Tholp1 34f76f44 f01552d0

+2 -2
src/macros/insert.rs
···
_scope: &[Token],
) -> Vec<Token> {
let origin_file = context
-
.file_for_index(origin_index)
+
.file_for_index_cannonical(origin_index)
.expect("Macro 'Insert' was given a bad origin index")
.clone();
if args.len() != 1 {
···
}
if !ok {
-
println!("[ERROR] \"{:?}\": Insert was unable to find the file \"{}\" relative to its origin or in project root.", origin_file.to_str(), arg);
+
println!("[ERROR] {:?}: Insert was unable to find the file \"{}\" relative to its origin or in project root.", origin_file.to_str().unwrap(), arg);
exit(1);
}
+11 -1
src/macros/mod.rs
···
use insert::macro_insert;
use simple_blocks::{macro_comment, macro_repeat, macro_section, macro_skip};
-
use simple_macros::{macro_clear, macro_time};
+
use simple_macros::{macro_clear, macro_filename, macro_filename_cannonical, macro_time};
use template::macro_template;
pub static MACRO_LIST: &'static [Macro<'_>] = &[
···
Macro {
symbol: "time",
expand: macro_time,
+
has_scope: false,
+
},
+
Macro {
+
symbol: "filename",
+
expand: macro_filename,
+
has_scope: false,
+
},
+
Macro {
+
symbol: "filename_cannonical",
+
expand: macro_filename_cannonical,
has_scope: false,
},
// Scoped
+39
src/macros/simple_macros.rs
···
+
// This file for implementations of short macros, im qualifying that as less than 30ish lines
use std::process::exit;
use chrono::{DateTime, Local};
···
return split_to_tokens(t.format(&args[0]).to_string(), origin_index);
}
+
+
pub fn macro_filename(
+
_file: &mut InputFile,
+
origin_index: usize,
+
_origin_line: usize,
+
context: &mut ProjectContext,
+
_args: &Vec<String>,
+
_scope: &[Token],
+
) -> Vec<Token> {
+
return split_to_tokens(
+
context
+
.file_for_index(origin_index)
+
.unwrap()
+
.to_str()
+
.unwrap()
+
.into(),
+
origin_index,
+
);
+
}
+
+
pub fn macro_filename_cannonical(
+
_file: &mut InputFile,
+
origin_index: usize,
+
_origin_line: usize,
+
context: &mut ProjectContext,
+
_args: &Vec<String>,
+
_scope: &[Token],
+
) -> Vec<Token> {
+
return split_to_tokens(
+
context
+
.file_for_index_cannonical(origin_index)
+
.unwrap()
+
.to_str()
+
.unwrap()
+
.into(),
+
origin_index,
+
);
+
}
+1 -1
src/main.rs
···
if !matched_macro {
println!(
"[WARN] {:?}:{}; Token written as a function but no such function exists \"{}\"",
-
file.file_input,
+
context.file_for_index(file.tokens[file.working_index].origin_file).unwrap(),
file.tokens[file.working_index].line_number,
file.tokens[file.working_index].contents.trim()
);
+12 -2
src/projectparse.rs
···
iter::{FilterMap, Map},
os::unix::process,
path::{Path, PathBuf},
+
process::exit,
string,
};
use toml::{ser, Table};
···
pub trait FileIndexing {
fn index_of_file(&mut self, f: &PathBuf) -> usize;
-
fn file_for_index(&self, i: usize) -> Option<&PathBuf>;
+
fn file_for_index(&self, i: usize) -> Option<PathBuf>;
+
fn file_for_index_cannonical(&self, i: usize) -> Option<&PathBuf>;
}
impl FileIndexing for ProjectContext {
···
return self.filemap.len() - 1;
}
-
fn file_for_index(&self, i: usize) -> Option<&PathBuf> {
+
fn file_for_index(&self, i: usize) -> Option<PathBuf> {
+
if i >= self.filemap.len() {
+
return None;
+
}
+
let path = self.filemap[i].strip_prefix(&self.input_folder.canonicalize().unwrap());
+
return Some(path.unwrap().to_path_buf());
+
}
+
+
fn file_for_index_cannonical(&self, i: usize) -> Option<&PathBuf> {
if i >= self.filemap.len() {
return None;
}