wip: finally, informative type errors from the macro
Some checks failed
/ build (push) Has been cancelled

fixin mixin
This commit is contained in:
🪞👃🪞 2025-05-21 15:54:25 +03:00
parent abc87d3234
commit 583660c330
10 changed files with 152 additions and 205 deletions

View file

@ -46,7 +46,7 @@ impl ToTokens for ViewDef {
let builtins: Vec<_> = builtins_with_types()
.iter()
.map(|ty|write_quote(quote! {
let value: Option<#ty> = Dsl::take(state, &mut exp.clone())?;
let value: Option<#ty> = Receive::<#ty>::receive(self, &mut exp.clone())?;
if let Some(value) = value {
return Ok(Some(value.boxed()))
}
@ -55,30 +55,20 @@ impl ToTokens for ViewDef {
let exposed: Vec<_> = exposed
.iter()
.map(|(key, value)|write_quote(quote! {
#key => Some(#self_ty::#value(state).boxed()),
#key => {
Some(Box::new(Thunk::new(move||#self_ty::#value(self))))//Box::new("todo"))
},
})).collect();
write_quote_to(out, quote! {
#block
/// Generated by [tengri_proc].
///
/// Delegates the rendering of [#self_ty] to the [#self_ty::view} method,
/// which you will need to implement, e.g. passing a [TokenIter]
/// containing a layout and keybindings config from user dirs.
impl ::tengri::output::Content<#output> for #self_ty {
fn content (&self) -> impl Render<#output> {
#self_ty::view(self)
}
}
/// Generated by [tengri_proc].
///
/// Gives [#self_ty] the ability to construct the [Render]able
/// which might corresponds to a given [TokenStream],
/// while taking [#self_ty]'s state into consideration.
impl ::tengri::dsl::Namespace<#self_ty> for Box<dyn Render<#output> + '_> {
fn take_from <'source> (
state: &#self_ty,
words: &mut ::tengri::dsl::TokenIter<'source>
) -> Perhaps<Self> {
impl ::tengri::dsl::Receive<Box<dyn Render<#output>>> for #self_ty {
fn receive <'source> (&self, words: &mut ::tengri::dsl::TokenIter<'source>)
-> Perhaps<Box<dyn Render<#output>>>
{
Ok(if let Some(::tengri::dsl::Token { value, .. }) = words.peek() {
match value {
// Expressions are handled by built-in functions
@ -100,6 +90,18 @@ impl ToTokens for ViewDef {
})
}
}
/// Generated by [tengri_proc].
///
/// Delegates the rendering of [#self_ty] to the [#self_ty::view} method,
/// which you will need to implement, e.g. passing a [TokenIter]
/// containing a layout and keybindings config from user dirs.
impl ::tengri::output::Content<#output> for #self_ty {
fn content (&self) -> impl Render<#output> + '_ {
#self_ty::view(self)
}
}
// Original user-provided implementation:
#block
})
}
}