move Mode to mode
				
					
				
			This commit is contained in:
		
							parent
							
								
									fa3151518d
								
							
						
					
					
						commit
						c91e34b04a
					
				
							
								
								
									
										105
									
								
								src/mode.rs
									
									
									
									
									
								
							
							
						
						
									
										105
									
								
								src/mode.rs
									
									
									
									
									
								
							| @ -0,0 +1,105 @@ | ||||
| /// See [`ModeResult`].
 | ||||
| pub type ParseSuccess<M, A, I> = <M as Mode>::ParseSuccess<A, I>; | ||||
| 
 | ||||
| /// [`Mode`] equivalent of [`ParseResult`] for extension.
 | ||||
| ///
 | ||||
| /// [`ParseResult`]: crate::rcore::ParseResult
 | ||||
| pub type ExtensionResult<M, A, E> = <M as Mode>::ExtensionResult<A, E>; | ||||
| 
 | ||||
| /// See [`Mode::prepare`].
 | ||||
| pub type ExtensionSource<M, A> = <M as Mode>::ExtensionSource<A>; | ||||
| 
 | ||||
| /// [`Mode`] equivalent of [`ParseResult`].
 | ||||
| ///
 | ||||
| /// [`ParseResult`]: crate::rcore::ParseResult
 | ||||
| pub type ModeResult<M, A, E, I> = Result<ParseSuccess<M, A, I>, E>; | ||||
| 
 | ||||
| /// Mode of parsing.
 | ||||
| ///
 | ||||
| /// | [`Mode`]         | [`Mode::ParseSuccess<A, I>`] | [`Mode::ExtensionResult<A, E>`] | [`Mode::ExtensionSource<A>`] |
 | ||||
| /// |------------------|------------------------------|---------------------------------|------------------------------|
 | ||||
| /// | [`RegularMode`]  | `A`                          | [`Result<A, E>`]                | `A`                          |
 | ||||
| /// | [`InliningMode`] | [`(A, I)`]                   | `E`                             | [`()`]                       |
 | ||||
| ///
 | ||||
| /// [`RegularMode`]: crate::rcore::RegularMode
 | ||||
| /// [`InliningMode`]: crate::rstd::inlining::InliningMode
 | ||||
| /// [`(A, I)`]: tuple
 | ||||
| /// [`()`]: unit
 | ||||
