QRegularFactory
This commit is contained in:
parent
59a771630f
commit
c9e65ca690
@ -34,7 +34,7 @@ pub use self::inctx::InCtx;
|
||||
pub use self::inlining::{Inlining, InliningExt, InliningResultExt};
|
||||
pub use self::modes::{
|
||||
ExtensionResultM, ExtensionSourceM, FactoryModeParse, FactoryModeProxy, ImplMode, Mode,
|
||||
ParseMode, ParseResultM, RegularFactory, RegularMode, WithMode, WithParseMode,
|
||||
ParseMode, ParseResultM, QRegularFactory, RegularFactory, RegularMode, WithMode, WithParseMode,
|
||||
};
|
||||
pub use self::origin::{OFctr, Origin};
|
||||
pub use self::point::Point;
|
||||
|
@ -32,6 +32,11 @@ pub trait Mode {
|
||||
) -> Self::ExtensionResult<A1, E>;
|
||||
|
||||
fn xseal<A, E>(result: Self::ExtensionResult<A, E>) -> Result<A, E>;
|
||||
|
||||
fn smap<A0, A1, E>(
|
||||
source: Self::ExtensionSource<A0, E>,
|
||||
f: impl FnOnce(A0) -> A1,
|
||||
) -> Self::ExtensionSource<A1, E>;
|
||||
}
|
||||
|
||||
pub trait ParseMode {
|
||||
@ -66,7 +71,7 @@ impl<'a, Ctx: Context<'a>, F: FactoryModeParse<'a, Ctx>> FactoryParse<'a, Ctx> f
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, Ctx: Context<'a>, F: FactoryParse<'a, Ctx> + WithParseMode> Factory<'a, Ctx> for F
|
||||
impl<'a, Ctx: Context<'a>, F: FactoryParse<'a, Ctx> + ParseMode> Factory<'a, Ctx> for F
|
||||
where
|
||||
F::Mtbl: MentionableTop<'a, Ctx>,
|
||||
{
|
||||
@ -174,6 +179,20 @@ impl Mode for RegularMode {
|
||||
fn xseal<A, E>(result: Self::ExtensionResult<A, E>) -> Result<A, E> {
|
||||
result
|
||||
}
|
||||
|
||||
fn smap<A0, A1, E>(
|
||||
source: Self::ExtensionSource<A0, E>,
|
||||
f: impl FnOnce(A0) -> A1,
|
||||
) -> Self::ExtensionSource<A1, E> {
|
||||
f(source)
|
||||
}
|
||||
}
|
||||
|
||||
pub trait QRegularFactory<'a, Ctx: Context<'a>>:
|
||||
FactoryBase<'a, Ctx> + ImplMode<Mode = RegularMode>
|
||||
{
|
||||
fn qrdeserialize(&self, inctx: impl InCtx<'a, Ctx>) -> ParseResult<'a, Ctx, Self>;
|
||||
fn qrextend(&self, mentionable: Self::Mtbl, tail: &[u8]) -> ParseResult<'a, Ctx, Self>;
|
||||
}
|
||||
|
||||
pub trait RegularFactory<'a, Ctx: Context<'a>>:
|
||||
@ -183,17 +202,29 @@ pub trait RegularFactory<'a, Ctx: Context<'a>>:
|
||||
fn rextend(&self, mentionable: Self::Mtbl, tail: &[u8]) -> ParseResult<'a, Ctx, Self>;
|
||||
}
|
||||
|
||||
impl<'a, Ctx: Context<'a>, F: RegularFactory<'a, Ctx>> FactoryModeProxy<'a, Ctx>
|
||||
impl<'a, Ctx: Context<'a>, F: FactoryModeParse<'a, Ctx> + ParseMode<Mode = RegularMode>>
|
||||
RegularFactory<'a, Ctx> for F
|
||||
{
|
||||
fn rdeserialize(&self, inctx: impl InCtx<'a, Ctx>) -> ParseResult<'a, Ctx, Self> {
|
||||
self.mdeserialize(inctx)
|
||||
}
|
||||
|
||||
fn rextend(&self, mentionable: Self::Mtbl, tail: &[u8]) -> ParseResult<'a, Ctx, Self> {
|
||||
self.mextend(mentionable, tail)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, Ctx: Context<'a>, F: QRegularFactory<'a, Ctx>> FactoryModeProxy<'a, Ctx>
|
||||
for WithMode<F, RegularMode>
|
||||
{
|
||||
type F = F;
|
||||
|
||||
fn pmdeserialize<I: InCtx<'a, Ctx>>(f: &Self::F, inctx: I) -> ParseResultM<'a, Ctx, F, I> {
|
||||
f.rdeserialize(inctx)
|
||||
f.qrdeserialize(inctx)
|
||||
}
|
||||
|
||||
fn pmextend(f: &F, mentionable: Mtbl<'a, Ctx, F>, tail: &[u8]) -> ExtensionResultM<'a, Ctx, F> {
|
||||
f.rextend(mentionable, tail)
|
||||
f.qrextend(mentionable, tail)
|
||||
}
|
||||
|
||||
fn pmprepare(mentionable: Mtbl<'a, Ctx, Self::F>) -> ExtensionSourceM<'a, Ctx, Self::F> {
|
||||
|
@ -75,17 +75,31 @@ impl<'a, Ctx: Context<'a>, A: AtomicBase> FactoryBase<'a, Ctx> for AtomicFactory
|
||||
type ParseError = A::AParseError;
|
||||
}
|
||||
|
||||
impl<A: ParseMode> ImplMode for AtomicFactory<A> {
|
||||
impl<A: ParseMode> ParseMode for AtomicFactory<A> {
|
||||
type Mode = A::Mode;
|
||||
}
|
||||
|
||||
impl<'a, Ctx: Context<'a>, A: RegularAtomic> RegularFactory<'a, Ctx> for AtomicFactory<A> {
|
||||
fn rdeserialize(&self, inctx: impl InCtx<'a, Ctx>) -> ParseResult<'a, Ctx, Self> {
|
||||
Ok(A::ra_deserialize(inctx)?.into())
|
||||
impl<'a, Ctx: Context<'a>, A: AtomicModeParse> FactoryModeParse<'a, Ctx> for AtomicFactory<A> {
|
||||
fn mdeserialize<I: InCtx<'a, Ctx>>(&self, inctx: I) -> ParseResultM<'a, Ctx, Self, I> {
|
||||
<<A as ParseMode>::Mode as Mode>::bind(A::ma_deserialize(inctx), |a| Ok(a.into()))
|
||||
}
|
||||
|
||||
fn rextend(&self, mentionable: Self::Mtbl, tail: &[u8]) -> ParseResult<'a, Ctx, Self> {
|
||||
Ok(A::ra_extend(mentionable.atomic, tail)?.into())
|
||||
fn mextend(
|
||||
&self,
|
||||
mentionable: ExtensionSourceM<'a, Ctx, Self>,
|
||||
tail: &[u8],
|
||||
) -> ExtensionResultM<'a, Ctx, Self> {
|
||||
<<A as ParseMode>::Mode as Mode>::xbind(
|
||||
A::ma_extend(
|
||||
<<A as ParseMode>::Mode as Mode>::smap(mentionable, |a| a.atomic),
|
||||
tail,
|
||||
),
|
||||
|a| Ok(a.into()),
|
||||
)
|
||||
}
|
||||
|
||||
fn mprepare(mentionable: Self::Mtbl) -> ExtensionSourceM<'a, Ctx, Self> {
|
||||
<<A as ParseMode>::Mode as Mode>::smap(mentionable.atomic.ma_prepare(), |a| a.into())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -106,12 +106,12 @@ impl<F: ParseMode> ImplMode for StackNodeFactory<F> {
|
||||
type Mode = F::Mode;
|
||||
}
|
||||
|
||||
impl<'a, Ctx: Context<'a>, F: Factory<'a, Ctx> + RegularFactory<'a, Ctx>> RegularFactory<'a, Ctx>
|
||||
impl<'a, Ctx: Context<'a>, F: Factory<'a, Ctx> + RegularFactory<'a, Ctx>> QRegularFactory<'a, Ctx>
|
||||
for StackNodeFactory<F>
|
||||
where
|
||||
F::Mtbl: MentionableTop<'a, Ctx>,
|
||||
{
|
||||
fn rdeserialize(&self, inctx: impl InCtx<'a, Ctx>) -> ParseResult<'a, Ctx, Self> {
|
||||
fn qrdeserialize(&self, inctx: impl InCtx<'a, Ctx>) -> ParseResult<'a, Ctx, Self> {
|
||||
let (rest, inctx) = self.parse_point(inctx)?;
|
||||
let element = self
|
||||
.element_factory
|
||||
@ -120,7 +120,7 @@ where
|
||||
Ok(StackNode { rest, element })
|
||||
}
|
||||
|
||||
fn rextend(&self, mut mentionable: Self::Mtbl, tail: &[u8]) -> ParseResult<'a, Ctx, Self> {
|
||||
fn qrextend(&self, mut mentionable: Self::Mtbl, tail: &[u8]) -> ParseResult<'a, Ctx, Self> {
|
||||
mentionable.element = self
|
||||
.element_factory
|
||||
.extend(mentionable.element, tail)
|
||||
@ -182,8 +182,8 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx> + Mentionable<'a, Ctx> + Clone>
|
||||
ExtStackClone<'a, Ctx, A> for Stack<'a, Ctx, A>
|
||||
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx> + Clone> ExtStackClone<'a, Ctx, A>
|
||||
for Stack<'a, Ctx, A>
|
||||
where
|
||||
StackNode<'a, Ctx, A>: Mentionable<'a, Ctx, _Fctr = StackNodeFactory<A::Fctr>>,
|
||||
StackNodeFactory<A::Fctr>: FactoryParse<'a, Ctx>,
|
||||
|
@ -144,8 +144,8 @@ impl<F> ImplMode for NodeFactory<F> {
|
||||
type Mode = RegularMode;
|
||||
}
|
||||
|
||||
impl<'a, Ctx: Context<'a>, F: FactoryParse<'a, Ctx>> RegularFactory<'a, Ctx> for NodeFactory<F> {
|
||||
fn rdeserialize(&self, inctx: impl InCtx<'a, Ctx>) -> ParseResult<'a, Ctx, Self> {
|
||||
impl<'a, Ctx: Context<'a>, F: FactoryParse<'a, Ctx>> QRegularFactory<'a, Ctx> for NodeFactory<F> {
|
||||
fn qrdeserialize(&self, inctx: impl InCtx<'a, Ctx>) -> ParseResult<'a, Ctx, Self> {
|
||||
let tree_factory = TreeFactory(NullableFactory::new(self.clone()));
|
||||
let (l, inctx) = tree_factory.ideserialize(inctx)?;
|
||||
let (r, inctx) = tree_factory.ideserialize(inctx)?;
|
||||
@ -153,7 +153,7 @@ impl<'a, Ctx: Context<'a>, F: FactoryParse<'a, Ctx>> RegularFactory<'a, Ctx> for
|
||||
Ok(Node { l, r, key })
|
||||
}
|
||||
|
||||
fn rextend(&self, mut mentionable: Self::Mtbl, tail: &[u8]) -> ParseResult<'a, Ctx, Self> {
|
||||
fn qrextend(&self, mut mentionable: Self::Mtbl, tail: &[u8]) -> ParseResult<'a, Ctx, Self> {
|
||||
mentionable.key = self
|
||||
.0
|
||||
.extend(mentionable.key, tail)
|
||||
|
@ -46,6 +46,13 @@ impl Mode for InliningMode {
|
||||
fn xseal<A, E>(result: Self::ExtensionResult<A, E>) -> Result<A, E> {
|
||||
Err(result)
|
||||
}
|
||||
|
||||
fn smap<A0, A1, E>(
|
||||
source: Self::ExtensionSource<A0, E>,
|
||||
_f: impl FnOnce(A0) -> A1,
|
||||
) -> Self::ExtensionSource<A1, E> {
|
||||
source
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, Ctx: Context<'a>, F: InliningFactory<'a, Ctx>> FactoryModeProxy<'a, Ctx>
|
||||
|
@ -140,16 +140,16 @@ impl<'a, Ctx: Context<'a>, SP: StaticPair<'a, Ctx>> FactoryBase<'a, Ctx>
|
||||
type ParseError = SP::ParseError;
|
||||
}
|
||||
|
||||
impl<'a, Ctx: Context<'a>, SP: StaticPair<'a, Ctx>> ParseMode for StaticPairFactory<'a, Ctx, SP> {
|
||||
impl<'a, Ctx: Context<'a>, SP: StaticPair<'a, Ctx>> ImplMode for StaticPairFactory<'a, Ctx, SP> {
|
||||
type Mode = <SP::FB as ParseMode>::Mode;
|
||||
}
|
||||
|
||||
impl<'a, Ctx: Context<'a>, SP: StaticPair<'a, Ctx>> RegularFactory<'a, Ctx>
|
||||
impl<'a, Ctx: Context<'a>, SP: StaticPair<'a, Ctx>> QRegularFactory<'a, Ctx>
|
||||
for StaticPairFactory<'a, Ctx, SP>
|
||||
where
|
||||
SP::FB: RegularFactory<'a, Ctx>,
|
||||
{
|
||||
fn rdeserialize(&self, inctx: impl InCtx<'a, Ctx>) -> ParseResult<'a, Ctx, Self> {
|
||||
fn qrdeserialize(&self, inctx: impl InCtx<'a, Ctx>) -> ParseResult<'a, Ctx, Self> {
|
||||
let (fa, fb) = SP::factories(&self.factory_data);
|
||||
let (a, inctx) = fa
|
||||
.ideserialize(inctx)
|
||||
@ -162,7 +162,7 @@ where
|
||||
})
|
||||
}
|
||||
|
||||
fn rextend(&self, mentionable: Self::Mtbl, tail: &[u8]) -> ParseResult<'a, Ctx, Self> {
|
||||
fn qrextend(&self, mentionable: Self::Mtbl, tail: &[u8]) -> ParseResult<'a, Ctx, Self> {
|
||||
let (_, fb) = SP::factories(&self.factory_data);
|
||||
let (a, b) = mentionable.pair.into_elements();
|
||||
match fb.rextend(b, tail) {
|
||||
|
@ -99,12 +99,12 @@ impl<'a, Ctx: Context<'a>> ImplMode for TypelessFactory<'a, Ctx> {
|
||||
type Mode = RegularMode;
|
||||
}
|
||||
|
||||
impl<'a, Ctx: Context<'a>> RegularFactory<'a, Ctx> for TypelessFactory<'a, Ctx> {
|
||||
fn rdeserialize(&self, inctx: impl InCtx<'a, Ctx>) -> ParseResult<'a, Ctx, Self> {
|
||||
impl<'a, Ctx: Context<'a>> QRegularFactory<'a, Ctx> for TypelessFactory<'a, Ctx> {
|
||||
fn qrdeserialize(&self, inctx: impl InCtx<'a, Ctx>) -> ParseResult<'a, Ctx, Self> {
|
||||
self.t_deserialize.de(inctx.demote()).map_err(TypelessError)
|
||||
}
|
||||
|
||||
fn rextend(&self, mentionable: Self::Mtbl, tail: &[u8]) -> ParseResult<'a, Ctx, Self> {
|
||||
fn qrextend(&self, mentionable: Self::Mtbl, tail: &[u8]) -> ParseResult<'a, Ctx, Self> {
|
||||
self.t_extend.xt(mentionable, tail)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user