melody_compiler 0.20.0

The Melody language compiler
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
pub fn format(source: &str) -> String {
    format_line_comments(source)
}

fn format_line_comments(source: &str) -> String {
    source
        .lines()
        .map(|line| {
            if line.trim_start().starts_with("//") {
                let comment = line.trim_start().trim_start_matches("//");
                format!("/*{comment}*/")
            } else {
                line.to_owned()
            }
        })
        .collect::<Vec<String>>()
        .join("\n")
}