NodeFactory
via FactoryModeParse
This commit is contained in:
parent
25fe0655dc
commit
7f1d72898d
@ -142,25 +142,32 @@ impl<'a, Ctx: Context<'a>, F: FactoryBase<'a, Ctx>> FactoryBase<'a, Ctx> for Nod
|
||||
type ParseError = TreeParseError<F::ParseError>;
|
||||
}
|
||||
|
||||
impl<F> ImplMode for NodeFactory<F> {
|
||||
type Mode = RegularMode;
|
||||
impl<F: ParseMode> ParseMode for NodeFactory<F> {
|
||||
type Mode = F::Mode;
|
||||
}
|
||||
|
||||
impl<'a, Ctx: Context<'a>, F: FactoryParse<'a, Ctx>> CRegularFactory<'a, Ctx> for NodeFactory<F> {
|
||||
fn crdeserialize(&self, inctx: impl InCtx<'a, Ctx>) -> ParseResult<'a, Ctx, Self> {
|
||||
impl<'a, Ctx: Context<'a>, F: FactoryModeParse<'a, Ctx>> FactoryModeParse<'a, Ctx>
|
||||
for NodeFactory<F>
|
||||
{
|
||||
fn mdeserialize<I: InCtx<'a, Ctx>>(&self, inctx: I) -> ModeResultM<'a, Ctx, Self, I> {
|
||||
let tree_factory = TreeFactory(NullableFactory::new(self.clone()));
|
||||
let (l, inctx) = tree_factory.ideserialize(inctx)?;
|
||||
let (r, inctx) = tree_factory.ideserialize(inctx)?;
|
||||
let key = self.0.deserialize(inctx).map_err(TreeParseError::Key)?;
|
||||
Ok(Node { l, r, key })
|
||||
let skey = self.0.mdeserialize(inctx).map_err(TreeParseError::Key)?;
|
||||
Ok(Self::map(skey, |key| Node { l, r, key }))
|
||||
}
|
||||
|
||||
fn crextend(&self, mut mentionable: Self::Mtbl, tail: &[u8]) -> ParseResult<'a, Ctx, Self> {
|
||||
mentionable.key = self
|
||||
.0
|
||||
.extend(mentionable.key, tail)
|
||||
.map_err(TreeParseError::Key)?;
|
||||
Ok(mentionable)
|
||||
fn mextend(
|
||||
&self,
|
||||
mentionable: ExtensionSourceM<'a, Ctx, Self>,
|
||||
tail: &[u8],
|
||||
) -> ExtensionResultM<'a, Ctx, Self> {
|
||||
Self::xsbind(
|
||||
mentionable,
|
||||
|Node { l, r, key }| ((l, r), key),
|
||||
|key| Self::xmap_err(self.0.mextend(key, tail), TreeParseError::Key),
|
||||
|(l, r), key| Ok(Node { l, r, key }),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user