no_comment/
languages.rs

1use crate::without_comments::Comment;
2
3/// Macro to generate getter a function from a constant like `fn rust() -> Box[Comment]` from
4/// `const RUST: [Comment; 2]`. These getters are the only public interface of this module,
5/// used as no_comment::languages::rust(), etc.
6macro_rules! make_getter {
7    (const $c:ident: [Comment; $_:expr], pub fn $f:ident) => {
8        #[allow(dead_code)]
9        pub fn $f() -> Box<[Comment]> {
10            $c.iter().copied().collect::<Vec<_>>().into_boxed_slice()
11        }
12    };
13}
14
15make_getter!(const RUST: [Comment; 2], pub fn rust);
16make_getter!(const C: [Comment; 2], pub fn c);
17make_getter!(const PYTHON: [Comment; 3], pub fn python);
18make_getter!(const HASKELL: [Comment; 2], pub fn haskell);
19
20#[allow(dead_code)]
21const RUST: [Comment; 2] = [
22    Comment {
23        open_pat: "//",
24        close_pat: "\n",
25        nests: false,
26        keep_close_pat: true,
27        allow_close_pat: true,
28    },
29    Comment {
30        open_pat: "/*",
31        close_pat: "*/",
32        nests: true,
33        keep_close_pat: false,
34        allow_close_pat: false,
35    },
36];
37
38#[allow(dead_code)]
39const C: [Comment; 2] = [
40    Comment {
41        open_pat: "//",
42        close_pat: "\n",
43        nests: false,
44        keep_close_pat: true,
45        allow_close_pat: true,
46    },
47    Comment {
48        open_pat: "/*",
49        close_pat: "*/",
50        nests: false,
51        keep_close_pat: false,
52        allow_close_pat: false,
53    },
54];
55
56#[allow(dead_code)]
57const PYTHON: [Comment; 3] = [
58    Comment {
59        open_pat: "#",
60        close_pat: "\n",
61        nests: false,
62        keep_close_pat: true,
63        allow_close_pat: true,
64    },
65    // allow_close_pat won't be checked because open_pat will match first
66    Comment {
67        open_pat: "'''",
68        close_pat: "'''",
69        nests: false,
70        keep_close_pat: false,
71        allow_close_pat: false,
72    },
73    Comment {
74        open_pat: "\"\"\"",
75        close_pat: "\"\"\"",
76        nests: false,
77        keep_close_pat: false,
78        allow_close_pat: false,
79    },
80];
81
82#[allow(dead_code)]
83const HASKELL: [Comment; 2] = [
84    Comment {
85        open_pat: "--",
86        close_pat: "\n",
87        nests: false,
88        keep_close_pat: true,
89        allow_close_pat: true,
90    },
91    Comment {
92        open_pat: "{-",
93        close_pat: "-}",
94        nests: true,
95        keep_close_pat: false,
96        allow_close_pat: false,
97    },
98];