Tholp's bespoke website generator

Inverse ephermerality

Tholp1 5bb7ef44 2d1a770b

+37 -28
+37 -28
src/main.rs
··· 50 50 .starts_with(['!', '&']) 51 51 { 52 52 let mut matched: bool = false; 53 + let mut prefix_len = 1; 54 + let mut symbol = file.tokens[file.working_index].contents.clone(); 55 + symbol = symbol.trim().to_string(); 53 56 54 - for m in &MACRO_LIST { 55 - let symbol = file.tokens[file.working_index].contents.trim(); 56 - if symbol.len() < 2 57 + if symbol.len() > 2 { 58 + let mut ephemeral = false; 59 + let same_file = file.tokens[file.working_index].origin_file != file.filename_input; 60 + 61 + //if file.tokens[file.working_index].contents.starts_with("!&") 62 + if symbol.starts_with("!&") 63 + { 64 + prefix_len = 2; 65 + ephemeral = !same_file; 66 + } 67 + //else if file.tokens[file.working_index].contents.starts_with("&") 68 + else if symbol.starts_with("&") 57 69 { 58 - continue; 70 + ephemeral = same_file; 59 71 } 60 - if &symbol[1..] == m.symbol { 61 - matched = true; 62 - println!("Found a macro ({})", m.symbol); 63 - let mut ephemeral = false; 64 - if file.tokens[file.working_index].contents.starts_with('&') 65 - && file.tokens[file.working_index].origin_file != file.filename_input 66 - { 67 - println!("Skipping Ephermal macro from included file."); 68 - ephemeral = true; 69 - } 72 + 73 + // Check if its a macro 74 + for m in &MACRO_LIST { 75 + if &symbol[prefix_len..] == m.symbol { 76 + matched = true; 77 + println!("Found a macro ({})", m.symbol); 70 78 71 - let (args, tokcount) = collect_arguments(&file.tokens[file.working_index..]); 72 - let expansion: Vec<Token>; 73 - if ephemeral { 74 - expansion = Vec::new(); 75 - } else { 76 - expansion = (m.expand)(file, &args); 79 + let (args, tokcount) = 80 + collect_arguments(&file.tokens[file.working_index..]); 81 + let expansion: Vec<Token>; 82 + if ephemeral { 83 + expansion = Vec::new(); 84 + } else { 85 + expansion = (m.expand)(file, &args); 86 + } 87 + file.tokens.remove(file.working_index); 88 + file.tokens.splice( 89 + file.working_index..(file.working_index + tokcount - 1), 90 + expansion, 91 + ); 77 92 } 78 - file.tokens.remove(file.working_index); 79 - file.tokens.splice( 80 - file.working_index..(file.working_index + tokcount - 1), 81 - expansion, 82 - ); 83 93 } 94 + // Check if its a block 95 + // for b in &BLOCK_LIST {}} 84 96 } 85 - 86 - // for b in &BLOCK_LIST {} 87 - 88 97 if !matched { 89 98 println!( 90 99 "Token written as a function but no such function exists \"{}\"",