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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
use crate::without_comments::Comment;

/// Macro to generate getter a function from a constant like `fn rust() -> Box[Comment]` from
/// `const RUST: [Comment; 2]`. These getters are the only public interface of this module,
/// used as no_comment::languages::rust(), etc.
macro_rules! make_getter {
    (const $c:ident: [Comment; $_:expr], pub fn $f:ident) => {
        #[allow(dead_code)]
        pub fn $f() -> Box<[Comment]> {
            $c.iter().copied().collect::<Vec<_>>().into_boxed_slice()
        }
    };
}

make_getter!(const RUST: [Comment; 2], pub fn rust);
make_getter!(const C: [Comment; 2], pub fn c);
make_getter!(const PYTHON: [Comment; 3], pub fn python);
make_getter!(const HASKELL: [Comment; 2], pub fn haskell);

#[allow(dead_code)]
const RUST: [Comment; 2] = [
    Comment {
        open_pat: "//",
        close_pat: "\n",
        nests: false,
        keep_close_pat: true,
        allow_close_pat: true,
    },
    Comment {
        open_pat: "/*",
        close_pat: "*/",
        nests: true,
        keep_close_pat: false,
        allow_close_pat: false,
    },
];

#[allow(dead_code)]
const C: [Comment; 2] = [
    Comment {
        open_pat: "//",
        close_pat: "\n",
        nests: false,
        keep_close_pat: true,
        allow_close_pat: true,
    },
    Comment {
        open_pat: "/*",
        close_pat: "*/",
        nests: false,
        keep_close_pat: false,
        allow_close_pat: false,
    },
];

#[allow(dead_code)]
const PYTHON: [Comment; 3] = [
    Comment {
        open_pat: "#",
        close_pat: "\n",
        nests: false,
        keep_close_pat: true,
        allow_close_pat: true,
    },
    // allow_close_pat won't be checked because open_pat will match first
    Comment {
        open_pat: "'''",
        close_pat: "'''",
        nests: false,
        keep_close_pat: false,
        allow_close_pat: false,
    },
    Comment {
        open_pat: "\"\"\"",
        close_pat: "\"\"\"",
        nests: false,
        keep_close_pat: false,
        allow_close_pat: false,
    },
];

#[allow(dead_code)]
const HASKELL: [Comment; 2] = [
    Comment {
        open_pat: "--",
        close_pat: "\n",
        nests: false,
        keep_close_pat: true,
        allow_close_pat: true,
    },
    Comment {
        open_pat: "{-",
        close_pat: "-}",
        nests: true,
        keep_close_pat: false,
        allow_close_pat: false,
    },
];