| pub trait Mode { | ||||
|     /// Successful parsing, may countain the parser itself
 | ||||
|     /// (`I`, usually [`Inlining`]).
 | ||||
|     ///
 | ||||
|     /// [`Inlining`]: crate::rcore::Inlining
 | ||||
|     type ParseSuccess<A, I>; | ||||
| 
 | ||||
|     /// Result of extending the value, failing sometimes or always.
 | ||||
|     type ExtensionResult<A, E>; | ||||
| 
 | ||||
|     /// Data enough to try extending the value.
 | ||||
|     ///
 | ||||
|     /// May be empty for always-failing extensions.
 | ||||
|     type ExtensionSource<A>; | ||||
| 
 | ||||
|     /// Do something with the successfully parsed value, potentially failing.
 | ||||
|     ///
 | ||||
|     /// Useful for for wrappers and chaining parsing after [`InliningFactory`].
 | ||||
|     ///
 | ||||
|     /// See also [`Mode::map`]
 | ||||
|     ///
 | ||||
|     /// [`InliningFactory`]: crate::rstd::inlining::InliningFactory
 | ||||
|     fn bind<A0, A1, E, I>( | ||||
|         s: Self::ParseSuccess<A0, I>, | ||||
|         f: impl FnOnce(A0) -> Result<A1, E>, | ||||
|     ) -> ModeResult<Self, A1, E, I>; | ||||
| 
 | ||||
|     /// Map the successfully parsed value.
 | ||||
|     ///
 | ||||
|     /// Useful for for wrappers.
 | ||||
|     ///
 | ||||
|     /// See also [`Mode::bind`]
 | ||||
|     fn map<A0, A1, I>( | ||||
|         s: Self::ParseSuccess<A0, I>, | ||||
|         f: impl FnOnce(A0) -> A1, | ||||
|     ) -> Self::ParseSuccess<A1, I>; | ||||
| 
 | ||||
|     /// Discard any extra information contained in [`Mode::ParseSuccess`].
 | ||||
|     fn seal<A, I>(s: Self::ParseSuccess<A, I>) -> A; | ||||
| 
 | ||||
|     /// Map the error of an extension result.
 | ||||
|     ///
 | ||||
|     /// Useful for for wrappers and chaining parsing after [`InliningFactory`].
 | ||||
|     ///
 | ||||
|     /// [`InliningFactory`]: crate::rstd::inlining::InliningFactory
 | ||||
|     fn xmap_err<A, E0, E1>( | ||||
|         result: Self::ExtensionResult<A, E0>, | ||||
|         f: impl FnOnce(E0) -> E1, | ||||
|     ) -> Self::ExtensionResult<A, E1>; | ||||
| 
 | ||||
|     /// Do something with the extension result, potentially failing.
 | ||||
|     ///
 | ||||
|     /// Useful for wrappers and chaining extension after [`InliningFactory`].
 | ||||
|     ///
 | ||||
|     /// [`InliningFactory`]: crate::rstd::inlining::InliningFactory
 | ||||
|     fn xbind<A0, A1, E>( | ||||
|         result: Self::ExtensionResult<A0, E>, | ||||
|         f: impl FnOnce(A0) -> Result<A1, E>, | ||||
|     ) -> Self::ExtensionResult<A1, E>; | ||||
| 
 | ||||
|     /// Convert [`Mode::ExtensionResult`] to [`Result`].
 | ||||
|     fn xseal<A, E>(result: Self::ExtensionResult<A, E>) -> Result<A, E>; | ||||
| 
 | ||||
|     fn smap<A0, A1>( | ||||
|         source: Self::ExtensionSource<A0>, | ||||
|         f: impl FnOnce(A0) -> A1, | ||||
|     ) -> Self::ExtensionSource<A1>; | ||||
| 
 | ||||
|     fn prepare<A>(a: A) -> Self::ExtensionSource<A>; | ||||
| 
 | ||||
|     /// For abstract extension implementations.
 | ||||
|     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>; | ||||
| } | ||||
| @ -33,10 +33,9 @@ pub use self::hashing::{Hash, HASH_SIZE, HASH_ZEROS}; | ||||
| pub use self::inctx::InCtx; | ||||
| pub use self::inlining::{Inlining, InliningExt, InliningResultExt}; | ||||
| pub use self::modes::{ | ||||
|     CRegularFactory, ExtensionResult, ExtensionResultM, ExtensionResultP, ExtensionSource, | ||||
|     ExtensionSourceM, ExtensionSourceP, FactoryModeParse, FactoryModeProxy, ImplMode, Mode, | ||||
|     ModeResult, ModeResultM, ModeResultP, ParseMode, ParseModeExt, ParseSuccess, ParseSuccessP, | ||||
|     RegularFactory, RegularMode, WithMode, WithParseMode, | ||||
|     CRegularFactory, ExtensionResultM, ExtensionResultP, ExtensionSourceM, ExtensionSourceP, | ||||
|     FactoryModeParse, FactoryModeProxy, ImplMode, ModeResultM, ModeResultP, ParseMode, | ||||
|     ParseModeExt, ParseSuccessP, RegularFactory, RegularMode, WithMode, WithParseMode, | ||||
| }; | ||||
| pub use self::origin::{OFctr, Origin}; | ||||
| pub use self::point::Point; | ||||
|  | ||||
| @ -1,112 +1,9 @@ | ||||
| use std::marker::PhantomData; | ||||
| 
 | ||||
| use crate::mode::*; | ||||
| 
 | ||||
| use super::*; | ||||
| 
 | ||||
| /// See [`ModeResult`].
 | ||||
| pub type ParseSuccess<M, A, I> = <M as Mode>::ParseSuccess<A, I>; | ||||
| 
 | ||||
| /// [`Mode`] equivalent of [`ParseResult`] for extension.
 | ||||
| pub type ExtensionResult<M, A, E> = <M as Mode>::ExtensionResult<A, E>; | ||||
| 
 | ||||
| /// See [`Mode::prepare`].
 | ||||
| pub type ExtensionSource<M, A> = <M as Mode>::ExtensionSource<A>; | ||||
| 
 | ||||
| /// [`Mode`] equivalent of [`ParseResult`].
 | ||||
| pub type ModeResult<M, A, E, I> = Result<ParseSuccess<M, A, I>, E>; | ||||
| 
 | ||||
| /// Mode of parsing.
 | ||||
| ///
 | ||||
| /// | [`Mode`]         | [`Mode::ParseSuccess<A, I>`] | [`Mode::ExtensionResult<A, E>`] | [`Mode::ExtensionSource<A>`] |
 | ||||
| /// |------------------|------------------------------|---------------------------------|------------------------------|
 | ||||
| /// | [`RegularMode`]  | `A`                          | [`Result<A, E>`]                | `A`                          |
 | ||||
| /// | [`InliningMode`] | [`(A, I)`]                   | `E`                             | [`()`]                       |
 | ||||
| ///
 | ||||
| /// [`InliningMode`]: crate::rstd::inlining::InliningMode
 | ||||
| /// [`(A, I)`]: tuple
 | ||||
| /// [`()`]: unit
 | ||||
