wip: dsl, output, input, proc, tui: sorting out give and take
Some checks are pending
/ build (push) Waiting to run

This commit is contained in:
🪞👃🪞 2025-05-24 23:57:12 +03:00
parent 5a2177cc77
commit 3e1084555b
10 changed files with 273 additions and 301 deletions

View file

@ -43,52 +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 builtins: Vec<_> = builtins_with_types().iter().map(|ty|write_quote(quote! {
::tengri::dsl::Value::Exp(_, expr) => {
Give::<#ty>::give(&mut expr.clone()).map(|value|value.boxed())
},
})).collect();
let builtin = builtins_with_types().map(|ty|write_quote(quote! { #ty }));
// Symbols are handled by user-taked functions
// that take no parameters but `&self`.
let exposed: Vec<_> = exposed.iter().map(|(key, value)|write_quote(quote! {
::tengri::dsl::Value::Sym(#key) => {
Some(Box::new(Thunk::new(move||#self_ty::#value(self))))
},
})).collect();
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))))}));
write_quote_to(out, quote! {
/// 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.
give!(Box<dyn Render<#output>>|state:#self_ty, words|Ok(None));
//impl <'n, State: ::tengri::dsl::Give<Box<dyn Render<#output>>>>
//Take<'n, Box<dyn Render<#output>> for #self_ty
//{
//fn give <'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
//// that operate over constants and symbols.
//::tengri::dsl::Value::Exp(_, exp) => {
//#(#builtins)*
//None
//},
//// Symbols are handled by user-taked functions
//// that take no parameters but `&self`.
//::tengri::dsl::Value::Sym(sym) => match sym {
//#(#exposed)*
//_ => None
//},
//_ => None
//}
//} else {
//None
//})
//}
//}
impl<'state> Give<'state, Box<dyn Render<#output> + 'state>> for #self_ty {
fn give <'source: 'state> (&self, mut words: TokenIter<'source>)
-> Perhaps<Box<dyn Render<#output> + 'state>>
{
let state = self;
Ok(if let Some(::tengri::dsl::Token { value, .. }) = words.peek() {
match value {
#(::tengri::dsl::Value::Exp(_, expr) => {
#builtin::take(state, expr)?.map(|value|value.boxed())
},)*
#(
#exposed,
)*
_ => None
}
} else {
None
})
}
}
/// Generated by [tengri_proc].
///
/// Delegates the rendering of [#self_ty] to the [#self_ty::view} method,
@ -105,21 +91,21 @@ impl ToTokens for ViewDef {
}
}
fn builtins_with_types () -> [TokenStream2;14] {
fn builtins_with_types () -> impl Iterator<Item=TokenStream2> {
[
quote! { When< Box<dyn Render<_> + '_> > },
quote! { Either< Box<dyn Render<_> + '_>, Box<dyn Render<_> + '_>> },
quote! { Align< Box<dyn Render<_> + '_> > },
quote! { Bsp< Box<dyn Render<_> + '_>, Box<dyn Render<_> + '_>> },
quote! { Fill< Box<dyn Render<_> + '_> > },
quote! { Fixed<_, Box<dyn Render<_> + '_> > },
quote! { Min<_, Box<dyn Render<_> + '_> > },
quote! { Max<_, Box<dyn Render<_> + '_> > },
quote! { Shrink<_, Box<dyn Render<_> + '_> > },
quote! { Expand<_, Box<dyn Render<_> + '_> > },
quote! { Push<_, Box<dyn Render<_> + '_> > },
quote! { Pull<_, Box<dyn Render<_> + '_> > },
quote! { Margin<_, Box<dyn Render<_> + '_> > },
quote! { Padding<_, Box<dyn Render<_> + '_> > },
]
quote! { When::< Box<dyn Render<_>> > },
quote! { Either::< Box<dyn Render<_>>, Box<dyn Render<_>>> },
quote! { Align::< Box<dyn Render<_>> > },
quote! { Bsp::< Box<dyn Render<_>>, Box<dyn Render<_>>> },
quote! { Fill::< Box<dyn Render<_>> > },
quote! { Fixed::<_, Box<dyn Render<_>> > },
quote! { Min::<_, Box<dyn Render<_>> > },
quote! { Max::<_, Box<dyn Render<_>> > },
quote! { Shrink::<_, Box<dyn Render<_>> > },
quote! { Expand::<_, Box<dyn Render<_>> > },
quote! { Push::<_, Box<dyn Render<_>> > },
quote! { Pull::<_, Box<dyn Render<_>> > },
quote! { Margin::<_, Box<dyn Render<_>> > },
quote! { Padding::<_, Box<dyn Render<_>> > },
].into_iter()
}