Tholp's bespoke website generator

add !reminder

Tholp1 f9e204bd add4c42d

+22 -5
src/console.rs
···
use crate::projectparse::{FileIndexing, ProjectContext};
-
pub fn error_generic(msg: String) {
+
pub fn error_generic(msg: &String) {
println!("{} {}", "[ERROR]".red(), msg);
exit(1);
}
-
pub fn error_skid(context: &ProjectContext, origin_index: usize, origin_line: usize, msg: String) {
+
pub fn error_skid(context: &ProjectContext, origin_index: usize, origin_line: usize, msg: &String) {
println!(
"{} {:?}:{}; {}",
"[ERROR]".red(),
···
exit(1);
}
-
pub fn warn_generic(msg: String) {
+
pub fn warn_generic(msg: &String) {
println!("{} {}", "[WARN]".yellow(), msg);
}
-
pub fn warn_skid(context: &ProjectContext, origin_index: usize, origin_line: usize, msg: String) {
+
pub fn warn_skid(context: &ProjectContext, origin_index: usize, origin_line: usize, msg: &String) {
println!(
"{} {:?}:{}; {}",
"[WARN]".yellow(),
···
);
}
-
pub fn ok_generic(msg: String) {
+
pub fn ok_generic(msg: &String) {
println!("{} {}", "[OK]".green(), msg);
}
+
+
pub fn reminder_skid(
+
context: &ProjectContext,
+
origin_index: usize,
+
origin_line: usize,
+
msg: &String,
+
) {
+
println!(
+
"{} {:?}:{}; {}",
+
"[REMINDER]".cyan(),
+
context
+
.file_for_index(origin_index)
+
.expect("Panic in the warn func.... (file_for_index() was None!)"),
+
origin_line,
+
msg
+
);
+
}
+1 -13
src/macros/insert.rs
···
.file_for_index_canonical(origin_index)
.expect("Macro 'Insert' was given a bad origin index")
.clone();
-
if args.len() != 1 {
-
error_skid(
-
context,
-
origin_index,
-
origin_line,
-
format!(
-
"Insert only accepts 1 argument, got given {} ({:?})",
-
args.len(),
-
args
-
),
-
);
-
}
let mut arg = args[0].clone();
let mut search_from_root = arg.starts_with("//");
···
}
if !ok {
-
error_skid(context, origin_index, origin_line, format!("Insert was unable to find the file \"{}\" relative to its origin or in project root.", arg));
+
error_skid(context, origin_index, origin_line, &format!("Insert was unable to find the file \"{}\" relative to its origin or in project root.", arg));
}
let mut output = fs::read_to_string(&include_file).expect("File unreadable or missing");
+9
src/macros/mod.rs
···
pub mod simple_blocks;
pub mod simple_macros;
pub mod template;
+
use crate::macros::simple_macros::macro_reminder;
+
use super::types::Macro;
use insert::macro_insert;
···
has_scope: false,
min_args: 0,
max_args: 0,
+
},
+
Macro {
+
symbol: "reminder",
+
expansion: macro_reminder,
+
has_scope: false,
+
min_args: 1,
+
max_args: 1,
},
// Scoped
Macro {
+2 -2
src/macros/simple_blocks.rs
···
context,
origin_index,
origin_line,
-
format!(
+
&format!(
"Macro `for_each_arg` given block with no \"[[{}..1]]\", intentional?",
varname
),
···
if real_args.len() % replacement_count != 0 {
error_skid(context, origin_index, origin_line,
-
format!("`for_each_var` was not given a number of arguments({}) that was a multiple of its replacement posistions({}) (got {:?})",
+
&format!("`for_each_var` was not given a number of arguments({}) that was a multiple of its replacement posistions({}) (got {:?})",
real_args.len(),
replacement_count,
real_args));
+14 -2
src/macros/simple_macros.rs
···
use chrono::Local;
use crate::{
-
console::error_skid,
+
console::{error_skid, reminder_skid},
projectparse::{FileIndexing, ProjectContext},
stringtools::split_to_tokens,
types::{InputFile, Token},
···
context,
origin_index,
origin_line,
-
format!(
+
&format!(
"Time only accepts 1 argument, got given {} ({:?})",
args.len(),
args
···
origin_index,
);
}
+
+
pub fn macro_reminder(
+
_file: &mut InputFile,
+
origin_index: usize,
+
origin_line: usize,
+
context: &mut ProjectContext,
+
args: &Vec<String>,
+
_scope: &[Token],
+
) -> Vec<Token> {
+
reminder_skid(context, origin_index, origin_line, &args[0]);
+
Vec::new()
+
}
+7 -7
src/macros/template.rs
···
context,
origin_index,
origin_line,
-
format!(
+
&format!(
"Template \"{}\" requires exactly {} arguments, got given {} ({:?})",
self.symbol,
self.args.len(),
···
context,
origin_index,
origin_line,
-
format!(
+
&format!(
"Template \"{}\" requires at least {} arguments, got given {} ({:?})",
self.symbol,
self.args.len(),
···
context,
origin_index,
origin_line,
-
format!("Attempted template redefinition of \"{}\"", args[0]),
+
&format!("Attempted template redefinition of \"{}\"", args[0]),
);
}
}
···
context,
origin_index,
origin_line,
-
format!(
+
&format!(
"Attempted to make a template using a reserved name \"{}\"",
args[0]
),
···
context,
origin_index,
origin_line,
-
format!(
+
&format!(
"Attempted to make a template using a reserved parameter name \"{}\"",
arg
),
···
context,
origin_index,
origin_line,
-
format!(
+
&format!(
"Attempted to make a template with a parameter that contains whitespace \"{}\"",
param
),
···
context,
origin_index,
origin_line,
-
format!(
+
&format!(
"Template definition of \"{}\" has {} paramters but only uses {}",
args[0],
args.len() - 1,
+10 -16
src/main.rs
···
let ok = project_folder.pop();
if !ok {
error_generic(
-
"No skidmark.toml project file found in this folder or ancestors.".into(),
+
&"No skidmark.toml project file found in this folder or ancestors.".into(),
);
}
project_path = project_folder.clone();
···
context,
file.tokens[file.working_index].template_origin,
file.tokens[file.working_index].line_number,
-
"Malformed Block".into(),
+
&"Malformed Block".into(),
);
}
let block: Vec<Token>;
···
context,
file.tokens[file.working_index].template_origin,
file.tokens[file.working_index].line_number,
-
"Malformed Block".into(),
+
&"Malformed Block".into(),
);
}
···
context,
file.tokens[file.working_index].origin_file,
file.tokens[file.working_index].line_number,
-
format!(
+
&format!(
"Token written as a function but no such function exists \"{}\"",
file.tokens[file.working_index].contents.trim()
),
···
)
.unwrap();
fs::write(&file.file_out, &html_output).expect("Couldn't write output to file");
-
ok_generic(format!(
-
"\"{}\" written \n\n",
-
file.file_out
-
.to_str()
-
.unwrap_or("Couldnt Unwrap file_out name")
-
));
} else {
fs::write(&file.file_out, &skid_output).expect("Couldn't write output to file");
-
ok_generic(format!(
-
"\"{}\" written \n\n",
-
file.file_out
-
.to_str()
-
.unwrap_or("Couldnt Unwrap file_out name")
-
));
}
+
ok_generic(&format!(
+
"\"{}\" written \n\n",
+
file.file_out
+
.to_str()
+
.unwrap_or("Couldnt Unwrap file_out name")
+
));
}
+1 -1
src/types.rs
···
scope: &[Token],
) -> Vec<Token> {
if (args.len() > self.max_args) || (args.len() < self.min_args) {
-
error_skid(context, origin_index, origin_line, format!("Macro \'{}\' was given a number of arguments ({}) not in its acceptable range ({}-{})",
+
error_skid(context, origin_index, origin_line, &format!("Macro \'{}\' was given a number of arguments ({}) not in its acceptable range ({}-{})",
self.symbol, args.len(), self.min_args, if self.max_args == usize::max_value() {"No Limit".to_string()} else {format!("{}", self.max_args)}));
Vec::new()
} else {