StackNodeFactory
via FactoryModeParse
This commit is contained in:
parent
6935b072dd
commit
25fe0655dc
@ -103,49 +103,40 @@ impl<'a, Ctx: Context<'a>, F: FactoryBase<'a, Ctx>> FactoryBase<'a, Ctx> for Sta
|
||||
type ParseError = StackParseError<ParseError<'a, Ctx, F>>;
|
||||
}
|
||||
|
||||
impl<F: ParseMode> ImplMode for StackNodeFactory<F> {
|
||||
impl<F: ParseMode> ParseMode for StackNodeFactory<F> {
|
||||
type Mode = F::Mode;
|
||||
}
|
||||
|
||||
impl<'a, Ctx: Context<'a>, F: Factory<'a, Ctx> + RegularFactory<'a, Ctx>> CRegularFactory<'a, Ctx>
|
||||
impl<'a, Ctx: Context<'a>, F: FactoryModeParse<'a, Ctx>> FactoryModeParse<'a, Ctx>
|
||||
for StackNodeFactory<F>
|
||||
where
|
||||
F::Mtbl: MentionableTop<'a, Ctx>,
|
||||
{
|
||||
fn crdeserialize(&self, inctx: impl InCtx<'a, Ctx>) -> ParseResult<'a, Ctx, Self> {
|
||||
fn mdeserialize<I: InCtx<'a, Ctx>>(&self, inctx: I) -> ModeResultM<'a, Ctx, Self, I> {
|
||||
let (rest, inctx) = self.parse_point(inctx)?;
|
||||
let element = self
|
||||
let selement = self
|
||||
.element_factory
|
||||
.rdeserialize(inctx)
|
||||
.mdeserialize(inctx)
|
||||
.map_err(StackParseError::Element)?;
|
||||
Ok(StackNode { rest, element })
|
||||
Ok(Self::map(selement, |element| StackNode { rest, element }))
|
||||
}
|
||||
|
||||
fn crextend(&self, mut mentionable: Self::Mtbl, tail: &[u8]) -> ParseResult<'a, Ctx, Self> {
|
||||
mentionable.element = self
|
||||
.element_factory
|
||||
.rextend(mentionable.element, tail)
|
||||
.map_err(StackParseError::Element)?;
|
||||
Ok(mentionable)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, Ctx: Context<'a>, F: Factory<'a, Ctx> + InliningFactory<'a, Ctx>> CInliningFactory<'a, Ctx>
|
||||
for StackNodeFactory<F>
|
||||
where
|
||||
F::Mtbl: MentionableTop<'a, Ctx>,
|
||||
{
|
||||
fn cextension_error(&self, tail: &[u8]) -> Self::ParseError {
|
||||
StackParseError::Element(self.element_factory.extension_error(tail))
|
||||
}
|
||||
|
||||
fn cideserialize<I: InCtx<'a, Ctx>>(&self, inctx: I) -> IParseResult<'a, Ctx, Self, I> {
|
||||
let (rest, inctx) = self.parse_point(inctx)?;
|
||||
let (element, inctx) = self
|
||||
.element_factory
|
||||
.ideserialize(inctx)
|
||||
.map_err(StackParseError::Element)?;
|
||||
Ok((StackNode { rest, element }, inctx))
|
||||
fn mextend(
|
||||
&self,
|
||||
mentionable: ExtensionSourceM<'a, Ctx, Self>,
|
||||
tail: &[u8],
|
||||
) -> ExtensionResultM<'a, Ctx, Self> {
|
||||
Self::xsbind(
|
||||
mentionable,
|
||||
|StackNode { rest, element }| (rest, element),
|
||||
|element| {
|
||||
Self::xmap_err(
|
||||
self.element_factory.mextend(element, tail),
|
||||
StackParseError::Element,
|
||||
)
|
||||
},
|
||||
|rest, element| Ok(StackNode { rest, element }),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user