wip: still trying to write the iterator

This commit is contained in:
🪞👃🪞 2025-01-05 04:07:27 +01:00
parent 140fd22223
commit 433e4df0f2
7 changed files with 114 additions and 66 deletions

View file

@ -1,8 +1,5 @@
use crate::*;
use std::marker::PhantomData;
use EdnItem::*;
use EdnItem::*;
/// Renders from EDN source and context.
pub struct EdnView<'a, E: Engine + 'a, T: EdnLayout<'a, E> + 'a> {
@ -15,9 +12,53 @@ pub struct EdnView<'a, E: Engine + 'a, T: EdnLayout<'a, E> + 'a> {
impl<'a, E: Engine + 'a, T: EdnLayout<'a, E> + 'a> EdnView<'a, E, T> {
pub fn new (context: T, source: &'a str) -> Usually<Self> {
let layout = EdnItem::read_one(&source)?.0;
for symbol in layout.symbols() {
context.import(symbol)
}
Ok(Self { _engine: Default::default(), context, layout, })
}
}
impl<'a, E: Engine + 'a, T: EdnLayout<'a, E> + Send + Sync + 'a> Content<E> for EdnView<'a, E, T> {
fn content (&self) -> impl Render<E> {
use EdnItem::*;
match &self.layout {
Nil => None,
Sym(t) => Some(self.context.get_content(t.as_str())),
Key(t) => panic!("todo: add error handling to content() chain. unexpected key {t}"),
Num(n) => panic!("todo: add error handling to content() chain. unexpected num {n}"),
Exp(e) => todo!("exp {e:?}"),
}
//let items = &self.layout;
//if let (Some(first), rest) = (items.get(0).map(EdnItem::to_str), &items[1..]) {
//match (first, rest) {
//("when", [c, a, ..]) => Box::new(move|state|Box::new(
//When(state.get_bool(&c.to_ref()), state.get_content(&a.to_ref())))),
//_ => Box::new(|_|Box::new(()))
//}
//} else {
//Box::new(|_|Box::new(()))
//}
}
//Box::new(match [items.get(0).map(|x|x.to_str()), items[1..]] {
//["when", [c, a, ..]] => When(state.get_bool(c), state.get_content(a)),
//["either", [c, a, b, ..]] => Either(state.get_bool(c), state.get_content(a), state.get_content(b)),
//["fill", [a, ..]] => Fill::xy(state.get_content(a)),
//["fill/x", [a, ..]] => Fill::x(state.get_content(a)),
//["fill/y", [a, ..]] => Fill::y(state.get_content(a)),
//["fixed", [x, y, a, ..]] => Fixed::xy(state.get_unit(x), state.get_unit(y), state.get_content(a)),
//["fixed/x", [x, a, ..]] => Fixed::x(state.get_unit(x), state.get_content(a)),
//["fixed/y", [y, a, ..]] => Fixed::y(state.get_unit(y), state.get_content(a)),
//["shrink", [x, y, a, ..]] => Shrink::xy(state.get_unit(x), state.get_unit(y), state.get_content(a)),
//["shrink/x", [x, a, ..]] => Shrink::x(state.get_unit(x), state.get_content(a)),
//["shrink/y", [y, a, ..]] => Shrink::y(state.get_unit(y), state.get_content(a)),
//["expand", [x, y, a, ..]] => Expand::xy(state.get_unit(x), state.get_unit(y), state.get_content(a)),
//["expand/x", [x, a, ..]] => Expand::x(state.get_unit(x), state.get_content(a)),
//["expand/y", [y, a, ..]] => Expand::y(state.get_unit(y), state.get_content(a)),
//["push", [x, y, a, ..]] => Push::xy(state.get_unit(x), state.get_unit(y), state.get_content(a)),
//["push/x", [x, a, ..]] => Push::x(state.get_unit(x), state.get_content(a)),
//["push/y", [y, a, ..]] => Push::y(state.get_unit(y), state.get_content(a)),
//["pull", [x, y, a, ..]] => Pull::xy(state.get_unit(x), state.get_unit(y), state.get_content(a)),
//["pull/x", [x, a, ..]] => Pull::x(state.get_unit(x), state.get_content(a)),
//["pull/y", [y, a, ..]] => Pull::y(state.get_unit(y), state.get_content(a)),
//_ => Box::
//})
//}
}