#![doc = docs!(doc_line)]
include!(concat!(env!("OUT_DIR"), "/raw.rs"));
mod doc;
mod language;
mod util;
mod highlighter;
mod capture;
pub use language::Language;
pub use highlighter::{Highlighter, Highlight};
pub use capture::{EXHAUSTIVE_CAPTURES, COMMON_CAPTURES};
pub use theme::Theme;
mod theme {
use std::borrow::Cow;
use rustc_hash::FxHashMap;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Theme<T> {
map: FxHashMap<Cow<'static, str>, T>
}
impl<S, T> FromIterator<(S, T)> for Theme<T>
where S: Into<Cow<'static, str>>
{
fn from_iter<I: IntoIterator<Item = (S, T)>>(iter: I) -> Self {
let map = iter.into_iter()
.map(|(k, v)| (k.into(), v))
.collect();
Self { map }
}
}
impl<T> Theme<T> {
pub fn find(&self, capture: &str) -> Option<&T> {
let mut candidate = capture;
loop {
if capture.is_empty() {
return None;
}
if let Some(value) = self.map.get(candidate) {
return Some(value);
}
candidate = &candidate[..candidate.rfind('.')?];
}
}
}
}