···
-
args::ProgramArgs, project::FileGroup, reservednames::RESERVED_NAMES_MISC, types::Expand,
···
use stringtools::{collect_arguments, collect_block, split_to_tokens, trim_whitespace_tokens};
use types::{InputFile, Token};
···
project_path = project_folder.clone();
project_path.push("skidmark.toml");
-
println!("Operatting with {:?}", &project_path.as_os_str());
assert!(env::set_current_dir(&project_folder).is_ok());
let mut project = parse_project(&project_path);
···
println!("Proccesing {} files.", num);
for group in &mut project.filegroups {
for infile in &mut group.files {
-
process_file(infile, group.convert_html, &mut project.context);
-
fn process_file(file: &mut InputFile, convert_html: bool, context: &mut ProjectContext) {
//}, context: &mut ProjectContext) {
-
let contents = fs::read_to_string(&file.file_input).expect("File unreadable or missing");
//println!("{}\n {}", f.filename_out, contents);
//file.tokens = strings_to_tokens(split_keep_delimiters(contents), file.filename_input.clone());
-
file.tokens = split_to_tokens(contents, context.index_of_file(&file.file_input));
//let mut escaped = false;
-
while file.working_index < file.tokens.len() {
//look for macros or blocks
-
//println!(">\"{}\"<", file.tokens[file.working_index].contents);
-
if file.tokens[file.working_index].contents.len() == 0 {
-
file.working_index += 1;
-
if file.tokens[file.working_index].contents == "\\" {
-
file.tokens[file.working_index].contents = "".into();
-
file.working_index += 2;
//println!("Hit backslash");
let mut matched_macro: bool = false;
-
if file.tokens[file.working_index]
-
.starts_with(['!', '&'])
-
let mut symbol = file.tokens[file.working_index].contents.clone();
symbol = symbol.trim().to_string();
let mut ephemeral = false;
-
let same_file = file.tokens[file.working_index].origin_file
-
!= context.index_of_file(&file.file_input);
if symbol.starts_with("!&") {
···
//println!("Found a macro ({})", m.symbol);
-
let (args, args_tokcount) =
-
collect_arguments(&file.tokens[file.working_index..]);
let expansion: Vec<Token>;
let block_tokcount: usize;
//println!("is scoped.");
-
collect_block(&file.tokens[(file.working_index + args_tokcount)..]);
-
file.tokens[file.working_index].template_origin,
-
file.tokens[file.working_index].line_number,
&"Malformed Block".into(),
···
-
file.tokens[file.working_index].origin_file,
-
file.tokens[file.working_index].line_number,
···
-
file.tokens[file.working_index].origin_file,
-
file.tokens[file.working_index].line_number,
···
let trimmed = trim_whitespace_tokens(&expansion);
-
file.tokens.remove(file.working_index);
-
..(file.working_index + args_tokcount + block_tokcount - 1),
-
if expansion.len() == 0 && file.working_index > 0 {
-
file.working_index -= 1;
// todo maybe deduplicate this
-
for m in &mut file.templates {
-
if &symbol[prefix_len..] == m.symbol {
//println!("Found a macro ({})", m.symbol);
-
let (args, args_tokcount) =
-
collect_arguments(&file.tokens[file.working_index..]);
let expansion: Vec<Token>;
let block_tokcount: usize;
//println!("is scoped.");
-
collect_block(&file.tokens[(file.working_index + args_tokcount)..]);
-
file.tokens[file.working_index].template_origin,
-
file.tokens[file.working_index].line_number,
&"Malformed Block".into(),
···
-
file.tokens[file.working_index].origin_file,
-
file.tokens[file.working_index].line_number,
···
-
file.tokens[file.working_index].origin_file,
-
file.tokens[file.working_index].line_number,
···
let trimmed = trim_whitespace_tokens(&expansion);
-
file.tokens.remove(file.working_index);
-
..(file.working_index + args_tokcount + block_tokcount - 1),
-
if expansion.len() == 0 && file.working_index > 0 {
-
file.working_index -= 1;
-
let name = file.tokens[file.working_index]
let mut dont_error = name.len() <= 1;
-
if !dont_error && convert_html {
for reserved in RESERVED_NAMES_HTML {
if name[1..].starts_with(reserved) {
···
-
file.tokens[file.working_index].origin_file,
-
file.tokens[file.working_index].line_number,
"Token written as a function but no such function exists \"{}\"",
-
file.tokens[file.working_index].contents.trim()
-
file.working_index += 1;
-
//println!("{:?}", file.tokens);
let mut skid_output: String = "".to_string();
skid_output += &t.contents;
···
+
args::ProgramArgs, macros::template::SkidTemplate, project::FileGroup,
+
reservednames::RESERVED_NAMES_MISC, types::Expand,
···
use stringtools::{collect_arguments, collect_block, split_to_tokens, trim_whitespace_tokens};
use types::{InputFile, Token};
···
project_path = project_folder.clone();
project_path.push("skidmark.toml");
+
println!("Operatting on {:?}", &project_path.as_os_str());
assert!(env::set_current_dir(&project_folder).is_ok());
let mut project = parse_project(&project_path);
···
println!("Proccesing {} files.", num);
+
// for group in &mut project.filegroups {
+
// for infile in &mut group.files {
+
// process_skid(infile, group.convert_html, &mut project.context);
for group in &mut project.filegroups {
for infile in &mut group.files {
+
fs::read_to_string(&infile.file_input).expect("File unreadable or missing");
+
split_to_tokens(contents, project.context.index_of_file(&infile.file_input));
+
project.context.index_of_file(&infile.file_input),
+
tokens_in: &mut [Token],
+
context: &mut ProjectContext,
+
templates_base: Vec<SkidTemplate>,
//}, context: &mut ProjectContext) {
//println!("{}\n {}", f.filename_out, contents);
//file.tokens = strings_to_tokens(split_keep_delimiters(contents), file.filename_input.clone());
//let mut escaped = false;
+
let mut tokens = tokens_in.to_vec();
+
let mut templates = templates_base;
+
let mut working_index = 0;
+
while working_index < tokens.len() {
//look for macros or blocks
+
//println!(">\"{}\"<", tokens[working_index].contents);
+
if tokens[working_index].contents.len() == 0 {
+
if tokens[working_index].contents == "\\" {
+
tokens[working_index].contents = "".into();
//println!("Hit backslash");
let mut matched_macro: bool = false;
+
if tokens[working_index].contents.starts_with(['!', '&']) {
+
let mut symbol = tokens[working_index].contents.clone();
symbol = symbol.trim().to_string();
let mut ephemeral = false;
+
let same_file = tokens[working_index].origin_file != file_index;
if symbol.starts_with("!&") {
···
//println!("Found a macro ({})", m.symbol);
+
let (args, args_tokcount) = collect_arguments(&tokens[working_index..]);
let expansion: Vec<Token>;
let block_tokcount: usize;
//println!("is scoped.");
+
collect_block(&tokens[(working_index + args_tokcount)..]);
+
tokens[working_index].template_origin,
+
tokens[working_index].line_number,
&"Malformed Block".into(),
···
+
tokens[working_index].origin_file,
+
tokens[working_index].line_number,
···
+
tokens[working_index].origin_file,
+
tokens[working_index].line_number,
···
let trimmed = trim_whitespace_tokens(&expansion);
+
tokens.remove(working_index);
+
working_index..(working_index + args_tokcount + block_tokcount - 1),
+
if expansion.len() == 0 && working_index > 0 {
// todo maybe deduplicate this
+
if &symbol[prefix_len..] == t.symbol {
//println!("Found a macro ({})", m.symbol);
+
let (args, args_tokcount) = collect_arguments(&tokens[working_index..]);
let expansion: Vec<Token>;
let block_tokcount: usize;
//println!("is scoped.");
+
collect_block(&tokens[(working_index + args_tokcount)..]);
+
tokens[working_index].template_origin,
+
tokens[working_index].line_number,
&"Malformed Block".into(),
···
+
tokens[working_index].origin_file,
+
tokens[working_index].line_number,
···
+
tokens[working_index].origin_file,
+
tokens[working_index].line_number,
···
let trimmed = trim_whitespace_tokens(&expansion);
+
tokens.remove(working_index);
+
working_index..(working_index + args_tokcount + block_tokcount - 1),
+
if expansion.len() == 0 && working_index > 0 {
+
let name = tokens[working_index].contents.trim().to_lowercase();
let mut dont_error = name.len() <= 1;
for reserved in RESERVED_NAMES_HTML {
if name[1..].starts_with(reserved) {
···
+
tokens[working_index].origin_file,
+
tokens[working_index].line_number,
"Token written as a function but no such function exists \"{}\"",
+
tokens[working_index].contents.trim()
+
fn write_file(file: InputFile, convert_html: bool) {
+
//println!("{:?}", tokens);
let mut skid_output: String = "".to_string();
skid_output += &t.contents;