···
// This file for implementations of short blocks, im qualifying that as less than 30ish lines
3
-
use std::{env::args, fmt::format, process::exit};
7
-
projectparse::{FileIndexing, ProjectContext},
8
-
stringtools::{find_pattern, split_to_tokens, TokenTools, WhitespaceChecks},
4
+
console::{error_skid, warn_skid},
5
+
projectparse::ProjectContext,
6
+
stringtools::{find_pattern, split_to_tokens, TokenTools},
types::{InputFile, Token},
···
let mut output = Vec::new();
let block: Vec<Token> = scope.into();
68
+
let varname = &args[0];
69
+
let real_args = &args[1..];
let mut replacement_count: usize = 0;
73
-
let mut replacement_pattern = find_pattern(scope, "[[..1]]".into());
73
+
let mut replacement_pattern = find_pattern(scope, format!("[[{}..1]]", varname));
75
+
if replacement_pattern.is_none() {
81
+
"Macro `for_each_arg` given block with no \"[[{}..1]]\", intentional?",
while replacement_pattern.is_some() {
77
-
find_pattern(scope, format!("[[..{}]]", replacement_count + 1).into());
90
+
find_pattern(scope, format!("[[{}..{}]]", varname, replacement_count + 1));
if replacement_count == 0 {
81
-
for _i in 0..args.iter().count() {
94
+
for _i in 0..real_args.iter().count() {
output.append(&mut block.clone());
87
-
if args.len() % replacement_count != 0 {
100
+
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 {:?})",
let mut replacement_index: usize = 0;
let mut arg_output: Vec<Token> = block.clone();
98
-
let mut found_pattern =
99
-
find_pattern(&arg_output, format!("[[..{}]]", replacement_index + 1));
110
+
for arg in real_args {
111
+
let mut found_pattern = find_pattern(
113
+
format!("[[{}..{}]]", varname, replacement_index + 1),
while found_pattern.is_some() {
let (start, len) = found_pattern.unwrap();
let replacement = split_to_tokens(arg.clone(), origin_index);
arg_output.splice(start..start + len, replacement);
105
-
found_pattern = find_pattern(&arg_output, format!("[[..{}]]", replacement_index + 1));
120
+
found_pattern = find_pattern(
122
+
format!("[[{}..{}]]", varname, replacement_index + 1),
//println!("{}", replacement_index + 1);