1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//! This crate implements a (pull) parser for extracting comments
//! from code in various programming languages.
//!
//! # Extract Comments from Rust Code
//!
//! ```no_run
//! 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
//!
//! ```no_run
//! 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\"")
//! ```

#![forbid(unsafe_code)]
#![deny(missing_docs)]
// #![deny(missing_doc_code_examples)]
#![deny(missing_debug_implementations)]
#![warn(clippy::all)]

mod languages;
mod parse;
mod syntax;

pub use languages::{get_syntax, get_syntax_from_extension, get_syntax_from_path, LanguageError};
pub use parse::{CommentParser, Event};
pub use syntax::SyntaxRule;