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
|
use std::path::Path;
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Hash)]
pub enum Language {
Tex,
Bib,
Aux,
Log,
Root,
Latexmkrc,
Tectonic,
FileList,
}
impl Language {
pub fn from_path(path: &Path) -> Option<Self> {
let name = path.file_name()?;
if name.eq_ignore_ascii_case(".texlabroot") || name.eq_ignore_ascii_case("texlabroot") {
return Some(Self::Root);
}
if name.eq_ignore_ascii_case("Tectonic.toml") {
return Some(Self::Tectonic);
}
if name.eq_ignore_ascii_case(".latexmkrc") || name.eq_ignore_ascii_case("latexmkrc") {
return Some(Self::Latexmkrc);
}
let extname = path.extension()?.to_str()?;
match extname.to_lowercase().as_str() {
"tex" | "sty" | "cls" | "def" | "lco" | "rnw" => Some(Self::Tex),
"bib" | "bibtex" => Some(Self::Bib),
"aux" => Some(Self::Aux),
"log" => Some(Self::Log),
"fls" => Some(Self::FileList),
_ => None,
}
}
pub fn from_id(id: &str) -> Option<Self> {
match id {
"tex" | "latex" => Some(Self::Tex),
"bib" | "bibtex" => Some(Self::Bib),
"texlabroot" => Some(Self::Root),
_ => None,
}
}
}
|