Checkpoint

This commit is contained in:
2023-10-14 16:39:16 -07:00
parent 87d027bf8d
commit 71228b9e09
18 changed files with 402 additions and 78 deletions

47
src/util/pretty.rs Normal file
View File

@@ -0,0 +1,47 @@
use internment::ArcIntern;
use pretty::{DocAllocator, Pretty};
#[derive(Clone)]
pub struct PrettySymbol {
name: ArcIntern<String>,
}
impl<'a> From<&'a ArcIntern<String>> for PrettySymbol {
fn from(value: &'a ArcIntern<String>) -> Self {
PrettySymbol { name: value.clone() }
}
}
impl<'a, D, A> Pretty<'a, D, A> for PrettySymbol
where
A: 'a,
D: ?Sized + DocAllocator<'a, A>,
{
fn pretty(self, allocator: &'a D) -> pretty::DocBuilder<'a, D, A> {
allocator.text(self.name.as_ref().to_string())
}
}
impl<'a, 'b, D, A> Pretty<'a, D, A> for &'b PrettySymbol
where
A: 'a,
D: ?Sized + DocAllocator<'a, A>,
{
fn pretty(self, allocator: &'a D) -> pretty::DocBuilder<'a, D, A> {
allocator.text(self.name.as_ref().to_string())
}
}
#[allow(clippy::ptr_arg)]
pub fn pretty_comma_separated<'a, D, A, P>(
allocator: &'a D,
args: &Vec<P>,
) -> pretty::DocBuilder<'a, D, A>
where
A: 'a,
D: ?Sized + DocAllocator<'a, A>,
P: Pretty<'a, D, A> + Clone,
{
let individuals = args.iter().map(|x| x.clone().pretty(allocator));
allocator.intersperse(individuals, ", ")
}

View File

@@ -5,6 +5,12 @@ pub struct ScopedMap<K: Eq + Hash + PartialEq, V> {
scopes: Vec<HashMap<K, V>>,
}
impl<K: Eq + Hash + PartialEq, V> Default for ScopedMap<K, V> {
fn default() -> Self {
ScopedMap::new()
}
}
impl<K: Eq + Hash + PartialEq, V> ScopedMap<K, V> {
/// Generate a new scoped map.
///