mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2025-12-06 19:56:44 +01:00
This commit is contained in:
parent
7c1cddc759
commit
455d6d00d5
14 changed files with 252 additions and 286 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue