mode::regular
This commit is contained in:
parent
5bc65753dd
commit
138f6f2d24
@ -1,5 +1,9 @@
|
|||||||
|
mod regular;
|
||||||
|
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
|
|
||||||
|
pub use self::regular::RegularMode;
|
||||||
|
|
||||||
/// See [`ModeResult`].
|
/// See [`ModeResult`].
|
||||||
pub type ParseSuccess<M, A, I> = <M as Mode>::ParseSuccess<A, I>;
|
pub type ParseSuccess<M, A, I> = <M as Mode>::ParseSuccess<A, I>;
|
||||||
|
|
||||||
@ -23,7 +27,6 @@ pub type ModeResult<M, A, E, I> = Result<ParseSuccess<M, A, I>, E>;
|
|||||||
/// | [`RegularMode`] | `A` | [`Result<A, E>`] | `A` |
|
/// | [`RegularMode`] | `A` | [`Result<A, E>`] | `A` |
|
||||||
/// | [`InliningMode`] | [`(A, I)`] | `E` | [`()`] |
|
/// | [`InliningMode`] | [`(A, I)`] | `E` | [`()`] |
|
||||||
///
|
///
|
||||||
/// [`RegularMode`]: crate::rcore::RegularMode
|
|
||||||
/// [`InliningMode`]: crate::rstd::inlining::InliningMode
|
/// [`InliningMode`]: crate::rstd::inlining::InliningMode
|
||||||
/// [`(A, I)`]: tuple
|
/// [`(A, I)`]: tuple
|
||||||
/// [`()`]: unit
|
/// [`()`]: unit
|
||||||
|
75
src/mode/regular.rs
Normal file
75
src/mode/regular.rs
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
use super::*;
|
||||||
|
|
||||||
|
/// [`Mode`] for [`RegularFactory`] and [`RegularAtomic`].
|
||||||
|
///
|
||||||
|
/// [`RegularFactory`]: crate::rcore::RegularFactory
|
||||||
|
/// [`RegularAtomic`]: crate::rstd::atomic::RegularAtomic
|
||||||
|
pub struct RegularMode;
|
||||||
|
|
||||||
|
impl Mode for RegularMode {
|
||||||
|
/// Discards the parser.
|
||||||
|
type ParseSuccess<A, I> = A;
|
||||||
|
|
||||||
|
/// Tries to extend the value.
|
||||||
|
type ExtensionResult<A, E> = Result<A, E>;
|
||||||
|
|
||||||
|
/// Keeps the value.
|
||||||
|
type ExtensionSource<A> = A;
|
||||||
|
|
||||||
|
fn bind<A0, A1, E, I>(
|
||||||
|
s: Self::ParseSuccess<A0, I>,
|
||||||
|
f: impl FnOnce(A0) -> Result<A1, E>,
|
||||||
|
) -> ModeResult<Self, A1, E, I> {
|
||||||
|
f(s)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn map<A0, A1, I>(
|
||||||
|
s: Self::ParseSuccess<A0, I>,
|
||||||
|
f: impl FnOnce(A0) -> A1,
|
||||||
|
) -> Self::ParseSuccess<A1, I> {
|
||||||
|
f(s)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn seal<A, I>(s: Self::ParseSuccess<A, I>) -> A {
|
||||||
|
s
|
||||||
|
}
|
||||||
|
|
||||||
|
fn xmap_err<A, E0, E1>(
|
||||||
|
result: Self::ExtensionResult<A, E0>,
|
||||||
|
f: impl FnOnce(E0) -> E1,
|
||||||
|
) -> Self::ExtensionResult<A, E1> {
|
||||||
|
result.map_err(f)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn xbind<A0, A1, E>(
|
||||||
|
result: Self::ExtensionResult<A0, E>,
|
||||||
|
f: impl FnOnce(A0) -> Result<A1, E>,
|
||||||
|
) -> Self::ExtensionResult<A1, E> {
|
||||||
|
result.and_then(f)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn xseal<A, E>(result: Self::ExtensionResult<A, E>) -> Result<A, E> {
|
||||||
|
result
|
||||||
|
}
|
||||||
|
|
||||||
|
fn smap<A0, A1>(
|
||||||
|
source: Self::ExtensionSource<A0>,
|
||||||
|
f: impl FnOnce(A0) -> A1,
|
||||||
|
) -> Self::ExtensionSource<A1> {
|
||||||
|
f(source)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn prepare<A>(a: A) -> Self::ExtensionSource<A> {
|
||||||
|
a
|
||||||
|
}
|
||||||
|
|
||||||
|
fn xsbind<AB, A, B, E>(
|
||||||
|
ab: Self::ExtensionSource<AB>,
|
||||||
|
t2ab: impl FnOnce(AB) -> (A, B),
|
||||||
|
ce: impl FnOnce(Self::ExtensionSource<B>) -> Self::ExtensionResult<B, E>,
|
||||||
|
ab2t: impl FnOnce(A, B) -> Result<AB, E>,
|
||||||
|
) -> Self::ExtensionResult<AB, E> {
|
||||||
|
let (b, c) = t2ab(ab);
|
||||||
|
ab2t(b, ce(c)?)
|
||||||
|
}
|
||||||
|
}
|
@ -35,7 +35,7 @@ pub use self::inctx::InCtx;
|
|||||||
pub use self::inlining::{Inlining, InliningExt, InliningResultExt};
|
pub use self::inlining::{Inlining, InliningExt, InliningResultExt};
|
||||||
pub use self::modes::{
|
pub use self::modes::{
|
||||||
CRegularFactory, ExtensionResultM, ExtensionSourceM, FactoryModeParse, FactoryModeProxy,
|
CRegularFactory, ExtensionResultM, ExtensionSourceM, FactoryModeParse, FactoryModeProxy,
|
||||||
ModeResultM, RegularFactory, RegularMode,
|
ModeResultM, RegularFactory,
|
||||||
};
|
};
|
||||||
pub use self::origin::{OFctr, Origin};
|
pub use self::origin::{OFctr, Origin};
|
||||||
pub use self::point::Point;
|
pub use self::point::Point;
|
||||||
|
@ -73,77 +73,6 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// [`Mode`] for [`RegularFactory`].
|
|
||||||
pub struct RegularMode;
|
|
||||||
|
|
||||||
impl Mode for RegularMode {
|
|
||||||
/// Discards the parser.
|
|
||||||
type ParseSuccess<A, I> = A;
|
|
||||||
|
|
||||||
/// Tries to extend the value.
|
|
||||||
type ExtensionResult<A, E> = Result<A, E>;
|
|
||||||
|
|
||||||
/// Keeps the value.
|
|
||||||
type ExtensionSource<A> = A;
|
|
||||||
|
|
||||||
fn bind<A0, A1, E, I>(
|
|
||||||
s: Self::ParseSuccess<A0, I>,
|
|
||||||
f: impl FnOnce(A0) -> Result<A1, E>,
|
|
||||||
) -> ModeResult<Self, A1, E, I> {
|
|
||||||
f(s)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn map<A0, A1, I>(
|
|
||||||
s: Self::ParseSuccess<A0, I>,
|
|
||||||
f: impl FnOnce(A0) -> A1,
|
|
||||||
) -> Self::ParseSuccess<A1, I> {
|
|
||||||
f(s)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn seal<A, I>(s: Self::ParseSuccess<A, I>) -> A {
|
|
||||||
s
|
|
||||||
}
|
|
||||||
|
|
||||||
fn xmap_err<A, E0, E1>(
|
|
||||||
result: Self::ExtensionResult<A, E0>,
|
|
||||||
f: impl FnOnce(E0) -> E1,
|
|
||||||
) -> Self::ExtensionResult<A, E1> {
|
|
||||||
result.map_err(f)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn xbind<A0, A1, E>(
|
|
||||||
result: Self::ExtensionResult<A0, E>,
|
|
||||||
f: impl FnOnce(A0) -> Result<A1, E>,
|
|
||||||
) -> Self::ExtensionResult<A1, E> {
|
|
||||||
result.and_then(f)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn xseal<A, E>(result: Self::ExtensionResult<A, E>) -> Result<A, E> {
|
|
||||||
result
|
|
||||||
}
|
|
||||||
|
|
||||||
fn smap<A0, A1>(
|
|
||||||
source: Self::ExtensionSource<A0>,
|
|
||||||
f: impl FnOnce(A0) -> A1,
|
|
||||||
) -> Self::ExtensionSource<A1> {
|
|
||||||
f(source)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn prepare<A>(a: A) -> Self::ExtensionSource<A> {
|
|
||||||
a
|
|
||||||
}
|
|
||||||
|
|
||||||
fn xsbind<AB, A, B, E>(
|
|
||||||
ab: Self::ExtensionSource<AB>,
|
|
||||||
t2ab: impl FnOnce(AB) -> (A, B),
|
|
||||||
ce: impl FnOnce(Self::ExtensionSource<B>) -> Self::ExtensionResult<B, E>,
|
|
||||||
ab2t: impl FnOnce(A, B) -> Result<AB, E>,
|
|
||||||
) -> Self::ExtensionResult<AB, E> {
|
|
||||||
let (b, c) = t2ab(ab);
|
|
||||||
ab2t(b, ce(c)?)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// For auto-deriving [`RegularFactory`] from concrete implementations.
|
/// For auto-deriving [`RegularFactory`] from concrete implementations.
|
||||||
pub trait CRegularFactory<'a, Ctx: Context<'a>>:
|
pub trait CRegularFactory<'a, Ctx: Context<'a>>:
|
||||||
FactoryBase<'a, Ctx> + ImplMode<Mode = RegularMode>
|
FactoryBase<'a, Ctx> + ImplMode<Mode = RegularMode>
|
||||||
|
Loading…
Reference in New Issue
Block a user