rpg_compiler/tokenizer/
rm_comments.rs

1use regex::Regex;
2
3pub fn rm_comments(code: &str) -> String {
4    let lines = code.lines();
5    let comment_regex = Regex::new("#").unwrap();
6    let uncommented = lines.into_iter().map(|line| {
7        let mut l = line;
8        if let Some(index) = comment_regex.find(line) {
9            l = &l[0..index.start()];
10        }
11        l.to_string()
12    }).collect::<Vec<String>>().join("\n");
13    uncommented
14}