mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 19:56:42 +01:00
wip: preparing to run groovebox from edn
This commit is contained in:
parent
ce4574ed78
commit
a6efde40f8
5 changed files with 43 additions and 28 deletions
|
|
@ -41,14 +41,20 @@ impl<T: PartialEq> PartialEq for EdnItem<T> {
|
|||
impl<T: AsRef<str> + PartialEq + Default + Clone + std::fmt::Debug> EdnItem<T> {
|
||||
pub fn to_ref (&self) -> EdnItem<&str> {
|
||||
match self {
|
||||
Self::Nil => EdnItem::Nil,
|
||||
Self::Num(x) => EdnItem::Num(*x),
|
||||
Self::Key(x) => EdnItem::Key(x.as_ref()),
|
||||
_ => todo!()
|
||||
Self::Sym(x) => EdnItem::Sym(x.as_ref()),
|
||||
Self::Exp(x) => EdnItem::Exp(x.iter().map(|x|x.to_ref()).collect::<Vec<_>>()),
|
||||
}
|
||||
}
|
||||
pub fn to_str (&self) -> &str {
|
||||
match self {
|
||||
Self::Nil => "",
|
||||
Self::Num(_) => "",
|
||||
Self::Key(x) => x.as_ref(),
|
||||
_ => todo!()
|
||||
Self::Sym(x) => x.as_ref(),
|
||||
Self::Exp(_) => "",
|
||||
}
|
||||
}
|
||||
pub fn symbols <'a> (&'a self) -> EdnIterator<'a, T> {
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue