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
|
use once_cell::sync::Lazy;
use serde::{Deserialize, Serialize};
#[derive(Debug, PartialEq, Eq, Clone, Copy, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub enum BibtexEntryTypeCategory {
Misc,
String,
Article,
Book,
Collection,
Part,
Thesis,
}
#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct BibtexEntryTypeDoc {
pub name: String,
pub category: BibtexEntryTypeCategory,
pub documentation: Option<String>,
}
#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct BibtexFieldDoc {
pub name: String,
pub documentation: String,
}
#[derive(Debug, PartialEq, Eq, Clone, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct LanguageData {
pub colors: Vec<String>,
pub entry_types: Vec<BibtexEntryTypeDoc>,
pub fields: Vec<BibtexFieldDoc>,
pub pgf_libraries: Vec<String>,
pub tikz_libraries: Vec<String>,
pub math_environments: Vec<String>,
pub enum_environments: Vec<String>,
}
impl LanguageData {
pub fn find_entry_type(&self, name: &str) -> Option<&BibtexEntryTypeDoc> {
let name = name.to_lowercase();
self.entry_types
.iter()
.find(|ty| ty.name.to_lowercase() == name)
}
pub fn entry_type_documentation(&self, name: &str) -> Option<&str> {
self.find_entry_type(name)
.and_then(|ty| ty.documentation.as_ref().map(AsRef::as_ref))
}
pub fn field_documentation(&self, name: &str) -> Option<&str> {
self.fields
.iter()
.find(|field| field.name.to_lowercase() == name.to_lowercase())
.map(|field| field.documentation.as_ref())
}
}
pub static LANGUAGE_DATA: Lazy<LanguageData> = Lazy::new(|| {
const JSON: &str = include_str!("../data/lang_data.json");
serde_json::from_str(JSON).expect("Failed to deserialize language.json")
});
|