-
Notifications
You must be signed in to change notification settings - Fork 6
/
config.rs
126 lines (121 loc) · 4.28 KB
/
config.rs
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#[derive(Debug)]
pub struct Config(&'static [Language]);
#[derive(Debug)]
pub struct Language {
pub name: &'static str,
pub extensions: &'static [&'static str],
pub single: &'static [&'static str],
pub multi: &'static [(&'static str, &'static str)],
}
macro_rules! language {
($name: expr, $ext: expr, $single: expr, $multi: expr) => {
Language {
name: $name,
extensions: $ext,
single: $single,
multi: $multi,
}
};
}
impl Config {
pub fn languages(&self) -> &'static [Language] {
self.0
}
// Get language configuration by extension
pub fn get(&self, extension: &str) -> Option<&Language> {
self.0
.iter()
.find(|&item| item.extensions.contains(&extension))
}
}
pub const CONFIG: Config = Config(&[
language!(
"ASP.NET",
&["asax", "ascx", "asmx", "aspx", "master", "sitemap", "webinfo"],
&[],
&[("<!--", "-->"), ("<%--", "-->")]
),
language!("C", &["c"], &["//"], &[("/*", "*/")]),
language!(
"CSS",
&["css", "scss", "sass", "less"],
&["//"],
&[("/*", "*/")]
),
language!("C++", &["cpp"], &["//"], &[("/*", "*/")]),
language!("Clojure", &["clj"], &[";", ";;", ";;;", ";;;;", "#_"], &[]),
language!(
"ClojureC",
&["cljc"],
&[";", ";;", ";;;", ";;;;", "#_"],
&[]
),
language!(
"ClojureDart",
&["cljd"],
&[";", ";;", ";;;", ";;;;", "#_"],
&[]
),
language!(
"ClojureScript",
&["cljs"],
&[";", ";;", ";;;", ";;;;", "#_"],
&[]
),
language!("CoffeeScript", &["coffee"], &["#"], &[("###", "###")]),
language!("C#", &["cs"], &["//", "///"], &[("/*", "*/")]),
language!("D", &["d"], &["//", "///"], &[("/*", "*/")]),
language!("Dart", &["dart"], &["//", "///"], &[("/*", "*/")]),
language!("EDN", &["edn"], &[";", ";;", ";;;", ";;;;", "#_"], &[]),
language!("Go", &["go"], &["//"], &[("/*", "*/")]),
language!("HTML", &["htm", "html"], &[], &[("<!--", "-->")]),
language!("Haskell", &["hs"], &["--"], &[("{-", "-}")]),
language!("JavaScript", &["js", "mjs"], &["//"], &[("/*", "*/")]),
language!("JavaScript JSX", &["jsx"], &["//"], &[("/*", "*/")]),
language!("JSON", &["json"], &[], &[]),
language!("Julia", &["jl"], &["#"], &[("#=", "=#")]),
language!("Java", &["java"], &["//"], &[("/*", "*/")]),
language!(
"Common Lisp",
&["lisp", "lsp", "l", "cl", "fasl"],
&[";", ";;", ";;;", ";;;;"],
&[("#|", "|#")]
),
language!("LLVM", &["ll"], &[","], &[]),
language!("Lua", &["lua"], &["--"], &[("--[[", "]]")]),
language!("Markdown", &["md", "markdown"], &[], &[]),
language!("Nim", &["nim"], &["#"], &[("#[", "]#")]),
language!("ObjectiveC", &["m"], &["//", "///"], &[("/*", "*/")]),
language!("Objective-C++", &["mm"], &["//"], &[("/*", "*/")]),
language!("PHP", &["php"], &["//", "#"], &[("/*", "*/")]),
language!(
"Python",
&["py"],
&["#"],
&[("'''", "'''"), (r#"""""#, r#"""""#)]
),
language!("Perl", &["pl", "pm"], &["#"], &[("=", "=")]),
language!("R", &["r"], &["#"], &[]),
language!("Rust", &["rs"], &["//", "///"], &[("/*", "*/")]),
language!("Ruby", &["rb"], &["#"], &[("=", "=")]),
language!("Swift", &["swift"], &["//"], &[("/*", "*/")]),
language!("Scala", &["sc"], &["//"], &[("/*", "*/")]),
language!(
"Scheme",
&["scm", "ss"],
&[";", ";;", ";;;", ";;;;", "#;"],
&[("#|", "|#")]
),
language!("Shell", &["sh", "bash", "zsh", "fish"], &["#"], &[]),
language!("SQL", &["sql"], &["--"], &[("/*", "*/")]),
language!("TypeScript", &["ts"], &["//"], &[("/*", "*/")]),
language!("TypeScript JSX", &["tsx"], &["//"], &[("/*", "*/")]),
language!("TOML", &["toml"], &["#"], &[]),
// This file may contain multiple languages. html.. js ts .. css scss sass..
// Not processed here
language!("Vue", &["vue"], &["//"], &[("<!--", "-->"), ("/*", "*/")]),
language!("VimScript", &["vim"], &[], &[]),
language!("XML", &["xml"], &[], &[("<!--", "-->")]),
language!("YAML", &["yml", "yaml"], &["#"], &[]),
language!("Kotlin", &["kt"], &["//"], &[("/*", "*/")]),
]);