Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vallentin/comment-parser
This crate implements a (pull) parser for extracting comments from code in various programming languages.
https://github.com/vallentin/comment-parser
extract-comments parser rust rust-crate rust-library
Last synced: 9 days ago
JSON representation
This crate implements a (pull) parser for extracting comments from code in various programming languages.
- Host: GitHub
- URL: https://github.com/vallentin/comment-parser
- Owner: vallentin
- License: mit
- Created: 2020-02-13T16:16:13.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-01-14T17:26:20.000Z (10 months ago)
- Last Synced: 2024-10-14T14:11:14.539Z (23 days ago)
- Topics: extract-comments, parser, rust, rust-crate, rust-library
- Language: Rust
- Homepage:
- Size: 17.6 KB
- Stars: 9
- Watchers: 3
- Forks: 3
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# comment-parser
[![Build Status](https://github.com/vallentin/comment-parser/workflows/Rust/badge.svg)](https://github.com/vallentin/comment-parser/actions?query=workflow%3ARust)
[![Build Status](https://travis-ci.org/vallentin/comment-parser.svg?branch=master)](https://travis-ci.org/vallentin/comment-parser)
[![Latest Version](https://img.shields.io/crates/v/comment-parser.svg)](https://crates.io/crates/comment-parser)
[![Docs](https://docs.rs/comment-parser/badge.svg)](https://docs.rs/comment-parser)
[![License](https://img.shields.io/github/license/vallentin/comment-parser.svg)](https://github.com/vallentin/comment-parser)This crate implements a (pull) parser for extracting comments
from code in various programming languages.## Usage
Add this to your `Cargo.toml`:
```toml
[dependencies]
comment-parser = "0.1"
```## Extract Comments from Rust Code
```rust
use comment_parser::CommentParser;let rust = r#"
/* This is
the main
function */
fn main() {
// println! is a macro
println!("Hello World"); // Prints "Hello World"
}
"#;let rules = comment_parser::get_syntax("rust").unwrap();
let parser = CommentParser::new(rust, rules);
for comment in parser {
println!("{:?}", comment);
}
```This will output the following:
```text
BlockComment(_, " This is\nthe main\nfunction ")
LineComment(_, " println! is a macro")
LineComment(_, " Prints \"Hello World\"")
```## Extract Comments from Python Code
```rust
use comment_parser::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 = comment_parser::get_syntax("python").unwrap();
let parser = CommentParser::new(python, rules);
for comment in parser {
println!("{:?}", comment);
}
```This will output the following:
```text
LineComment(_, " In Python main is not a function")
LineComment(_, " print is a function")
LineComment(_, " Prints \"Hello World\"")
```