use std::collections::HashMap;
use crate::style::StyleSpec;
#[derive(Clone, Default, Debug)]
pub struct CaptureMap {
flat: HashMap<String, StyleSpec>,
}
impl CaptureMap {
pub(crate) fn from_map(flat: HashMap<String, StyleSpec>) -> Self {
Self { flat }
}
pub fn get(&self, capture: &str) -> Option<&StyleSpec> {
self.flat.get(capture)
}
pub fn resolve(&self, capture: &str) -> Option<&StyleSpec> {
let mut key = capture;
loop {
if let Some(spec) = self.flat.get(key) {
return Some(spec);
}
{
let pos = key.rfind('.')?;
key = &key[..pos]
}
}
}
}