use string_parser::string_parser_with_file; use colored::Colorize; pub struct Parser{ keyword: String, end_filter: Box) -> bool>, callback: Box, } impl Parser { pub fn new(keyword: String, end_filter: Box) -> bool>) -> Parser { let callback = Box::from(|text: String, line: usize, file: &str| { // let path = Path::new(file).strip_prefix(env::current_dir().unwrap().to_str().unwrap()).unwrap(); println!("{} {} {} {} : {}", file, "TODO".green() ,"Line ".green(), line.to_string().green(), text.blue()); }); Parser{ keyword, end_filter, callback } } pub fn new_callback(keyword: String, end_filter: Box) -> bool>, callback: Box) -> Parser { Parser { keyword, end_filter, callback } } fn get_keyword(&self) -> String { self.keyword.clone() } fn get_end_filter(&self) -> &dyn Fn(Vec) -> bool { &self.end_filter } fn get_callback(&self) -> &dyn Fn(String, usize, &str) { &self.callback } pub fn parse(&self, path: &str) { string_parser_with_file(path, &self.get_keyword(), self.get_end_filter(), self.get_callback()).expect("failed to open file"); } }