Introduce a registry into the conversion to intermediate format.

This commit is contained in:
Tom Alexander
2023-10-27 14:43:06 -04:00
parent e3b5f7f74f
commit c6cf5f75ac
8 changed files with 68 additions and 12 deletions

View File

@@ -0,0 +1,24 @@
use std::collections::HashMap;
type IdCounter = u16;
pub(crate) struct Registry<'p> {
id_counter: IdCounter,
targets: HashMap<&'p str, String>,
}
impl<'p> Registry<'p> {
pub(crate) fn new() -> Registry<'p> {
Registry {
id_counter: 0,
targets: HashMap::new(),
}
}
pub(crate) fn get_target<'b>(&'b mut self, body: &'p str) -> &'b String {
self.targets.entry(body).or_insert_with(|| {
self.id_counter += 1;
format!("target_{}", self.id_counter)
})
}
}