wip: compiles and runs (not enabled yet)

This commit is contained in:
🪞👃🪞 2025-01-04 11:19:37 +01:00
parent ac3827b8f3
commit 98d2107e4e
15 changed files with 440 additions and 357 deletions

View file

@ -18,10 +18,10 @@ impl<'a, E, T: AsRef<str>> From<&'a [Item<T>]> for EdnContent<'a, E, T> {
//pub struct EdnContent<'a, T>(T, &'a [Item]);
pub trait EdnLayout<E: Engine + 'static> {
fn get_bool (&self, item: &Item<&str>) -> bool { todo!() }
fn get_unit (&self, item: &Item<&str>) -> E::Unit { todo!() }
fn get_usize (&self, key: &str) -> usize { todo!() }
fn get_content (&self, item: &Item<&str>) -> &dyn Render<E> { todo!() }
fn get_bool (&self, item: &Item<&str>) -> bool { false }
fn get_unit (&self, item: &Item<&str>) -> E::Unit { 0.into() }
fn get_usize (&self, key: &str) -> usize { 0 }
fn get_content (&self, item: &Item<&str>) -> Box<dyn Render<E> + '_> { Box::new(()) }
fn parse <'a: 'static> (&'a self, items: &[Item<&str>]) -> Box<dyn Render<E> + 'a> {
match items {
[Key("when"), c, a, ..] =>
@ -71,50 +71,6 @@ pub trait EdnLayout<E: Engine + 'static> {
}
}
macro_rules! edn_context {
($Struct:ident |$l:lifetime, $state:ident| {
$($key:literal = $field:ident: $Type:ty => $expr:expr,)*
}) => {
#[derive(Default)]
pub struct EdnView<$l> { $($field: Option<$Type>),* }
impl<$l> EdnView<$l> {
pub fn parse <'e> (edn: &[Edn<'e>]) -> impl Fn(&$Struct) + use<'e> {
let imports = Self::imports_all(edn);
move |state| {
let mut context = EdnView::default();
for import in imports.iter() {
context.import(state, import)
}
}
}
fn imports_all <'e> (edn: &[Edn<'e>]) -> Vec<&'e str> {
let mut imports = vec![];
for edn in edn.iter() {
for import in Self::imports_one(edn) {
imports.push(import);
}
}
imports
}
fn imports_one <'e> (edn: &Edn<'e>) -> Vec<&'e str> {
match edn {
Edn::Symbol(import) => vec![import],
Edn::List(edn) => Self::imports_all(edn.as_slice()),
_ => vec![],
}
}
pub fn import (&mut self, $state: &$l$Struct, key: &str) {
match key {
$($key => self.$field = Some($expr),)*
_ => {}
}
}
}
}
}
//edn_ns! { EdnLayout |context, item| {
//[Key("when"), Sym(condition), Sym(template)] => When(