mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2025-12-06 03:36:42 +01:00
wip: scaffold proc crate and view macro
This commit is contained in:
parent
21f7f6b38a
commit
2c797fd41f
9 changed files with 135 additions and 5 deletions
9
Cargo.lock
generated
9
Cargo.lock
generated
|
|
@ -972,6 +972,15 @@ dependencies = [
|
||||||
"tengri_tui",
|
"tengri_tui",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tengri_proc"
|
||||||
|
version = "0.13.0"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tengri_tui"
|
name = "tengri_tui"
|
||||||
version = "0.13.0"
|
version = "0.13.0"
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
[workspace.package]
|
[workspace.package]
|
||||||
version = "0.13.0"
|
version = "0.13.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
[workspace]
|
[workspace]
|
||||||
resolver = "2"
|
resolver = "2"
|
||||||
|
|
@ -8,7 +9,8 @@ members = [
|
||||||
"./input",
|
"./input",
|
||||||
"./output",
|
"./output",
|
||||||
"./tui",
|
"./tui",
|
||||||
"./dsl"
|
"./dsl",
|
||||||
|
"./proc",
|
||||||
]
|
]
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
[package]
|
[package]
|
||||||
name = "tengri_dsl"
|
name = "tengri_dsl"
|
||||||
edition = "2024"
|
|
||||||
description = "UI metaframework, tiny S-expression-based DSL."
|
description = "UI metaframework, tiny S-expression-based DSL."
|
||||||
version = { workspace = true }
|
version = { workspace = true }
|
||||||
|
edition = { workspace = true }
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
konst = { version = "0.3.16", features = [ "rust_1_83" ] }
|
konst = { version = "0.3.16", features = [ "rust_1_83" ] }
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
[package]
|
[package]
|
||||||
name = "tengri_input"
|
name = "tengri_input"
|
||||||
edition = "2024"
|
|
||||||
description = "UI metaframework, input layer."
|
description = "UI metaframework, input layer."
|
||||||
version = { workspace = true }
|
version = { workspace = true }
|
||||||
|
edition = { workspace = true }
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
tengri_dsl = { optional = true, path = "../dsl" }
|
tengri_dsl = { optional = true, path = "../dsl" }
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
[package]
|
[package]
|
||||||
name = "tengri_output"
|
name = "tengri_output"
|
||||||
edition = "2024"
|
|
||||||
description = "UI metaframework, output layer."
|
description = "UI metaframework, output layer."
|
||||||
version = { workspace = true }
|
version = { workspace = true }
|
||||||
|
edition = { workspace = true }
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
tengri_dsl = { optional = true, path = "../dsl" }
|
tengri_dsl = { optional = true, path = "../dsl" }
|
||||||
|
|
|
||||||
13
proc/Cargo.toml
Normal file
13
proc/Cargo.toml
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
[package]
|
||||||
|
name = "tengri_proc"
|
||||||
|
description = "UI metaframework, procedural macros."
|
||||||
|
version = { workspace = true }
|
||||||
|
edition = { workspace = true }
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
proc-macro = true
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
syn = { version = "2", features = ["full"] }
|
||||||
|
quote = { version = "1" }
|
||||||
|
proc-macro2 = { version = "1", features = ["span-locations"] }
|
||||||
26
proc/src/lib.rs
Normal file
26
proc/src/lib.rs
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
extern crate proc_macro;
|
||||||
|
use proc_macro::TokenStream;
|
||||||
|
use proc_macro2::{TokenStream as TokenStream2};
|
||||||
|
|
||||||
|
mod proc_view;
|
||||||
|
|
||||||
|
#[proc_macro_attribute]
|
||||||
|
pub fn view (meta: TokenStream, item: TokenStream) -> TokenStream {
|
||||||
|
self::proc_view::view_impl(meta.into(), item.into()).into()
|
||||||
|
//for attr in syn::parse_macro_input!(meta as syn::MetaList).iter() {
|
||||||
|
//}
|
||||||
|
//let item = syn::parse_macro_input!(item as syn::ItemImpl);
|
||||||
|
//let output = "TuiOut";
|
||||||
|
//let target = "Tek";
|
||||||
|
//let define = "self.config.view";
|
||||||
|
//let expose = vec![];
|
||||||
|
//let output = format!(
|
||||||
|
//"::tengri_dsl::view!({}:|self:{}|self.size.of(::tengri_dsl::View(self,{}));{{{}}});",
|
||||||
|
//output,
|
||||||
|
//target,
|
||||||
|
//define,
|
||||||
|
//expose.iter().fold(String::new(), |acc, (key, value)|format!("{acc},{key}=>{value}")),
|
||||||
|
//);
|
||||||
|
//let output = "";
|
||||||
|
//output.parse().unwrap()
|
||||||
|
}
|
||||||
80
proc/src/proc_view.rs
Normal file
80
proc/src/proc_view.rs
Normal file
|
|
@ -0,0 +1,80 @@
|
||||||
|
use proc_macro::TokenStream;
|
||||||
|
use proc_macro2::{TokenStream as TokenStream2};
|
||||||
|
|
||||||
|
pub(crate) fn view_impl (meta: TokenStream, item: TokenStream) -> TokenStream {
|
||||||
|
let ViewMeta { output, define, attrs } = syn::parse_macro_input!(meta as ViewMeta);
|
||||||
|
let ViewItem { target, mapped, items } = syn::parse_macro_input!(item as ViewItem);
|
||||||
|
quote::quote! {
|
||||||
|
#attrs
|
||||||
|
impl #target {
|
||||||
|
#items
|
||||||
|
}
|
||||||
|
impl ::tengri::Content<#output> for #target {
|
||||||
|
fn content (&self) -> impl Render<#output> {
|
||||||
|
self.size.of(::tengri::View(self, #define))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl<'a> ::tengri::ViewContext<'a, #output> for #target {
|
||||||
|
fn get_content_sym (&'a self, value: &Value<'a>) -> Option<RenderBox<'a, #output>> {
|
||||||
|
match value {
|
||||||
|
#mapped
|
||||||
|
_ => panic!("expected Sym(content), got: {value:?}")
|
||||||
|
}
|
||||||
|
//if let Value::Sym(s) = value {
|
||||||
|
//match *s {
|
||||||
|
//$($sym => Some($body.boxed()),)*
|
||||||
|
//_ => None
|
||||||
|
//}
|
||||||
|
//} else {
|
||||||
|
//panic!("expected Sym(content), got: {value:?}")
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.into()
|
||||||
|
}
|
||||||
|
|
||||||
|
struct ViewMeta {
|
||||||
|
attrs: &'static str,
|
||||||
|
output: &'static str,
|
||||||
|
define: &'static str,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl syn::parse::Parse for ViewMeta {
|
||||||
|
fn parse (input: syn::parse::ParseStream) -> syn::parse::Result<Self> {
|
||||||
|
Ok(Self {
|
||||||
|
attrs: "",
|
||||||
|
output: "",
|
||||||
|
define: "",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct ViewItem {
|
||||||
|
items: &'static str,
|
||||||
|
target: &'static str,
|
||||||
|
mapped: &'static str,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl syn::parse::Parse for ViewItem {
|
||||||
|
fn parse (input: syn::parse::ParseStream) -> syn::parse::Result<Self> {
|
||||||
|
Ok(Self {
|
||||||
|
items: "",
|
||||||
|
target: "",
|
||||||
|
mapped: "",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)] #[test] fn test_view () {
|
||||||
|
|
||||||
|
let _: syn::ItemImpl = syn::parse_quote! {
|
||||||
|
#[tengri::view(Tui)]
|
||||||
|
impl SomeView {
|
||||||
|
#[tengri::view(":view")]
|
||||||
|
fn view (&self) -> impl Content<TuiOut> + use<'_> {
|
||||||
|
"view"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
[package]
|
[package]
|
||||||
name = "tengri_tui"
|
name = "tengri_tui"
|
||||||
edition = "2024"
|
|
||||||
description = "UI metaframework, Ratatui backend."
|
description = "UI metaframework, Ratatui backend."
|
||||||
version = { workspace = true }
|
version = { workspace = true }
|
||||||
|
edition = { workspace = true }
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
palette = { version = "0.7.6", features = [ "random" ] }
|
palette = { version = "0.7.6", features = [ "random" ] }
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue