mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2025-12-06 19:56:44 +01:00
FromDsl -> Namespace
This commit is contained in:
parent
455d6d00d5
commit
f714302f21
8 changed files with 33 additions and 32 deletions
|
|
@ -1,6 +1,6 @@
|
|||
use crate::*;
|
||||
|
||||
pub trait Dsl<Other>: Sized {
|
||||
pub trait Dsl<Other> {
|
||||
fn take <'state, 'source: 'state> (
|
||||
&'state self,
|
||||
token: &mut TokenIter<'source>
|
||||
|
|
@ -18,7 +18,7 @@ pub trait Dsl<Other>: Sized {
|
|||
}
|
||||
}
|
||||
}
|
||||
pub trait FromDsl<'source, State>: Sized {
|
||||
pub trait Namespace<'source, State>: Sized {
|
||||
fn take_from <'state> (state: &'state State, token: &mut TokenIter<'source>)
|
||||
-> Perhaps<Self>;
|
||||
fn take_from_or_fail <'state> (
|
||||
|
|
@ -26,14 +26,14 @@ pub trait FromDsl<'source, State>: Sized {
|
|||
token: &mut TokenIter<'source>,
|
||||
error: impl Into<Box<dyn std::error::Error>>
|
||||
) -> Usually<Self> {
|
||||
if let Some(value) = FromDsl::<State>::take_from(state, token)? {
|
||||
if let Some(value) = Namespace::<State>::take_from(state, token)? {
|
||||
Ok(value)
|
||||
} else {
|
||||
Result::Err(error.into())
|
||||
}
|
||||
}
|
||||
}
|
||||
//impl<State: Dsl<T>, T> FromDsl<State> for T {
|
||||
//impl<State: Dsl<T>, T> Namespace<State> for T {
|
||||
//fn take_from <'state, 'source: 'state> (state: &'state State, token: &mut TokenIter<'source>)
|
||||
//-> Perhaps<Self>
|
||||
//{
|
||||
|
|
@ -45,7 +45,7 @@ pub trait FromDsl<'source, State>: Sized {
|
|||
/// specifying two types and providing an expression.
|
||||
#[macro_export] macro_rules! from_dsl {
|
||||
(@a: $T:ty: |$state:ident, $words:ident|$expr:expr) => {
|
||||
impl<'source, State: Dsl<A>, A> FromDsl<'source, State> for $T {
|
||||
impl<'source, State: Dsl<A>, A> Namespace<'source, State> for $T {
|
||||
fn take_from <'state> (
|
||||
$state: &'state State,
|
||||
$words: &mut TokenIter<'source>,
|
||||
|
|
@ -55,7 +55,7 @@ pub trait FromDsl<'source, State>: Sized {
|
|||
}
|
||||
};
|
||||
(@ab: $T:ty: |$state:ident, $words:ident|$expr:expr) => {
|
||||
impl<'source, State: Dsl<A> + Dsl<B>, A, B> FromDsl<'source, State> for $T {
|
||||
impl<'source, State: Dsl<A> + Dsl<B>, A, B> Namespace<'source, State> for $T {
|
||||
fn take_from <'state> (
|
||||
$state: &'state State,
|
||||
$words: &mut TokenIter<'source>,
|
||||
|
|
@ -65,7 +65,7 @@ pub trait FromDsl<'source, State>: Sized {
|
|||
}
|
||||
};
|
||||
($T:ty: |$state:ident:$S:ty, $words:ident|$expr:expr) => {
|
||||
impl<'source> FromDsl<'source, $S> for $T {
|
||||
impl<'source> Namespace<'source, $S> for $T {
|
||||
fn take_from <'state> (
|
||||
$state: &'state $S,
|
||||
$words: &mut TokenIter<'source>,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue