Tholp's bespoke website generator
1use std::path::PathBuf; 2 3use crate::{macros::template::SkidTemplate, projectparse::ProjectContext}; 4 5pub struct Token { 6 pub contents: String, 7 pub origin_file: usize, 8 pub line_number: usize, 9} 10 11pub struct InputFile { 12 pub file_input: PathBuf, 13 pub file_skidout: PathBuf, 14 pub file_htmlout: PathBuf, 15 pub tokens: Vec<Token>, 16 pub working_index: usize, 17 pub templates: Vec<SkidTemplate>, 18} 19 20type MacroExpansion = 21 fn(&mut InputFile, usize, usize, &mut ProjectContext, &Vec<String>, &[Token]) -> Vec<Token>; 22// ( 23// _file: &mut InputFile, 24// origin_index: usize, 25// origin_line: usize, 26// context: &mut ProjectContext, 27// args: &Vec<String>, 28// _scope: &[Token], 29// ) -> Vec<Token> 30 31pub struct Macro<'a> { 32 pub symbol: &'a str, 33 pub expand: MacroExpansion, 34 pub has_scope: bool, //takes blocks of text input as well as parameters using {{...}} 35} 36 37impl InputFile { 38 pub fn new() -> InputFile { 39 InputFile { 40 file_input: "".into(), 41 file_skidout: "".into(), 42 file_htmlout: "".into(), 43 tokens: Vec::new(), 44 working_index: 0, 45 templates: Vec::new(), 46 } 47 } 48} 49 50impl Token { 51 pub fn new(contents: String, origin_file: usize, line_number: usize) -> Token { 52 Token { 53 contents: contents, 54 origin_file: origin_file, 55 line_number: line_number, 56 } 57 } 58} 59 60impl ToString for Token { 61 fn to_string(&self) -> String { 62 return self.contents.clone(); 63 } 64} 65 66impl Clone for Token { 67 fn clone(&self) -> Self { 68 return Token::new( 69 self.contents.clone(), 70 self.origin_file.clone(), 71 self.line_number, 72 ); 73 } 74}