wip: preparing to run groovebox from edn

This commit is contained in:
🪞👃🪞 2025-01-05 17:10:57 +01:00
parent ce4574ed78
commit a6efde40f8
5 changed files with 43 additions and 28 deletions

View file

@ -10,10 +10,10 @@ pub type EdnRenderCallback<'a, Engine, State> =
Box<EdnCallback<'a, Engine, State>>;
pub trait EdnViewData<E: Engine> {
fn get_bool (&self, _sym: &str) -> bool { false }
fn get_unit (&self, _sym: &str) -> E::Unit { 0.into() }
fn get_usize (&self, _sym: &str) -> usize { 0 }
fn get_content <'a> (&'a self, _sym: &'a str) -> RenderBox<'a, E> { Box::new(()) }
fn get_bool (&self, _sym: EdnItem<&str>) -> bool { false }
fn get_unit (&self, _sym: EdnItem<&str>) -> E::Unit { 0.into() }
fn get_usize (&self, _sym: EdnItem<&str>) -> usize { 0 }
fn get_content <'a> (&'a self, _sym: EdnItem<&str>) -> RenderBox<'a, E> { Box::new(()) }
}
/// Renders from EDN source and context.
@ -36,18 +36,15 @@ impl<E: Engine, T: EdnViewData<E> + Send + Sync> Content<E> for EdnView<E, T> {
use EdnItem::*;
match &self.layout {
Nil => ().boxed(),
Sym(t) => self.context.get_content(t.as_str()).boxed(),
Sym(t) => self.context.get_content(Sym(t.as_str())).boxed(),
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) => if let [head, tail @ ..] = e.as_slice() {
let head = &head.to_ref();
let state = &self.context;
match (head, tail) {
(Key("when"), [Sym(c), Sym(a)]) => When(
self.context.get_bool(c.as_str()),
self.context.get_content(a.as_str())).boxed(),
(Key("bsp/s"), [Sym(a), Sym(b)]) => Bsp::s(
self.context.get_content(a.as_str()),
self.context.get_content(b.as_str())).boxed(),
(Key("when"), [c, a]) => When(state.get_bool(c.to_ref()), state.get_content(a.to_ref())).boxed(),
(Key("bsp/s"), [a, b]) => Bsp::s(state.get_content(a.to_ref()), state.get_content(b.to_ref()),).boxed(),
_ => todo!("{:?} {:?}", &head, &tail)
}
} else {