#![allow(clippy::redundant_pub_crate)]
use alloc::{collections::BTreeSet, string::String};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ScopingMode {
RespectParent,
AllowShadowing,
}
pub trait VariableBindingContext {
fn is_var_unbound(&self, var_name: &str, scoping: ScopingMode) -> bool;
fn has_same_scope_binding(&self, var_name: &str) -> bool;
}
pub(crate) struct OverlayBindingContext<'a, T: VariableBindingContext> {
pub(crate) base: &'a T,
pub(crate) newly_bound: &'a BTreeSet<String>,
}
impl<'a, T: VariableBindingContext> VariableBindingContext for OverlayBindingContext<'a, T> {
fn is_var_unbound(&self, var_name: &str, scoping: ScopingMode) -> bool {
if self.newly_bound.contains(var_name) {
return false;
}
self.base.is_var_unbound(var_name, scoping)
}
fn has_same_scope_binding(&self, var_name: &str) -> bool {
if self.newly_bound.contains(var_name) {
return true;
}
self.base.has_same_scope_binding(var_name)
}
}