comment-parser
This crate implements a (pull) parser for extracting comments from code in various programming languages.
Usage
Add this to your Cargo.toml
:
[]
= "0.1"
Extract Comments from Rust Code
use CommentParser;
let rust = r#"
/* This is
the main
function */
fn main() {
// println! is a macro
println!("Hello World"); // Prints "Hello World"
}
"#;
let rules = get_syntax.unwrap;
let parser = new;
for comment in parser
This will output the following:
BlockComment(_, " This is\nthe main\nfunction ")
LineComment(_, " println! is a macro")
LineComment(_, " Prints \"Hello World\"")
Extract Comments from Python Code
use CommentParser;
let python = r#"
# In Python main is not a function
if __name__ == "__main__":
# print is a function
print("Hello World") # Prints "Hello World"
"#;
let rules = get_syntax.unwrap;
let parser = new;
for comment in parser
This will output the following:
LineComment(_, " In Python main is not a function")
LineComment(_, " print is a function")
LineComment(_, " Prints \"Hello World\"")