mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2025-12-06 11:46:42 +01:00
parent
4a385b40ff
commit
cb8fd26922
8 changed files with 234 additions and 257 deletions
190
proc/src/lib.rs
190
proc/src/lib.rs
|
|
@ -21,14 +21,7 @@ mod proc_view;
|
|||
mod proc_expose;
|
||||
mod proc_command;
|
||||
|
||||
#[proc_macro_attribute]
|
||||
pub fn view (meta: TokenStream, item: TokenStream) -> TokenStream {
|
||||
use self::proc_view::{ViewDef, ViewMeta, ViewImpl};
|
||||
write(ViewDef(
|
||||
parse_macro_input!(meta as ViewMeta),
|
||||
parse_macro_input!(item as ViewImpl),
|
||||
))
|
||||
}
|
||||
#[cfg(test)] use syn::parse_quote as pq;
|
||||
|
||||
#[proc_macro_attribute]
|
||||
pub fn expose (meta: TokenStream, item: TokenStream) -> TokenStream {
|
||||
|
|
@ -48,6 +41,15 @@ pub fn command (meta: TokenStream, item: TokenStream) -> TokenStream {
|
|||
))
|
||||
}
|
||||
|
||||
#[proc_macro_attribute]
|
||||
pub fn view (meta: TokenStream, item: TokenStream) -> TokenStream {
|
||||
use self::proc_view::{ViewDef, ViewMeta, ViewImpl};
|
||||
write(ViewDef(
|
||||
parse_macro_input!(meta as ViewMeta),
|
||||
parse_macro_input!(item as ViewImpl),
|
||||
))
|
||||
}
|
||||
|
||||
pub(crate) fn write <T: ToTokens> (t: T) -> TokenStream {
|
||||
let mut out = TokenStream2::new();
|
||||
t.to_tokens(&mut out);
|
||||
|
|
@ -67,3 +69,175 @@ pub(crate) fn write_quote_to (out: &mut TokenStream2, quote: TokenStream2) {
|
|||
out.append(token);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)] #[test] fn test_proc_view () {
|
||||
let x: crate::proc_view::ViewMeta = pq! { SomeOutput };
|
||||
let output: Ident = pq! { SomeOutput };
|
||||
assert_eq!(x.output, output);
|
||||
|
||||
// TODO
|
||||
let x: crate::proc_view::ViewImpl = pq! {
|
||||
impl Foo {
|
||||
/// docstring1
|
||||
#[tengri::view(":view1")] #[bar] fn a_view () {}
|
||||
|
||||
#[baz]
|
||||
/// docstring2
|
||||
#[baz] fn is_not_view () {}
|
||||
}
|
||||
};
|
||||
let expected_target: Ident = pq! { Foo };
|
||||
//assert_eq!(x.target, expected_target);
|
||||
//assert_eq!(x.items.len(), 2);
|
||||
//assert_eq!(x.items[0].item, pq! {
|
||||
///// docstring1
|
||||
//#[bar] fn a_view () {}
|
||||
//});
|
||||
//assert_eq!(x.items[1].item, pq! {
|
||||
//#[baz]
|
||||
///// docstring2
|
||||
//#[baz] fn is_not_view () {}
|
||||
//});
|
||||
//assert_eq!(x.syms, vec![
|
||||
//ViewArm( { symbol: pq! { ":view1" }, name: pq! { a_view }, },
|
||||
//]);
|
||||
// FIXME
|
||||
//let parsed: ViewDefinition = pq! {
|
||||
//#[tengri_proc::view(SomeOutput)]
|
||||
//impl SomeView {
|
||||
//#[tengri::view(":view-1")]
|
||||
//fn view_1 (&self) -> impl Content<SomeOutput> + use<'_> {
|
||||
//"view-1"
|
||||
//}
|
||||
//}
|
||||
//};
|
||||
//let written = quote! { #parsed };
|
||||
//assert_eq!(format!("{written}"), format!("{}", quote! {
|
||||
//impl SomeView {
|
||||
//fn view_1 (&self) -> impl Content<SomeOutput> + use<'_> {
|
||||
//"view-1"
|
||||
//}
|
||||
//}
|
||||
///// Generated by [tengri_proc].
|
||||
//impl ::tengri::output::Content<SomeOutput> for SomeView {
|
||||
//fn content (&self) -> impl Render<SomeOutput> {
|
||||
//self.size.of(::tengri::output::View(self, self.config.view))
|
||||
//}
|
||||
//}
|
||||
///// Generated by [tengri_proc].
|
||||
//impl<'a> ::tengri::dsl::ViewContext<'a, SomeOutput> for SomeView {
|
||||
//fn get_content_sym (&'a self, value: &Value<'a>) -> Option<RenderBox<'a, SomeOutput>> {
|
||||
//match value {
|
||||
//::tengri::dsl::Value::Sym(":view-1") => self.view_1().boxed(),
|
||||
//_ => panic!("expected Sym(content), got: {value:?}")
|
||||
//}
|
||||
//}
|
||||
//}
|
||||
//}));
|
||||
}
|
||||
|
||||
//#[cfg(test)] #[test] fn test_expose_definition () {
|
||||
// TODO
|
||||
//let parsed: ExposeImpl = pq! {
|
||||
////#[tengri_proc::expose]
|
||||
//impl Something {
|
||||
//fn something () -> bool {}
|
||||
//}
|
||||
//};
|
||||
//// FIXME:
|
||||
////assert_eq!(
|
||||
////format!("{}", quote! { #parsed }),
|
||||
////format!("{}", quote! {
|
||||
////impl Something {
|
||||
////fn something () {}
|
||||
////}
|
||||
////impl ::tengri::Context<bool> for Something {
|
||||
////fn get (&self, dsl: &::tengri::Value) -> Option<bool> {
|
||||
////Some(match dsl {
|
||||
////::tengri::Value::Sym(":true") => true,
|
||||
////::tengri::Value::Sym(":false") => false,
|
||||
////::tengri::Value::Sym(":bool1") => true || false,
|
||||
////_ => return None
|
||||
////})
|
||||
////}
|
||||
////}
|
||||
////})
|
||||
////);
|
||||
|
||||
//let parsed: ExposeImpl = pq! {
|
||||
////#[tengri_proc::expose]
|
||||
//impl Something {
|
||||
//#[tengri::expose(bool)] {
|
||||
//":bool1" => true || false,
|
||||
//}
|
||||
//#[tengri::expose(u16)] {
|
||||
//":u161" => 0 + 1,
|
||||
//}
|
||||
//#[tengri::expose(usize)] {
|
||||
//":usize1" => 1 + 2,
|
||||
//}
|
||||
//#[tengri::expose(Arc<str>)] {
|
||||
//":arcstr1" => "foo".into(),
|
||||
//}
|
||||
//#[tengri::expose(Option<Arc<str>>)] {
|
||||
//":optarcstr1" => Some("bar".into()),
|
||||
//":optarcstr2" => Some("baz".into()),
|
||||
//}
|
||||
//fn something () {}
|
||||
//}
|
||||
//};
|
||||
//// FIXME:
|
||||
////assert_eq!(
|
||||
////format!("{}", quote! { #parsed }),
|
||||
////format!("{}", quote! {
|
||||
////impl Something {
|
||||
////fn something () {}
|
||||
////}
|
||||
////impl ::tengri::Context<Arc<str>> for Something {
|
||||
////fn get (&self, dsl: &::tengri::Value) -> Option<Arc<str>> {
|
||||
////Some(match dsl {
|
||||
////::tengri::Value::Sym(":arcstr1") => "foo".into(),
|
||||
////_ => return None
|
||||
////})
|
||||
////}
|
||||
////}
|
||||
////impl ::tengri::Context<Option<Arc<str>>> for Something {
|
||||
////fn get (&self, dsl: &::tengri::Value) -> Option<Option<Arc<str>>> {
|
||||
////Some(match dsl {
|
||||
////::tengri::Value::Sym(":optarcstr1") => Some("bar".into()),
|
||||
////::tengri::Value::Sym(":optarcstr2") => Some("baz".into()),
|
||||
////_ => return None
|
||||
////})
|
||||
////}
|
||||
////}
|
||||
////impl ::tengri::Context<bool> for Something {
|
||||
////fn get (&self, dsl: &::tengri::Value) -> Option<bool> {
|
||||
////Some(match dsl {
|
||||
////::tengri::Value::Sym(":true") => true,
|
||||
////::tengri::Value::Sym(":false") => false,
|
||||
////::tengri::Value::Sym(":bool1") => true || false,
|
||||
////_ => return None
|
||||
////})
|
||||
////}
|
||||
////}
|
||||
////impl ::tengri::Context<u16> for Something {
|
||||
////fn get (&self, dsl: &::tengri::Value) -> Option<u16> {
|
||||
////Some(match dsl {
|
||||
////::tengri::Value::Num(n) => *n as u16,
|
||||
////::tengri::Value::Sym(":u161") => 0 + 1,
|
||||
////_ => return None
|
||||
////})
|
||||
////}
|
||||
////}
|
||||
////impl ::tengri::Context<usize> for Something {
|
||||
////fn get (&self, dsl: &::tengri::Value) -> Option<usize> {
|
||||
////Some(match dsl {
|
||||
////::tengri::Value::Num(n) => *n as usize,
|
||||
////::tengri::Value::Sym(":usize1") => 1 + 2,
|
||||
////_ => return None
|
||||
////})
|
||||
////}
|
||||
////}
|
||||
////})
|
||||
////)
|
||||
//}
|
||||
|
|
|
|||
|
|
@ -189,109 +189,3 @@ impl ToTokens for ExposeType {
|
|||
self.0.to_tokens(out)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)] #[test] fn test_expose_definition () {
|
||||
// TODO
|
||||
//let parsed: ExposeImpl = pq! {
|
||||
////#[tengri_proc::expose]
|
||||
//impl Something {
|
||||
//fn something () -> bool {}
|
||||
//}
|
||||
//};
|
||||
//// FIXME:
|
||||
////assert_eq!(
|
||||
////format!("{}", quote! { #parsed }),
|
||||
////format!("{}", quote! {
|
||||
////impl Something {
|
||||
////fn something () {}
|
||||
////}
|
||||
////impl ::tengri::Context<bool> for Something {
|
||||
////fn get (&self, dsl: &::tengri::Value) -> Option<bool> {
|
||||
////Some(match dsl {
|
||||
////::tengri::Value::Sym(":true") => true,
|
||||
////::tengri::Value::Sym(":false") => false,
|
||||
////::tengri::Value::Sym(":bool1") => true || false,
|
||||
////_ => return None
|
||||
////})
|
||||
////}
|
||||
////}
|
||||
////})
|
||||
////);
|
||||
|
||||
//let parsed: ExposeImpl = pq! {
|
||||
////#[tengri_proc::expose]
|
||||
//impl Something {
|
||||
//#[tengri::expose(bool)] {
|
||||
//":bool1" => true || false,
|
||||
//}
|
||||
//#[tengri::expose(u16)] {
|
||||
//":u161" => 0 + 1,
|
||||
//}
|
||||
//#[tengri::expose(usize)] {
|
||||
//":usize1" => 1 + 2,
|
||||
//}
|
||||
//#[tengri::expose(Arc<str>)] {
|
||||
//":arcstr1" => "foo".into(),
|
||||
//}
|
||||
//#[tengri::expose(Option<Arc<str>>)] {
|
||||
//":optarcstr1" => Some("bar".into()),
|
||||
//":optarcstr2" => Some("baz".into()),
|
||||
//}
|
||||
//fn something () {}
|
||||
//}
|
||||
//};
|
||||
//// FIXME:
|
||||
////assert_eq!(
|
||||
////format!("{}", quote! { #parsed }),
|
||||
////format!("{}", quote! {
|
||||
////impl Something {
|
||||
////fn something () {}
|
||||
////}
|
||||
////impl ::tengri::Context<Arc<str>> for Something {
|
||||
////fn get (&self, dsl: &::tengri::Value) -> Option<Arc<str>> {
|
||||
////Some(match dsl {
|
||||
////::tengri::Value::Sym(":arcstr1") => "foo".into(),
|
||||
////_ => return None
|
||||
////})
|
||||
////}
|
||||
////}
|
||||
////impl ::tengri::Context<Option<Arc<str>>> for Something {
|
||||
////fn get (&self, dsl: &::tengri::Value) -> Option<Option<Arc<str>>> {
|
||||
////Some(match dsl {
|
||||
////::tengri::Value::Sym(":optarcstr1") => Some("bar".into()),
|
||||
////::tengri::Value::Sym(":optarcstr2") => Some("baz".into()),
|
||||
////_ => return None
|
||||
////})
|
||||
////}
|
||||
////}
|
||||
////impl ::tengri::Context<bool> for Something {
|
||||
////fn get (&self, dsl: &::tengri::Value) -> Option<bool> {
|
||||
////Some(match dsl {
|
||||
////::tengri::Value::Sym(":true") => true,
|
||||
////::tengri::Value::Sym(":false") => false,
|
||||
////::tengri::Value::Sym(":bool1") => true || false,
|
||||
////_ => return None
|
||||
////})
|
||||
////}
|
||||
////}
|
||||
////impl ::tengri::Context<u16> for Something {
|
||||
////fn get (&self, dsl: &::tengri::Value) -> Option<u16> {
|
||||
////Some(match dsl {
|
||||
////::tengri::Value::Num(n) => *n as u16,
|
||||
////::tengri::Value::Sym(":u161") => 0 + 1,
|
||||
////_ => return None
|
||||
////})
|
||||
////}
|
||||
////}
|
||||
////impl ::tengri::Context<usize> for Something {
|
||||
////fn get (&self, dsl: &::tengri::Value) -> Option<usize> {
|
||||
////Some(match dsl {
|
||||
////::tengri::Value::Num(n) => *n as usize,
|
||||
////::tengri::Value::Sym(":usize1") => 1 + 2,
|
||||
////_ => return None
|
||||
////})
|
||||
////}
|
||||
////}
|
||||
////})
|
||||
////)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ pub(crate) struct ViewDef(pub(crate) ViewMeta, pub(crate) ViewImpl);
|
|||
|
||||
#[derive(Debug, Clone)]
|
||||
pub(crate) struct ViewMeta {
|
||||
output: Ident,
|
||||
pub(crate) output: Ident,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
|
|
@ -114,123 +114,3 @@ impl ToTokens for ViewArm {
|
|||
out.append(Punct::new(',', Alone));
|
||||
}
|
||||
}
|
||||
|
||||
//impl ToTokens for ViewSym {
|
||||
//fn to_tokens (&self, out: &mut TokenStream2) {
|
||||
//out.append(Punct::new(':', Joint));
|
||||
//out.append(Punct::new(':', Alone));
|
||||
//out.append(Ident::new("tengri", Span::call_site()));
|
||||
//out.append(Punct::new(':', Joint));
|
||||
//out.append(Punct::new(':', Alone));
|
||||
//out.append(Ident::new("dsl", Span::call_site()));
|
||||
//out.append(Punct::new(':', Joint));
|
||||
//out.append(Punct::new(':', Alone));
|
||||
//out.append(Ident::new("Value", Span::call_site()));
|
||||
//out.append(Punct::new(':', Joint));
|
||||
//out.append(Punct::new(':', Alone));
|
||||
//out.append(Ident::new("Sym", Span::call_site()));
|
||||
//out.append(Group::new(Delimiter::Parenthesis, {
|
||||
//let mut out = TokenStream2::new();
|
||||
//out.append(self.symbol.clone());
|
||||
//out
|
||||
//}));
|
||||
//out.append(Punct::new('=', Joint));
|
||||
//out.append(Punct::new('>', Alone));
|
||||
//out.append(Ident::new("Some", Span::call_site()));
|
||||
//out.append(Group::new(Delimiter::Parenthesis, {
|
||||
//let mut out = TokenStream2::new();
|
||||
//out.append(Ident::new("self", Span::call_site()));
|
||||
//out.append(Punct::new('.', Alone));
|
||||
//out.append(self.name.clone());
|
||||
//out.append(Group::new(Delimiter::Parenthesis, TokenStream2::new()));
|
||||
//out.append(Punct::new('.', Alone));
|
||||
//out.append(Ident::new("boxed", Span::call_site()));
|
||||
//out.append(Group::new(Delimiter::Parenthesis, TokenStream2::new()));
|
||||
//out
|
||||
//}));
|
||||
//out.append(Punct::new(',', Alone));
|
||||
//}
|
||||
//}
|
||||
|
||||
//impl std::cmp::PartialEq for ViewItem {
|
||||
//fn eq (&self, other: &Self) -> bool {
|
||||
//self.item == other.item && (format!("{:?}", self.expose) == format!("{:?}", other.expose))
|
||||
//}
|
||||
//}
|
||||
|
||||
//impl std::cmp::PartialEq for ViewSym {
|
||||
//fn eq (&self, other: &Self) -> bool {
|
||||
//self.name == other.name && (format!("{}", self.symbol) == format!("{}", other.symbol))
|
||||
//}
|
||||
//}
|
||||
|
||||
#[cfg(test)] #[test] fn test_view_meta () {
|
||||
let x: ViewMeta = pq! { SomeOutput };
|
||||
let output: Ident = pq! { SomeOutput };
|
||||
assert_eq!(x.output, output);
|
||||
}
|
||||
|
||||
#[cfg(test)] #[test] fn test_view_impl () {
|
||||
// TODO
|
||||
let x: ViewImpl = pq! {
|
||||
impl Foo {
|
||||
/// docstring1
|
||||
#[tengri::view(":view1")] #[bar] fn a_view () {}
|
||||
|
||||
#[baz]
|
||||
/// docstring2
|
||||
#[baz] fn is_not_view () {}
|
||||
}
|
||||
};
|
||||
let expected_target: Ident = pq! { Foo };
|
||||
//assert_eq!(x.target, expected_target);
|
||||
//assert_eq!(x.items.len(), 2);
|
||||
//assert_eq!(x.items[0].item, pq! {
|
||||
///// docstring1
|
||||
//#[bar] fn a_view () {}
|
||||
//});
|
||||
//assert_eq!(x.items[1].item, pq! {
|
||||
//#[baz]
|
||||
///// docstring2
|
||||
//#[baz] fn is_not_view () {}
|
||||
//});
|
||||
//assert_eq!(x.syms, vec![
|
||||
//ViewArm( { symbol: pq! { ":view1" }, name: pq! { a_view }, },
|
||||
//]);
|
||||
}
|
||||
|
||||
#[cfg(test)] #[test] fn test_view_definition () {
|
||||
// FIXME
|
||||
//let parsed: ViewDefinition = pq! {
|
||||
//#[tengri_proc::view(SomeOutput)]
|
||||
//impl SomeView {
|
||||
//#[tengri::view(":view-1")]
|
||||
//fn view_1 (&self) -> impl Content<SomeOutput> + use<'_> {
|
||||
//"view-1"
|
||||
//}
|
||||
//}
|
||||
//};
|
||||
//let written = quote! { #parsed };
|
||||
//assert_eq!(format!("{written}"), format!("{}", quote! {
|
||||
//impl SomeView {
|
||||
//fn view_1 (&self) -> impl Content<SomeOutput> + use<'_> {
|
||||
//"view-1"
|
||||
//}
|
||||
//}
|
||||
///// Generated by [tengri_proc].
|
||||
//impl ::tengri::output::Content<SomeOutput> for SomeView {
|
||||
//fn content (&self) -> impl Render<SomeOutput> {
|
||||
//self.size.of(::tengri::output::View(self, self.config.view))
|
||||
//}
|
||||
//}
|
||||
///// Generated by [tengri_proc].
|
||||
//impl<'a> ::tengri::dsl::ViewContext<'a, SomeOutput> for SomeView {
|
||||
//fn get_content_sym (&'a self, value: &Value<'a>) -> Option<RenderBox<'a, SomeOutput>> {
|
||||
//match value {
|
||||
//::tengri::dsl::Value::Sym(":view-1") => self.view_1().boxed(),
|
||||
//_ => panic!("expected Sym(content), got: {value:?}")
|
||||
//}
|
||||
//}
|
||||
//}
|
||||
//}));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue