ok now it fails in a different place

This commit is contained in:
🪞👃🪞 2025-01-14 00:41:05 +01:00
parent 585bba6666
commit 23fe9f0949
9 changed files with 82 additions and 130 deletions

View file

@ -32,8 +32,8 @@ mod try_from_edn; pub use self::try_from_edn::*;
} }
#[cfg(test)] #[test] fn test_edn_layout () -> Result<(), ParseError> { #[cfg(test)] #[test] fn test_edn_layout () -> Result<(), ParseError> {
EdnItem::<String>::read_all(include_str!("../../tek/examples/edn01.edn"))?; EdnItem::<String>::read_all(include_str!("../../output/examples/edn01.edn"))?;
EdnItem::<String>::read_all(include_str!("../../tek/examples/edn02.edn"))?; EdnItem::<String>::read_all(include_str!("../../output/examples/edn02.edn"))?;
//panic!("{layout:?}"); //panic!("{layout:?}");
//let content = <dyn EdnViewData<::tek_engine::tui::Tui>>::from(&layout); //let content = <dyn EdnViewData<::tek_engine::tui::Tui>>::from(&layout);
Ok(()) Ok(())

View file

@ -45,26 +45,21 @@ impl<E: Output, A: Content<E>> Content<E> for Align<E, A> {
to.place(Content::layout(self, to.area()), &self.content()) to.place(Content::layout(self, to.area()), &self.content())
} }
} }
impl<'a, T, E, A> TryFromEdn<'a, T> for Align<E, A> impl<'a, E: Output + 'a, T: EdnViewData<'a, E>> TryFromEdn<'a, T> for Align<E, RenderBox<'a, E>> {
where
T: EdnProvide<'a, A> + 'a,
E: Output,
A: Render<E> + 'a,
{
fn try_from_edn (state: &'a T, head: &EdnItem<&str>, tail: &'a [EdnItem<&str>]) -> Option<Self> { fn try_from_edn (state: &'a T, head: &EdnItem<&str>, tail: &'a [EdnItem<&str>]) -> Option<Self> {
use EdnItem::*; use EdnItem::*;
Some(match (head, tail) { Some(match (head, tail) {
(Key("align/c"), [a]) => Self::c(state.get(a).expect("no content")), (Key("align/c"), [a]) => Self::c(state.get_content(a).expect("no content")),
(Key("align/x"), [a]) => Self::x(state.get(a).expect("no content")), (Key("align/x"), [a]) => Self::x(state.get_content(a).expect("no content")),
(Key("align/y"), [a]) => Self::y(state.get(a).expect("no content")), (Key("align/y"), [a]) => Self::y(state.get_content(a).expect("no content")),
(Key("align/n"), [a]) => Self::n(state.get(a).expect("no content")), (Key("align/n"), [a]) => Self::n(state.get_content(a).expect("no content")),
(Key("align/s"), [a]) => Self::s(state.get(a).expect("no content")), (Key("align/s"), [a]) => Self::s(state.get_content(a).expect("no content")),
(Key("align/e"), [a]) => Self::e(state.get(a).expect("no content")), (Key("align/e"), [a]) => Self::e(state.get_content(a).expect("no content")),
(Key("align/w"), [a]) => Self::w(state.get(a).expect("no content")), (Key("align/w"), [a]) => Self::w(state.get_content(a).expect("no content")),
(Key("align/nw"), [a]) => Self::nw(state.get(a).expect("no content")), (Key("align/nw"), [a]) => Self::nw(state.get_content(a).expect("no content")),
(Key("align/ne"), [a]) => Self::ne(state.get(a).expect("no content")), (Key("align/ne"), [a]) => Self::ne(state.get_content(a).expect("no content")),
(Key("align/sw"), [a]) => Self::sw(state.get(a).expect("no content")), (Key("align/sw"), [a]) => Self::sw(state.get_content(a).expect("no content")),
(Key("align/se"), [a]) => Self::se(state.get(a).expect("no content")), (Key("align/se"), [a]) => Self::se(state.get_content(a).expect("no content")),
_ => return None _ => return None
}) })
} }

View file

@ -91,22 +91,16 @@ impl<E: Output, A: Content<E>, B: Content<E>> BspAreas<E, A, B> for Bsp<E, A, B>
fn direction (&self) -> Direction { self.1 } fn direction (&self) -> Direction { self.1 }
fn contents (&self) -> (&A, &B) { (&self.2, &self.3) } fn contents (&self) -> (&A, &B) { (&self.2, &self.3) }
} }
impl<'a, T, E, A, B> TryFromEdn<'a, T> for Bsp<E, A, B> impl<'a, E: Output + 'a, T: EdnViewData<'a, E>> TryFromEdn<'a, T> for Bsp<E, RenderBox<'a, E>, RenderBox<'a, E>> {
where
T: EdnProvide<'a, A> + EdnProvide<'a, B> + 'a,
E: Output,
A: Render<E> + 'a,
B: Render<E> + 'a,
{
fn try_from_edn (s: &'a T, head: &EdnItem<&str>, tail: &'a [EdnItem<&str>]) -> Option<Self> { fn try_from_edn (s: &'a T, head: &EdnItem<&str>, tail: &'a [EdnItem<&str>]) -> Option<Self> {
use EdnItem::*; use EdnItem::*;
Some(match (head, tail) { Some(match (head, tail) {
(Key("bsp/n"), [a, b]) => Self::n(s.get(a).expect("no a"), s.get(b).expect("no b")), (Key("bsp/n"), [a, b]) => Self::n(s.get_content(a).expect("no a"), s.get(b).expect("no b")),
(Key("bsp/s"), [a, b]) => Self::s(s.get(a).expect("no a"), s.get(b).expect("no b")), (Key("bsp/s"), [a, b]) => Self::s(s.get_content(a).expect("no a"), s.get(b).expect("no b")),
(Key("bsp/e"), [a, b]) => Self::e(s.get(a).expect("no a"), s.get(b).expect("no b")), (Key("bsp/e"), [a, b]) => Self::e(s.get_content(a).expect("no a"), s.get(b).expect("no b")),
(Key("bsp/w"), [a, b]) => Self::w(s.get(a).expect("no a"), s.get(b).expect("no b")), (Key("bsp/w"), [a, b]) => Self::w(s.get_content(a).expect("no a"), s.get(b).expect("no b")),
(Key("bsp/a"), [a, b]) => Self::a(s.get(a).expect("no a"), s.get(b).expect("no b")), (Key("bsp/a"), [a, b]) => Self::a(s.get_content(a).expect("no a"), s.get(b).expect("no b")),
(Key("bsp/b"), [a, b]) => Self::b(s.get(a).expect("no a"), s.get(b).expect("no b")), (Key("bsp/b"), [a, b]) => Self::b(s.get_content(a).expect("no a"), s.get(b).expect("no b")),
_ => return None _ => return None
}) })
} }

View file

@ -69,77 +69,59 @@ pub trait EdnViewData<'a, E: Output>:
EdnProvide<'a, E::Unit> + EdnProvide<'a, E::Unit> +
EdnProvide<'a, Box<dyn Render<E> + 'a>> EdnProvide<'a, Box<dyn Render<E> + 'a>>
{ {
fn get_bool (&'a self, item: &'a EdnItem<&str>) -> bool { fn get_bool (&'a self, item: &'a EdnItem<&str>) -> Option<bool> {
match &item { Some(match &item {
Num(0) => false, Sym(":false") | Sym(":f") | Num(0) => false,
Num(_) => true, Sym(":true") | Sym(":t") | Num(_) => true,
Sym(":true") | Sym(":t") => true, _ => return EdnProvide::get(self, item)
Sym(":false") | Sym(":f") => false, })
_ => EdnProvide::get_or_fail(self, item)
}
} }
fn get_usize (&'a self, item: &'a EdnItem<&str>) -> usize { fn get_usize (&'a self, item: &'a EdnItem<&str>) -> Option<usize> {
match &item { Num(n) => *n, _ => EdnProvide::get_or_fail(self, item) } Some(match &item { Num(n) => *n, _ => return EdnProvide::get(self, item) })
} }
fn get_unit (&'a self, item: &'a EdnItem<&str>) -> E::Unit { fn get_unit (&'a self, item: &'a EdnItem<&str>) -> Option<E::Unit> {
match &item { Num(n) => (*n as u16).into(), _ => EdnProvide::get_or_fail(self, item) } Some(match &item { Num(n) => (*n as u16).into(), _ => return EdnProvide::get(self, item) })
} }
fn get_content (&'a self, item: &'a EdnItem<&'a str>) -> Box<dyn Render<E> + 'a> where E: 'a { fn get_content (&'a self, item: &'a EdnItem<&'a str>) -> Option<Box<dyn Render<E> + 'a>> where E: 'a {
match item { Some(match item {
Nil => Box::new(()), Nil => Box::new(()),
Exp(e) => if let [head, tail @ ..] = e.as_slice() { Exp(e) => if let [head, tail @ ..] = e.as_slice() {
if let Some(builtin) = When::<_, RenderBox<'a, E>>::try_from_edn(self, head, tail) { if let Some(builtin) = When::<_, RenderBox<'a, E>>::try_from_edn(self, head, tail) {
return builtin.boxed() builtin.boxed()
} else if let Some(builtin) = Either::<_, RenderBox<'a, E>, RenderBox<'a, E>>::try_from_edn(self, head, tail) {
builtin.boxed()
} else if let Some(builtin) = Align::<_, RenderBox<'a, E>>::try_from_edn(self, head, tail) {
builtin.boxed()
} else if let Some(builtin) = Bsp::<_, RenderBox<'a, E>, RenderBox<'a, E>>::try_from_edn(self, head, tail) {
builtin.boxed()
} else if let Some(builtin) = Fill::<_, RenderBox<'a, E>>::try_from_edn(self, head, tail) {
builtin.boxed()
} else if let Some(builtin) = Fixed::<_, _, RenderBox<'a, E>>::try_from_edn(self, head, tail) {
builtin.boxed()
} else if let Some(builtin) = Min::<_, _, RenderBox<'a, E>>::try_from_edn(self, head, tail) {
builtin.boxed()
} else if let Some(builtin) = Max::<_, _, RenderBox<'a, E>>::try_from_edn(self, head, tail) {
builtin.boxed()
} else if let Some(builtin) = Shrink::<_, _, RenderBox<'a, E>>::try_from_edn(self, head, tail) {
builtin.boxed()
} else if let Some(builtin) = Expand::<_, _, RenderBox<'a, E>>::try_from_edn(self, head, tail) {
builtin.boxed()
} else if let Some(builtin) = Push::<_, _, RenderBox<'a, E>>::try_from_edn(self, head, tail) {
builtin.boxed()
} else if let Some(builtin) = Pull::<_, _, RenderBox<'a, E>>::try_from_edn(self, head, tail) {
builtin.boxed()
} else if let Some(builtin) = Margin::<_, _, RenderBox<'a, E>>::try_from_edn(self, head, tail) {
builtin.boxed()
} else if let Some(builtin) = Padding::<_, _, RenderBox<'a, E>>::try_from_edn(self, head, tail) {
builtin.boxed()
} else {
EdnProvide::get_or_fail(self, &item)
} }
if let Some(builtin) = Either::<_, RenderBox<'a, E>, RenderBox<'a, E>>::try_from_edn(
self, head, tail
) {
return builtin.boxed()
}
if let Some(builtin) = Align::<_, RenderBox<'a, E>>::try_from_edn(self, head, tail) {
return builtin.boxed()
}
if let Some(builtin) = Bsp::<_, RenderBox<'a, E>, RenderBox<'a, E>>::try_from_edn(
self, head, tail
) {
return builtin.boxed()
}
if let Some(builtin) = Fill::<_, RenderBox<'a, E>>::try_from_edn(self, head, tail) {
return builtin.boxed()
}
if let Some(builtin) = Fixed::<_, _, RenderBox<'a, E>>::try_from_edn(self, head, tail) {
return builtin.boxed()
}
if let Some(builtin) = Min::<_, _, RenderBox<'a, E>>::try_from_edn(self, head, tail) {
return builtin.boxed()
}
if let Some(builtin) = Max::<_, _, RenderBox<'a, E>>::try_from_edn(self, head, tail) {
return builtin.boxed()
}
if let Some(builtin) = Shrink::<_, _, RenderBox<'a, E>>::try_from_edn(self, head, tail) {
return builtin.boxed()
}
if let Some(builtin) = Expand::<_, _, RenderBox<'a, E>>::try_from_edn(self, head, tail) {
return builtin.boxed()
}
if let Some(builtin) = Push::<_, _, RenderBox<'a, E>>::try_from_edn(self, head, tail) {
return builtin.boxed()
}
if let Some(builtin) = Pull::<_, _, RenderBox<'a, E>>::try_from_edn(self, head, tail) {
return builtin.boxed()
}
if let Some(builtin) = Margin::<_, _, RenderBox<'a, E>>::try_from_edn(self, head, tail) {
return builtin.boxed()
}
if let Some(builtin) = Padding::<_, _, RenderBox<'a, E>>::try_from_edn(self, head, tail) {
return builtin.boxed()
}
EdnProvide::get_or_fail(self, &item)
} else { } else {
EdnProvide::get_or_fail(self, &item) EdnProvide::get_or_fail(self, &item)
}, },
_ => EdnProvide::get_or_fail(self, &item) _ => EdnProvide::get_or_fail(self, &item)
} })
//panic!("no content") //panic!("no content")
} }
} }

View file

@ -6,13 +6,7 @@ impl<E, A, B> Either<E, A, B> {
Self(Default::default(), c, a, b) Self(Default::default(), c, a, b)
} }
} }
impl<'a, T, E, A, B> TryFromEdn<'a, T> for Either<E, A, B> impl<'a, E: Output + 'a, T: EdnViewData<'a, E>> TryFromEdn<'a, T> for Either<E, RenderBox<'a, E>, RenderBox<'a, E>> {
where
T: EdnProvide<'a, bool> + EdnProvide<'a, B> + EdnProvide<'a, A> + 'a,
E: Output,
A: Render<E> + 'a,
B: Render<E> + 'a,
{
fn try_from_edn (state: &'a T, head: &EdnItem<&str>, tail: &'a [EdnItem<&str>]) -> Option<Self> { fn try_from_edn (state: &'a T, head: &EdnItem<&str>, tail: &'a [EdnItem<&str>]) -> Option<Self> {
use EdnItem::*; use EdnItem::*;
if let (Key("either"), [condition, content, alternative]) = (head, tail) { if let (Key("either"), [condition, content, alternative]) = (head, tail) {

View file

@ -27,20 +27,15 @@ macro_rules! transform_xy {
$area $area
} }
} }
impl<'a, T, E, A> TryFromEdn<'a, T> for $Enum<E, A> impl<'a, E: Output + 'a, T: EdnViewData<'a, E>> TryFromEdn<'a, T> for $Enum<E, RenderBox<'a, E>> {
where
T: EdnProvide<'a, A> + 'a,
E: Output,
A: Render<E> + 'a
{
fn try_from_edn ( fn try_from_edn (
state: &'a T, head: &EdnItem<&str>, tail: &'a [EdnItem<&str>] state: &'a T, head: &EdnItem<&str>, tail: &'a [EdnItem<&str>]
) -> Option<Self> { ) -> Option<Self> {
use EdnItem::*; use EdnItem::*;
Some(match (head, tail) { Some(match (head, tail) {
(Key($x), [a]) => Self::x(state.get(a).expect("no content")), (Key($x), [a]) => Self::x(state.get_content(a).expect("no content")),
(Key($y), [a]) => Self::y(state.get(a).expect("no content")), (Key($y), [a]) => Self::y(state.get_content(a).expect("no content")),
(Key($xy), [a]) => Self::xy(state.get(a).expect("no content")), (Key($xy), [a]) => Self::xy(state.get_content(a).expect("no content")),
_ => return None _ => return None
}) })
} }

View file

@ -41,29 +41,24 @@ macro_rules! transform_xy_unit {
$layout.into() $layout.into()
} }
} }
impl<'a, T, E, A> TryFromEdn<'a, T> for $Enum<E, E::Unit, A> impl<'a, E: Output + 'a, T: EdnViewData<'a, E>> TryFromEdn<'a, T> for $Enum<E, E::Unit, RenderBox<'a, E>> {
where
T: EdnProvide<'a, E::Unit> + EdnProvide<'a, A> + 'a,
E: Output,
A: Render<E> + 'a,
{
fn try_from_edn ( fn try_from_edn (
state: &'a T, head: &EdnItem<&str>, tail: &'a [EdnItem<&str>] state: &'a T, head: &EdnItem<&str>, tail: &'a [EdnItem<&str>]
) -> Option<Self> { ) -> Option<Self> {
use EdnItem::*; use EdnItem::*;
Some(match (head, tail) { Some(match (head, tail) {
(Key($x), [x, a]) => Self::x( (Key($x), [x, a]) => Self::x(
state.get(x).expect("no content"), state.get_unit(x).expect("no x"),
state.get(a).expect("no content"), state.get_content(a).expect("no content"),
), ),
(Key($y), [y, a]) => Self::y( (Key($y), [y, a]) => Self::y(
state.get(y).expect("no content"), state.get_unit(y).expect("no y"),
state.get(a).expect("no content"), state.get_content(a).expect("no content"),
), ),
(Key($xy), [x, y, a]) => Self::xy( (Key($xy), [x, y, a]) => Self::xy(
state.get(x).expect("no content"), state.get_unit(x).expect("no x"),
state.get(y).expect("no content"), state.get_unit(y).expect("no y"),
state.get(a).expect("no content"), state.get_content(a).expect("no content"),
), ),
_ => return None _ => return None
}) })

View file

@ -6,12 +6,7 @@ impl<E, A> When<E, A> {
Self(Default::default(), c, a) Self(Default::default(), c, a)
} }
} }
impl<'a, T, E, A> TryFromEdn<'a, T> for When<E, A> impl<'a, E: Output + 'a, T: EdnViewData<'a, E>> TryFromEdn<'a, T> for When<E, RenderBox<'a, E>> {
where
T: EdnProvide<'a, bool> + EdnProvide<'a, A> + 'a,
E: Output,
A: Render<E> + 'a
{
fn try_from_edn ( fn try_from_edn (
state: &'a T, head: &EdnItem<&str>, tail: &'a [EdnItem<&str>] state: &'a T, head: &EdnItem<&str>, tail: &'a [EdnItem<&str>]
) -> Option<Self> { ) -> Option<Self> {
@ -19,8 +14,8 @@ where
if let (Key("when"), [condition, content]) = (head, tail) { if let (Key("when"), [condition, content]) = (head, tail) {
Some(Self( Some(Self(
Default::default(), Default::default(),
state.get(condition).expect("when: no condition"), state.get_bool(condition).expect("when: no condition"),
state.get(content).expect("when: no content") state.get_content(content).expect("when: no content")
)) ))
} else { } else {
None None

View file

@ -1 +1,3 @@
(fill/x (fixed/y 2 :toolbar)) (bsp/s :toolbar
(fill/x (align/c (bsp/w :pool
(bsp/n :outputs (bsp/n :inputs (bsp/n :tracks :scenes)))))))