edn -> dsl

This commit is contained in:
🪞👃🪞 2025-03-14 23:44:13 +02:00
parent d30eda33d1
commit 877b344765
35 changed files with 197 additions and 225 deletions

View file

@ -1,4 +1,5 @@
use crate::*;
#[macro_export] macro_rules! view {
($Output:ty: |$self:ident: $State:ty| $expr:expr; {
$($sym:literal => $body:expr),* $(,)?
@ -23,7 +24,10 @@ use crate::*;
// An ephemeral wrapper around view state and view description,
// that is meant to be constructed and returned from [Content::content].
#[cfg(feature = "dsl")]
pub struct View<'a, T>(pub &'a T, pub SourceIter<'a>);
#[cfg(feature = "dsl")]
impl<'a, O: Output + 'a, T: ViewContext<'a, O>> Content<O> for View<'a, T> {
fn content (&self) -> impl Render<O> {
let iter = self.1.clone();
@ -35,7 +39,9 @@ impl<'a, O: Output + 'a, T: ViewContext<'a, O>> Content<O> for View<'a, T> {
return None
}
}
// Provides components to the view.
#[cfg(feature = "dsl")]
pub trait ViewContext<'a, E: Output + 'a>: Send + Sync
+ Context<bool>
+ Context<usize>
@ -67,6 +73,8 @@ pub trait ViewContext<'a, E: Output + 'a>: Send + Sync
None
}
}
#[cfg(feature = "dsl")]
#[macro_export] macro_rules! try_delegate {
($s:ident, $atom:expr, $T:ty) => {
if let Some(value) = <$T>::try_from_atom($s, $atom) {
@ -74,6 +82,8 @@ pub trait ViewContext<'a, E: Output + 'a>: Send + Sync
}
}
}
#[cfg(feature = "dsl")]
#[macro_export] macro_rules! try_from_expr {
(<$l:lifetime, $E:ident>: $Struct:ty: |$state:ident, $iter:ident|$body:expr) => {
impl<$l, $E: Output + $l, T: ViewContext<$l, $E>> TryFromAtom<$l, T> for $Struct {