| pub trait Mode { | ||||
|     /// Successful parsing, may countain the parser itself
 | ||||
|     /// (`I`, usually [`Inlining`]).
 | ||||
|     ///
 | ||||
|     /// See [`FactoryParse::deserialize`].
 | ||||
|     type ParseSuccess<A, I>; | ||||
| 
 | ||||
|     /// Result of extending the value, failing sometimes or always.
 | ||||
|     ///
 | ||||
|     /// See [`FactoryParse::extend`].
 | ||||
|     type ExtensionResult<A, E>; | ||||
| 
 | ||||
|     /// Data enough to try extending the value.
 | ||||
|     ///
 | ||||
|     /// May be empty for always-failing extensions.
 | ||||
|     ///
 | ||||
|     /// See [`FactoryParse::extend`].
 | ||||
|     type ExtensionSource<A>; | ||||
| 
 | ||||
|     /// Do something with the successfully parsed value, potentially failing.
 | ||||
|     ///
 | ||||
|     /// Useful for for wrappers and chaining parsing after [`InliningFactory`].
 | ||||
|     ///
 | ||||
|     /// See also [`Mode::map`]
 | ||||
|     ///
 | ||||
|     /// [`InliningFactory`]: crate::rstd::inlining::InliningFactory
 | ||||
|     fn bind<A0, A1, E, I>( | ||||
|         s: Self::ParseSuccess<A0, I>, | ||||
|         f: impl FnOnce(A0) -> Result<A1, E>, | ||||
|     ) -> ModeResult<Self, A1, E, I>; | ||||
| 
 | ||||
|     /// Map the successfully parsed value.
 | ||||
|     ///
 | ||||
|     /// Useful for for wrappers.
 | ||||
|     ///
 | ||||
|     /// See also [`Mode::bind`]
 | ||||
|     fn map<A0, A1, I>( | ||||
|         s: Self::ParseSuccess<A0, I>, | ||||
|         f: impl FnOnce(A0) -> A1, | ||||
|     ) -> Self::ParseSuccess<A1, I>; | ||||
| 
 | ||||
|     /// Discard any extra information contained in [`Mode::ParseSuccess`].
 | ||||
|     fn seal<A, I>(s: Self::ParseSuccess<A, I>) -> A; | ||||
| 
 | ||||
|     /// Map the error of an extension result.
 | ||||
|     ///
 | ||||
|     /// Useful for for wrappers and chaining parsing after [`InliningFactory`].
 | ||||
|     ///
 | ||||
|     /// [`InliningFactory`]: crate::rstd::inlining::InliningFactory
 | ||||
|     fn xmap_err<A, E0, E1>( | ||||
|         result: Self::ExtensionResult<A, E0>, | ||||
|         f: impl FnOnce(E0) -> E1, | ||||
|     ) -> Self::ExtensionResult<A, E1>; | ||||
| 
 | ||||
|     /// Do something with the extension result, potentially failing.
 | ||||
|     ///
 | ||||
|     /// Useful for wrappers and chaining extension after [`InliningFactory`].
 | ||||
|     ///
 | ||||
|     /// [`InliningFactory`]: crate::rstd::inlining::InliningFactory
 | ||||
|     fn xbind<A0, A1, E>( | ||||
|         result: Self::ExtensionResult<A0, E>, | ||||
|         f: impl FnOnce(A0) -> Result<A1, E>, | ||||
|     ) -> Self::ExtensionResult<A1, E>; | ||||
| 
 | ||||
|     /// Convert [`Mode::ExtensionResult`] to [`Result`].
 | ||||
|     fn xseal<A, E>(result: Self::ExtensionResult<A, E>) -> Result<A, E>; | ||||
| 
 | ||||
|     fn smap<A0, A1>( | ||||
|         source: Self::ExtensionSource<A0>, | ||||
|         f: impl FnOnce(A0) -> A1, | ||||
|     ) -> Self::ExtensionSource<A1>; | ||||
| 
 | ||||
|     fn prepare<A>(a: A) -> Self::ExtensionSource<A>; | ||||
| 
 | ||||
|     /// For abstract [`FactoryParse::extend`] implementations.
 | ||||
|     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>; | ||||
| } | ||||
| 
 | ||||
| /// Type that a [`Mode`] associated with it.
 | ||||
| pub trait ParseMode { | ||||
|     /// Associated [`Mode`].
 | ||||
|  | ||||
| @ -1,3 +1,6 @@ | ||||
| #[cfg(doc)] | ||||
| use crate::mode::*; | ||||
| 
 | ||||
| use super::*; | ||||
| 
 | ||||
| impl<A: AtomicModeParse> Atomic for A { | ||||
|  | ||||
| @ -1,3 +1,5 @@ | ||||
| use crate::mode::*; | ||||
| 
 | ||||
| use super::*; | ||||
| 
 | ||||
| /// [`Mode`] for [`InliningFactory`].
 | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user