mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2025-12-06 11:46:42 +01:00
parent
31e84bf5b3
commit
f1b24d436a
20 changed files with 1081 additions and 1103 deletions
|
|
@ -43,50 +43,38 @@ impl ToTokens for ViewDef {
|
|||
let self_ty = &block.self_ty;
|
||||
// Expressions are handled by built-in functions
|
||||
// that operate over constants and symbols.
|
||||
let builtin = builtins_with_boxes_output(quote! { #output });
|
||||
let builtin = builtins_with_boxes_output(quote! { #output }).map(|builtin|quote! {
|
||||
::tengri::dsl::Value::Exp(_, expr) => return Ok(Some(
|
||||
#builtin::take_or_fail(state, expr, ||"failed to load builtin")?.boxed()
|
||||
)),
|
||||
});
|
||||
// Symbols are handled by user-taked functions
|
||||
// that take no parameters but `&self`.
|
||||
let exposed = exposed.iter().map(|(key, value)|write_quote(quote! {
|
||||
::tengri::dsl::Value::Sym(#key) => Some(Box::new(Thunk::new(
|
||||
move||#self_ty::#value(state))))}));
|
||||
::tengri::dsl::Value::Sym(#key) => return Ok(Some(
|
||||
state.#value().boxed()
|
||||
)),
|
||||
}));
|
||||
write_quote_to(out, quote! {
|
||||
// Original user-taked implementation:
|
||||
#block
|
||||
/// Generated by [tengri_proc].
|
||||
///
|
||||
/// Makes [#self_ty] able to construct the [Render]able
|
||||
/// which might correspond to a given [TokenStream],
|
||||
/// while taking [#self_ty]'s state into consideration.
|
||||
impl<'state: 'static> Take<'state, #self_ty> for Box<dyn Render<#output> + 'state> {
|
||||
fn take <'source: 'state> (state: &#self_ty, mut words: TokenIter<'source>)
|
||||
-> Perhaps<Box<dyn Render<#output> + 'state>>
|
||||
{
|
||||
//let state = self;
|
||||
impl<'source, 'state: 'source>
|
||||
Take<'state, 'source, #self_ty>
|
||||
for Box<dyn Render<#output> + 'state>
|
||||
{
|
||||
fn take (state: &'state #self_ty, mut words: Cst<'source>) -> Perhaps<Self> {
|
||||
Ok(if let Some(::tengri::dsl::Token { value, .. }) = words.peek() {
|
||||
match value {
|
||||
#(::tengri::dsl::Value::Exp(_, expr) => {
|
||||
Give::<'state, #builtin>::give(state, expr)?.map(|value|value.boxed())
|
||||
},)*
|
||||
#(
|
||||
#exposed,
|
||||
)*
|
||||
_ => None
|
||||
}
|
||||
match value { #(#builtin)* #(#exposed)* _ => None }
|
||||
} else {
|
||||
None
|
||||
})
|
||||
}
|
||||
}
|
||||
/// 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-taked implementation:
|
||||
#block
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
@ -96,11 +84,11 @@ fn builtins_with_holes () -> impl Iterator<Item=TokenStream2> {
|
|||
}
|
||||
|
||||
fn builtins_with_boxes () -> impl Iterator<Item=TokenStream2> {
|
||||
builtins_with(quote! { _ }, quote! { Box<dyn Render<_>+'state> })
|
||||
builtins_with(quote! { _ }, quote! { Box<dyn Render<_>> })
|
||||
}
|
||||
|
||||
fn builtins_with_boxes_output (o: TokenStream2) -> impl Iterator<Item=TokenStream2> {
|
||||
builtins_with(quote! { _ }, quote! { Box<dyn Render<#o>+'state> })
|
||||
builtins_with(quote! { _ }, quote! { Box<dyn Render<#o>> })
|
||||
}
|
||||
|
||||
fn builtins_with (n: TokenStream2, c: TokenStream2) -> impl Iterator<Item=TokenStream2> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue