added comment and newline cleaning
This commit is contained in:
parent
1ef1ef6c89
commit
662005b2f0
5 changed files with 98 additions and 10 deletions
|
@ -10,7 +10,7 @@ fn main() {
|
|||
println!("{:?}", preprocessor::preprocess(file));
|
||||
}
|
||||
|
||||
fn parse_and_interpret(code: String) {
|
||||
//fn parse_and_interpret(code: String) {
|
||||
|
||||
}
|
||||
//}
|
||||
|
||||
|
|
|
@ -1,5 +1,28 @@
|
|||
pub fn preprocess(raw_code: String) -> String {
|
||||
let lines = raw_code.split(' ');
|
||||
for &line in lines {
|
||||
use lazy_static::lazy_static;
|
||||
use fancy_regex::Regex;
|
||||
|
||||
pub fn preprocess(raw_code: String) {
|
||||
lazy_static! {
|
||||
static ref COMMENT_RE: Regex = Regex::new(r"(\]\].*?\[\[|&&.*\n|``(.|\n)*?´´)").unwrap();
|
||||
}
|
||||
|
||||
let code = COMMENT_RE.replace_all(&raw_code, "");
|
||||
let code = remove_empty_lines(code.to_string());
|
||||
println!("{}", &code)
|
||||
}
|
||||
|
||||
pub fn remove_empty_lines(text: String) -> String {
|
||||
let text: Vec<&str> = text.split('\n').collect();
|
||||
|
||||
let mut out = String::new();
|
||||
for line in text {
|
||||
if !line.trim().is_empty() {
|
||||
out += line;
|
||||
out.push('\n');
|
||||
}
|
||||
}
|
||||
|
||||
out
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue