read explicit lifetime to FromDsl
Some checks are pending
/ build (push) Waiting to run

This commit is contained in:
🪞👃🪞 2025-05-20 22:02:51 +03:00
parent 7c1cddc759
commit 455d6d00d5
14 changed files with 252 additions and 286 deletions

View file

@ -18,10 +18,10 @@ pub trait Dsl<Other>: Sized {
}
}
}
pub trait FromDsl<State>: Sized {
fn take_from <'state, 'source: 'state> (state: &'state State, token: &mut TokenIter<'source>)
pub trait FromDsl<'source, State>: Sized {
fn take_from <'state> (state: &'state State, token: &mut TokenIter<'source>)
-> Perhaps<Self>;
fn take_from_or_fail <'state, 'source: 'state> (
fn take_from_or_fail <'state> (
state: &'state State,
token: &mut TokenIter<'source>,
error: impl Into<Box<dyn std::error::Error>>
@ -33,13 +33,6 @@ pub trait FromDsl<State>: Sized {
}
}
}
impl<T: FromDsl<State>, State> Dsl<T> for State {
fn take <'state, 'source: 'state> (&'state self, token: &mut TokenIter<'source>)
-> Perhaps<T>
{
FromDsl::take_from(self, token)
}
}
//impl<State: Dsl<T>, T> FromDsl<State> for T {
//fn take_from <'state, 'source: 'state> (state: &'state State, token: &mut TokenIter<'source>)
//-> Perhaps<Self>
@ -51,16 +44,36 @@ impl<T: FromDsl<State>, State> Dsl<T> for State {
/// Implement the [Dsl] trait, which boils down to
/// specifying two types and providing an expression.
#[macro_export] macro_rules! from_dsl {
($T:ty: |$state:ident:$S:ty, $words:ident|$expr:expr) => {
impl ::tengri::dsl::FromDsl<$S> for $T {
fn take_from <'state, 'source: 'state> (
$state: &'state $S,
$words: &mut ::tengri::dsl::TokenIter<'source>,
) -> ::tengri::Perhaps<$T> {
(@a: $T:ty: |$state:ident, $words:ident|$expr:expr) => {
impl<'source, State: Dsl<A>, A> FromDsl<'source, State> for $T {
fn take_from <'state> (
$state: &'state State,
$words: &mut TokenIter<'source>,
) -> Perhaps<$T> {
$expr
}
}
}
};
(@ab: $T:ty: |$state:ident, $words:ident|$expr:expr) => {
impl<'source, State: Dsl<A> + Dsl<B>, A, B> FromDsl<'source, State> for $T {
fn take_from <'state> (
$state: &'state State,
$words: &mut TokenIter<'source>,
) -> Perhaps<$T> {
$expr
}
}
};
($T:ty: |$state:ident:$S:ty, $words:ident|$expr:expr) => {
impl<'source> FromDsl<'source, $S> for $T {
fn take_from <'state> (
$state: &'state $S,
$words: &mut TokenIter<'source>,
) -> Perhaps<$T> {
$expr
}
}
};
}
///// Maps a sequencer of EDN tokens to parameters of supported types