From 23fe9f09499deda63c27ab20f1402d6a971953ad Mon Sep 17 00:00:00 2001 From: unspeaker Date: Tue, 14 Jan 2025 00:41:05 +0100 Subject: [PATCH] ok now it fails in a different place --- edn/src/lib.rs | 4 +- output/src/align.rs | 29 ++++----- output/src/direction.rs | 20 +++---- output/src/edn_view.rs | 102 +++++++++++++------------------- output/src/either.rs | 8 +-- output/src/transform_xy.rs | 13 ++-- output/src/transform_xy_unit.rs | 21 +++---- output/src/when.rs | 11 +--- tek/src/arranger-view.edn | 4 +- 9 files changed, 82 insertions(+), 130 deletions(-) diff --git a/edn/src/lib.rs b/edn/src/lib.rs index c7d8b783..b817a7d2 100644 --- a/edn/src/lib.rs +++ b/edn/src/lib.rs @@ -32,8 +32,8 @@ mod try_from_edn; pub use self::try_from_edn::*; } #[cfg(test)] #[test] fn test_edn_layout () -> Result<(), ParseError> { - EdnItem::::read_all(include_str!("../../tek/examples/edn01.edn"))?; - EdnItem::::read_all(include_str!("../../tek/examples/edn02.edn"))?; + EdnItem::::read_all(include_str!("../../output/examples/edn01.edn"))?; + EdnItem::::read_all(include_str!("../../output/examples/edn02.edn"))?; //panic!("{layout:?}"); //let content = >::from(&layout); Ok(()) diff --git a/output/src/align.rs b/output/src/align.rs index 59b5a617..ecbd02d9 100644 --- a/output/src/align.rs +++ b/output/src/align.rs @@ -45,26 +45,21 @@ impl> Content for Align { to.place(Content::layout(self, to.area()), &self.content()) } } -impl<'a, T, E, A> TryFromEdn<'a, T> for Align -where - T: EdnProvide<'a, A> + 'a, - E: Output, - A: Render + 'a, -{ +impl<'a, E: Output + 'a, T: EdnViewData<'a, E>> TryFromEdn<'a, T> for Align> { fn try_from_edn (state: &'a T, head: &EdnItem<&str>, tail: &'a [EdnItem<&str>]) -> Option { use EdnItem::*; Some(match (head, tail) { - (Key("align/c"), [a]) => Self::c(state.get(a).expect("no content")), - (Key("align/x"), [a]) => Self::x(state.get(a).expect("no content")), - (Key("align/y"), [a]) => Self::y(state.get(a).expect("no content")), - (Key("align/n"), [a]) => Self::n(state.get(a).expect("no content")), - (Key("align/s"), [a]) => Self::s(state.get(a).expect("no content")), - (Key("align/e"), [a]) => Self::e(state.get(a).expect("no content")), - (Key("align/w"), [a]) => Self::w(state.get(a).expect("no content")), - (Key("align/nw"), [a]) => Self::nw(state.get(a).expect("no content")), - (Key("align/ne"), [a]) => Self::ne(state.get(a).expect("no content")), - (Key("align/sw"), [a]) => Self::sw(state.get(a).expect("no content")), - (Key("align/se"), [a]) => Self::se(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_content(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_content(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_content(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_content(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_content(a).expect("no content")), + (Key("align/se"), [a]) => Self::se(state.get_content(a).expect("no content")), _ => return None }) } diff --git a/output/src/direction.rs b/output/src/direction.rs index a5b88e64..044a7d24 100644 --- a/output/src/direction.rs +++ b/output/src/direction.rs @@ -91,22 +91,16 @@ impl, B: Content> BspAreas for Bsp fn direction (&self) -> Direction { self.1 } fn contents (&self) -> (&A, &B) { (&self.2, &self.3) } } -impl<'a, T, E, A, B> TryFromEdn<'a, T> for Bsp -where - T: EdnProvide<'a, A> + EdnProvide<'a, B> + 'a, - E: Output, - A: Render + 'a, - B: Render + 'a, -{ +impl<'a, E: Output + 'a, T: EdnViewData<'a, E>> TryFromEdn<'a, T> for Bsp, RenderBox<'a, E>> { fn try_from_edn (s: &'a T, head: &EdnItem<&str>, tail: &'a [EdnItem<&str>]) -> Option { use EdnItem::*; 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/s"), [a, b]) => Self::s(s.get(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/w"), [a, b]) => Self::w(s.get(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/b"), [a, b]) => Self::b(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_content(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_content(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_content(a).expect("no a"), s.get(b).expect("no b")), _ => return None }) } diff --git a/output/src/edn_view.rs b/output/src/edn_view.rs index 8aadc130..0936848e 100644 --- a/output/src/edn_view.rs +++ b/output/src/edn_view.rs @@ -69,77 +69,59 @@ pub trait EdnViewData<'a, E: Output>: EdnProvide<'a, E::Unit> + EdnProvide<'a, Box + 'a>> { - fn get_bool (&'a self, item: &'a EdnItem<&str>) -> bool { - match &item { - Num(0) => false, - Num(_) => true, - Sym(":true") | Sym(":t") => true, - Sym(":false") | Sym(":f") => false, - _ => EdnProvide::get_or_fail(self, item) - } + fn get_bool (&'a self, item: &'a EdnItem<&str>) -> Option { + Some(match &item { + Sym(":false") | Sym(":f") | Num(0) => false, + Sym(":true") | Sym(":t") | Num(_) => true, + _ => return EdnProvide::get(self, item) + }) } - fn get_usize (&'a self, item: &'a EdnItem<&str>) -> usize { - match &item { Num(n) => *n, _ => EdnProvide::get_or_fail(self, item) } + fn get_usize (&'a self, item: &'a EdnItem<&str>) -> Option { + Some(match &item { Num(n) => *n, _ => return EdnProvide::get(self, item) }) } - fn get_unit (&'a self, item: &'a EdnItem<&str>) -> E::Unit { - match &item { Num(n) => (*n as u16).into(), _ => EdnProvide::get_or_fail(self, item) } + fn get_unit (&'a self, item: &'a EdnItem<&str>) -> Option { + 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 + 'a> where E: 'a { - match item { + fn get_content (&'a self, item: &'a EdnItem<&'a str>) -> Option + 'a>> where E: 'a { + Some(match item { Nil => Box::new(()), Exp(e) => if let [head, tail @ ..] = e.as_slice() { 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 { EdnProvide::get_or_fail(self, &item) }, _ => EdnProvide::get_or_fail(self, &item) - } + }) //panic!("no content") } } diff --git a/output/src/either.rs b/output/src/either.rs index f796da41..a58f7c33 100644 --- a/output/src/either.rs +++ b/output/src/either.rs @@ -6,13 +6,7 @@ impl Either { Self(Default::default(), c, a, b) } } -impl<'a, T, E, A, B> TryFromEdn<'a, T> for Either -where - T: EdnProvide<'a, bool> + EdnProvide<'a, B> + EdnProvide<'a, A> + 'a, - E: Output, - A: Render + 'a, - B: Render + 'a, -{ +impl<'a, E: Output + 'a, T: EdnViewData<'a, E>> TryFromEdn<'a, T> for Either, RenderBox<'a, E>> { fn try_from_edn (state: &'a T, head: &EdnItem<&str>, tail: &'a [EdnItem<&str>]) -> Option { use EdnItem::*; if let (Key("either"), [condition, content, alternative]) = (head, tail) { diff --git a/output/src/transform_xy.rs b/output/src/transform_xy.rs index c3e9c165..351ecb5c 100644 --- a/output/src/transform_xy.rs +++ b/output/src/transform_xy.rs @@ -27,20 +27,15 @@ macro_rules! transform_xy { $area } } - impl<'a, T, E, A> TryFromEdn<'a, T> for $Enum - where - T: EdnProvide<'a, A> + 'a, - E: Output, - A: Render + 'a - { + impl<'a, E: Output + 'a, T: EdnViewData<'a, E>> TryFromEdn<'a, T> for $Enum> { fn try_from_edn ( state: &'a T, head: &EdnItem<&str>, tail: &'a [EdnItem<&str>] ) -> Option { use EdnItem::*; Some(match (head, tail) { - (Key($x), [a]) => Self::x(state.get(a).expect("no content")), - (Key($y), [a]) => Self::y(state.get(a).expect("no content")), - (Key($xy), [a]) => Self::xy(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_content(a).expect("no content")), + (Key($xy), [a]) => Self::xy(state.get_content(a).expect("no content")), _ => return None }) } diff --git a/output/src/transform_xy_unit.rs b/output/src/transform_xy_unit.rs index 78c08730..486939be 100644 --- a/output/src/transform_xy_unit.rs +++ b/output/src/transform_xy_unit.rs @@ -41,29 +41,24 @@ macro_rules! transform_xy_unit { $layout.into() } } - impl<'a, T, E, A> TryFromEdn<'a, T> for $Enum - where - T: EdnProvide<'a, E::Unit> + EdnProvide<'a, A> + 'a, - E: Output, - A: Render + 'a, - { + impl<'a, E: Output + 'a, T: EdnViewData<'a, E>> TryFromEdn<'a, T> for $Enum> { fn try_from_edn ( state: &'a T, head: &EdnItem<&str>, tail: &'a [EdnItem<&str>] ) -> Option { use EdnItem::*; Some(match (head, tail) { (Key($x), [x, a]) => Self::x( - state.get(x).expect("no content"), - state.get(a).expect("no content"), + state.get_unit(x).expect("no x"), + state.get_content(a).expect("no content"), ), (Key($y), [y, a]) => Self::y( - state.get(y).expect("no content"), - state.get(a).expect("no content"), + state.get_unit(y).expect("no y"), + state.get_content(a).expect("no content"), ), (Key($xy), [x, y, a]) => Self::xy( - state.get(x).expect("no content"), - state.get(y).expect("no content"), - state.get(a).expect("no content"), + state.get_unit(x).expect("no x"), + state.get_unit(y).expect("no y"), + state.get_content(a).expect("no content"), ), _ => return None }) diff --git a/output/src/when.rs b/output/src/when.rs index 7ee96bb0..8971b107 100644 --- a/output/src/when.rs +++ b/output/src/when.rs @@ -6,12 +6,7 @@ impl When { Self(Default::default(), c, a) } } -impl<'a, T, E, A> TryFromEdn<'a, T> for When -where - T: EdnProvide<'a, bool> + EdnProvide<'a, A> + 'a, - E: Output, - A: Render + 'a -{ +impl<'a, E: Output + 'a, T: EdnViewData<'a, E>> TryFromEdn<'a, T> for When> { fn try_from_edn ( state: &'a T, head: &EdnItem<&str>, tail: &'a [EdnItem<&str>] ) -> Option { @@ -19,8 +14,8 @@ where if let (Key("when"), [condition, content]) = (head, tail) { Some(Self( Default::default(), - state.get(condition).expect("when: no condition"), - state.get(content).expect("when: no content") + state.get_bool(condition).expect("when: no condition"), + state.get_content(content).expect("when: no content") )) } else { None diff --git a/tek/src/arranger-view.edn b/tek/src/arranger-view.edn index 39dbed09..1d1ac948 100644 --- a/tek/src/arranger-view.edn +++ b/tek/src/arranger-view.edn @@ -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)))))))