···
-
closures::CLOSURE_LIST,
-
macros::template::SkidTemplate,
reservednames::RESERVED_NAMES_MISC,
-
types::{Expand, SkidContext},
use markdown::{CompileOptions, Constructs, Options, ParseOptions};
···
-
use stringtools::{collect_arguments, collect_block, split_to_tokens, trim_whitespace_tokens};
use types::{InputFile, Token};
// really need to change this whole thing to work with characters rather than
···
' ', '\n', '\t', '(', ')', '{', '}', '[', ']', '<', '>', '\\', '\'', '\"', ';', '?', '^', '-',
// let args = ProgramArgs::parse();
···
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));
-
let mut skid_context = SkidContext::new();
-
project.context.index_of_file(&infile.file_input),
-
tokens_in: &mut [Token],
-
context: &mut ProjectContext,
skid_context: &mut SkidContext,
-
//}, 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 starting_template_count = skid_context.templates.len();
-
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 prefix_len = 1;
-
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("!&") {
-
ephemeral = !same_file;
-
else if symbol.starts_with("&") {
-
// Check if its a macro
-
if &symbol[prefix_len..] == m.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)..]);
-
if block_opt.is_none() {
-
tokens[working_index].template_origin,
-
tokens[working_index].line_number,
-
&"Malformed Block".into(),
-
(block, block_tokcount) = block_opt.unwrap();
-
expansion = Vec::new();
-
tokens[working_index].origin_file,
-
tokens[working_index].line_number,
-
expansion = Vec::new();
-
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),
-
trimmed.iter().cloned(),
-
if expansion.len() == 0 && working_index > 0 {
-
// todo maybe deduplicate this
-
for t in &skid_context.templates {
-
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)..]);
-
if block_opt.is_none() {
-
tokens[working_index].template_origin,
-
tokens[working_index].line_number,
-
&"Malformed Block".into(),
-
(block, block_tokcount) = block_opt.unwrap();
-
expansion = Vec::new();
-
tokens[working_index].origin_file,
-
tokens[working_index].line_number,
-
expansion = Vec::new();
-
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),
-
trimmed.iter().cloned(),
-
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) {
-
for reserved in RESERVED_NAMES_MISC {
-
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()
···
skid_context.templates.truncate(starting_template_count);
-
fn write_file(file: InputFile, convert_html: bool) {
//println!("{:?}", tokens);
let mut skid_output: String = "".to_string();
-
for t in &file.tokens {
-
skid_output += &t.contents;
let mut folder = file.file_skidout.clone();
···
reservednames::RESERVED_NAMES_MISC,
+
stringtools::TokenTools,
+
types::{IsScoped, MacroExpand, SkidContext},
use markdown::{CompileOptions, Constructs, Options, ParseOptions};
···
+
use stringtools::{collect_arguments, collect_block, split_to_tokens};
use types::{InputFile, Token};
// really need to change this whole thing to work with characters rather than
···
' ', '\n', '\t', '(', ')', '{', '}', '[', ']', '<', '>', '\\', '\'', '\"', ';', '?', '^', '-',
// let args = ProgramArgs::parse();
···
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));
+
SkidContext::new(project.context.index_of_file(&infile.file_input));
+
&process_skid(&tokens, &mut project.context, &mut skid_context),
+
proj_context: &mut ProjectContext,
skid_context: &mut SkidContext,
+
) -> Option<(Vec<Token>, usize)> {
+
// (Output, to be consumed size)
+
// At this point we think its a macro (starts with ! or &) so check which, we have the rest of the file
+
let ephemeral_type: EphemeralType;
+
if tokens_in.len() < 2 {
+
if tokens_in[0] == '!' && tokens_in[1] == '&' {
+
ephemeral_type = EphemeralType::InverseEphemeral;
+
} else if tokens_in[0] == '!' {
+
ephemeral_type = EphemeralType::Normal;
+
} else if tokens_in[0] == '&' {
+
ephemeral_type = EphemeralType::Ephemeral;
+
let mut chars_consumed = if ephemeral_type == EphemeralType::InverseEphemeral {
+
let mut symbol: String = "".into();
+
for tok in &tokens_in[chars_consumed..] {
+
if tok.contents.is_whitespace() || DELIMITERS.contains(&tok.contents) {
+
symbol.push(tok.contents);
+
let mut expander: &dyn IsScoped = &MACRO_LIST[0]; // assinging because it complains about possibly being empty later even if not the case
+
// Check if its a macro
+
if m.symbol == symbol {
+
// Not a macro check templates
+
for t in &skid_context.templates {
+
if t.symbol == symbol {
+
// Not a template either, see if its reserved or not to see if we should say something
+
let name = symbol.to_lowercase();
+
let mut dont_error = false;
+
for reserved in RESERVED_NAMES_HTML {
+
if name.starts_with(reserved) {
+
for reserved in RESERVED_NAMES_MISC {
+
if name.starts_with(reserved) {
+
tokens_in[0].origin_index,
+
tokens_in[0].origin_line,
+
&format!("No such macro or defined template \"{symbol}\""),
+
let args_result = collect_arguments(&tokens_in[chars_consumed..]);
+
if args_result.is_none() {
+
tokens_in[0].origin_index,
+
tokens_in[0].origin_line,
+
&format!("Didnt find any arguments for macro \"{symbol}\"."),
+
(args, consumed_by_args) = args_result.unwrap();
+
chars_consumed += consumed_by_args;
+
if expander.is_scoped() {
+
let block_result = collect_block(&tokens_in[chars_consumed..]);
+
if block_result.is_none() {
+
tokens_in[0].origin_index,
+
tokens_in[0].origin_line,
+
&format!("Didnt find a block for macro \"{symbol}\"."),
+
(block, consumed_by_block) = block_result.unwrap();
+
chars_consumed += consumed_by_block;
+
let return_empty: bool;
+
EphemeralType::Normal => return_empty = false,
+
EphemeralType::Ephemeral => {
+
return_empty = skid_context.file_index != tokens_in[0].origin_index
+
EphemeralType::InverseEphemeral => {
+
return_empty = skid_context.file_index == tokens_in[0].origin_index
+
return Some((Vec::new(), chars_consumed));
+
// we have to find it again because of borrower
+
if m.symbol == symbol {
+
tokens_in[0].origin_index,
+
tokens_in[0].origin_line,
+
while i < skid_context.templates.len() {
+
if skid_context.templates[i].symbol == symbol {
+
skid_context.templates[i]
+
tokens_in[0].origin_index,
+
tokens_in[0].origin_line,
+
proj_context: &mut ProjectContext,
+
skid_context: &mut SkidContext,
+
//}, 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 starting_template_count = skid_context.templates.len();
+
let mut escaped = false;
+
let mut working_index = 0;
+
while working_index < tokens.len() {
+
if tokens[working_index] == '\\' && !escaped {
+
tokens[working_index].contents = '\0'; // skip over this later when outputting to avoid shifting memory rn
+
// bit of a hack for reverse ephemeral escaping behavior to be the same as previously
+
if tokens.len() > working_index + 1
+
&& tokens[working_index] == '!'
+
&& tokens[working_index + 1] == '&'
+
if (tokens[working_index] == '!' || tokens[working_index] == '&') && !escaped {
+
find_and_run_macro(&tokens[working_index..], proj_context, skid_context);
+
if expansion.is_some() {
+
working_index..working_index + expansion.as_ref().unwrap().1,
···
skid_context.templates.truncate(starting_template_count);
+
tokens.retain(|t| t.contents != '\0');
+
fn write_file(file: &InputFile, convert_html: bool, tokens: &[Token]) {
//println!("{:?}", tokens);
let mut skid_output: String = "".to_string();
+
skid_output.push(t.contents);
let mut folder = file.file_skidout.clone();