forked from Orchid/orchid
Most files suffered major changes
- Less ambiguous syntax - Better parser (Chumsky only does tokenization now) - Tidy(|ier) error handling - Facade for simplified embedding - External code grouped in (fairly) self-contained Systems - Dynamic action dispatch - Many STL additions
This commit is contained in:
@@ -8,6 +8,7 @@ use hashbrown::HashMap;
|
||||
|
||||
use super::monotype::TypedInterner;
|
||||
use super::token::Tok;
|
||||
use super::InternedDisplay;
|
||||
|
||||
/// A collection of interners based on their type. Allows to intern any object
|
||||
/// that implements [ToOwned]. Objects of the same type are stored together in a
|
||||
@@ -59,6 +60,29 @@ impl Interner {
|
||||
) -> Vec<T> {
|
||||
s.iter().map(|t| self.r(*t)).cloned().collect()
|
||||
}
|
||||
|
||||
/// A variant of `unwrap` using [InternedDisplay] to circumvent `unwrap`'s
|
||||
/// dependencyon [Debug]. For clarity, [expect] should be preferred.
|
||||
pub fn unwrap<T, E: InternedDisplay>(&self, result: Result<T, E>) -> T {
|
||||
result.unwrap_or_else(|e| {
|
||||
println!("Unwrapped Error: {}", e.bundle(self));
|
||||
panic!("Unwrapped an error");
|
||||
})
|
||||
}
|
||||
|
||||
/// A variant of `expect` using [InternedDisplay] to circumvent `expect`'s
|
||||
/// depeendency on [Debug].
|
||||
pub fn expect<T, E: InternedDisplay>(
|
||||
&self,
|
||||
result: Result<T, E>,
|
||||
msg: &str,
|
||||
) -> T {
|
||||
result.unwrap_or_else(|e| {
|
||||
println!("Expectation failed: {msg}");
|
||||
println!("Error: {}", e.bundle(self));
|
||||
panic!("Expected an error");
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Interner {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use core::fmt::Formatter;
|
||||
use std::fmt::Display;
|
||||
use core::fmt::{self, Display, Formatter};
|
||||
use core::ops::Deref;
|
||||
use std::rc::Rc;
|
||||
|
||||
use crate::interner::Interner;
|
||||
|
||||
@@ -29,16 +30,13 @@ pub trait InternedDisplay {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> InternedDisplay for T
|
||||
// Special loophole for Rc<dyn ProjectError>
|
||||
impl<T: ?Sized> InternedDisplay for Rc<T>
|
||||
where
|
||||
T: Display,
|
||||
T: InternedDisplay,
|
||||
{
|
||||
fn fmt_i(
|
||||
&self,
|
||||
f: &mut std::fmt::Formatter<'_>,
|
||||
_i: &Interner,
|
||||
) -> std::fmt::Result {
|
||||
<Self as Display>::fmt(self, f)
|
||||
fn fmt_i(&self, f: &mut Formatter<'_>, i: &Interner) -> fmt::Result {
|
||||
self.deref().fmt_i(f, i)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user