OriginMap
This commit is contained in:
parent
1acce76b0b
commit
be427e4e87
@ -35,7 +35,7 @@ pub use self::inlining::{CInliningFactory, IParseResult, InliningFactory};
|
||||
pub use self::modes::{
|
||||
ExtensionResultM, ExtensionSourceM, FactoryModeParse, FactoryModeProxy, ModeResultM,
|
||||
};
|
||||
pub use self::origin::{OFctr, Origin};
|
||||
pub use self::origin::{OFctr, Origin, OriginMap};
|
||||
pub use self::point::Point;
|
||||
pub use self::points::PointsVisitor;
|
||||
pub use self::regular::{CRegularFactory, RegularFactory};
|
||||
|
@ -16,3 +16,25 @@ pub trait Origin<'a, Ctx: Context<'a>>: 'a {
|
||||
|
||||
/// Type of the [`Factory`] associated with the [`Origin`].
|
||||
pub type OFctr<'a, Ctx, O> = Fctr<'a, Ctx, <O as Origin<'a, Ctx>>::Mtbl>;
|
||||
|
||||
/// [`OriginMap::resolve_map`].
|
||||
pub trait OriginMap<'a, Ctx: Context<'a>>: Origin<'a, Ctx> {
|
||||
fn ref_resolve(self: &Rc<Self>) -> Resolution<'a, Ctx, Self::Mtbl>
|
||||
where
|
||||
OFctr<'a, Ctx, Self>: FactoryParse<'a, Ctx>,
|
||||
{
|
||||
self.clone().resolve()
|
||||
}
|
||||
|
||||
fn resolve_map<T>(
|
||||
self: &Rc<Self>,
|
||||
f: impl 'a + FnOnce(ResolutionResult<'a, Ctx, Self::Mtbl>) -> T,
|
||||
) -> Wrapped<'a, Ctx, T>
|
||||
where
|
||||
OFctr<'a, Ctx, Self>: FactoryParse<'a, Ctx>,
|
||||
{
|
||||
Ctx::fmap(self.ref_resolve(), f)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, Ctx: Context<'a>, R: ?Sized + Origin<'a, Ctx>> OriginMap<'a, Ctx> for R {}
|
||||
|
@ -32,7 +32,7 @@ where
|
||||
{
|
||||
/// See [`Origin::resolve`].
|
||||
pub fn resolve(&self) -> Resolution<'a, Ctx, A> {
|
||||
self.origin.clone().resolve()
|
||||
self.origin.ref_resolve()
|
||||
}
|
||||
|
||||
/// Resolve the object, then map the [ResolutionResult].
|
||||
@ -40,6 +40,6 @@ where
|
||||
&self,
|
||||
f: impl 'a + FnOnce(ResolutionResult<'a, Ctx, A>) -> B,
|
||||
) -> Wrapped<'a, Ctx, B> {
|
||||
Ctx::fmap(self.resolve(), f)
|
||||
self.origin.resolve_map(f)
|
||||
}
|
||||
}
|
||||
|
@ -126,7 +126,7 @@ impl<'a, Ctx: CastCtx<'a>> CastResolver<'a, Ctx> {
|
||||
}
|
||||
}
|
||||
|
||||
fn cast_resolved<'a, Ctx: CastCtx<'a>>(
|
||||
fn map_resolved<'a, Ctx: CastCtx<'a>>(
|
||||
resolved: ResolutionResult<'a, Ctx, TypelessMentionable<'a, Ctx>>,
|
||||
) -> HashResolutionResult<'a, Ctx> {
|
||||
match resolved {
|
||||
@ -147,7 +147,7 @@ impl<'a, Ctx: CastCtx<'a>> Resolver<'a, Ctx> for CastResolver<'a, Ctx> {
|
||||
Ok(point) => point,
|
||||
Err(cast_error) => return cast_error.pure::<Ctx>(),
|
||||
};
|
||||
point.resolve_map(cast_resolved)
|
||||
point.resolve_map(map_resolved)
|
||||
}
|
||||
}
|
||||
|
||||
@ -173,21 +173,16 @@ fn cast_resolve<'a, Ctx: CastCtx<'a>, A: Mentionable<'a, Ctx>>(
|
||||
typeless_origin: Rc<dyn Origin<'a, Ctx, Mtbl = TypelessMentionable<'a, Ctx>>>,
|
||||
factory: A::Fctr,
|
||||
) -> Resolution<'a, Ctx, A> {
|
||||
Ctx::fmap(
|
||||
typeless_origin.clone().resolve(),
|
||||
move |resolved| match resolved {
|
||||
Ok(typeless_mentionable) => match typeless_mentionable.cast(factory) {
|
||||
Ok(mentionable) => Ok(Rc::new(mentionable)),
|
||||
Err(parse_error) => Err(ResolutionError::Parse(parse_error)),
|
||||
},
|
||||
Err(error) => Err(ResolutionError::Lookup(match error {
|
||||
ResolutionError::Lookup(lookup_error) => lookup_error,
|
||||
ResolutionError::Parse(parse_error) => {
|
||||
Ctx::from_cast(CastError::Typeless(parse_error))
|
||||
}
|
||||
})),
|
||||
typeless_origin.resolve_map(|resolved| match resolved {
|
||||
Ok(typeless_mentionable) => match typeless_mentionable.cast(factory) {
|
||||
Ok(mentionable) => Ok(Rc::new(mentionable)),
|
||||
Err(parse_error) => Err(ResolutionError::Parse(parse_error)),
|
||||
},
|
||||
)
|
||||
Err(error) => Err(ResolutionError::Lookup(match error {
|
||||
ResolutionError::Lookup(lookup_error) => lookup_error,
|
||||
ResolutionError::Parse(parse_error) => Ctx::from_cast(CastError::Typeless(parse_error)),
|
||||
})),
|
||||
})
|
||||
}
|
||||
|
||||
fn cast_origin<'a, Ctx: CastCtx<'a>, A: Mentionable<'a, Ctx>>(
|
||||
|
@ -37,7 +37,7 @@ pub trait MappableOrigin<'a, Ctx: Context<'a>>: Origin<'a, Ctx> {
|
||||
let origin = origin_r.clone();
|
||||
let map_ok = map_ok.clone();
|
||||
let map_err = map_err.clone();
|
||||
map_resolve(move || origin.clone().resolve(), map_ok, map_err)
|
||||
map_resolve(move || origin.ref_resolve(), map_ok, map_err)
|
||||
}),
|
||||
w_resolve_bytes: Box::new(move || origin_rb.clone().resolve_bytes()),
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user