mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2025-12-06 03:36:42 +01:00
proc, view: fix usage of builtins
This commit is contained in:
parent
776cea6f1b
commit
7516517078
4 changed files with 83 additions and 78 deletions
|
|
@ -1,9 +1,10 @@
|
|||
//mod reduce; pub use self::reduce::*;
|
||||
mod align; pub use self::align::*;
|
||||
mod bsp; pub use self::bsp::*;
|
||||
mod cond; pub use self::cond::*;
|
||||
mod either; pub use self::either::*;
|
||||
mod map; pub use self::map::*;
|
||||
mod memo; pub use self::memo::*;
|
||||
mod stack; pub use self::stack::*;
|
||||
//mod reduce; pub use self::reduce::*;
|
||||
mod thunk; pub use self::thunk::*;
|
||||
mod transform; pub use self::transform::*;
|
||||
mod when; pub use self::when::*;
|
||||
|
|
|
|||
38
output/src/ops/either.rs
Normal file
38
output/src/ops/either.rs
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
use crate::*;
|
||||
|
||||
/// Show one item if a condition is true and another if the condition is false
|
||||
pub struct Either<A, B>(pub bool, pub A, pub B);
|
||||
impl<A, B> Either<A, B> {
|
||||
/// Create a ternary condition.
|
||||
pub const fn new (c: bool, a: A, b: B) -> Self {
|
||||
Self(c, a, b)
|
||||
}
|
||||
}
|
||||
#[cfg(feature = "dsl")]
|
||||
impl<A, B, T: Dsl<bool> + Dsl<A> + Dsl<B>> Namespace<T> for Either<A, B> {
|
||||
fn take_from <'source> (
|
||||
state: &T,
|
||||
token: &mut TokenIter<'source>
|
||||
) -> Perhaps<Self> {
|
||||
if let Some(Token { value: Value::Key("either"), .. }) = token.peek() {
|
||||
let base = token.clone();
|
||||
let _ = token.next().unwrap();
|
||||
return Ok(Some(Self(
|
||||
state.take_or_fail(token, "either: no condition")?,
|
||||
state.take_or_fail(token, "either: no content 1")?,
|
||||
state.take_or_fail(token, "either: no content 2")?,
|
||||
)))
|
||||
}
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
impl<E: Output, A: Render<E>, B: Render<E>> Content<E> for Either<A, B> {
|
||||
fn layout (&self, to: E::Area) -> E::Area {
|
||||
let Self(cond, a, b) = self;
|
||||
if *cond { a.layout(to) } else { b.layout(to) }
|
||||
}
|
||||
fn render (&self, to: &mut E) {
|
||||
let Self(cond, a, b) = self;
|
||||
if *cond { a.render(to) } else { b.render(to) }
|
||||
}
|
||||
}
|
||||
|
|
@ -8,15 +8,6 @@ impl<A> When<A> {
|
|||
Self(c, a)
|
||||
}
|
||||
}
|
||||
|
||||
/// Show one item if a condition is true and another if the condition is false
|
||||
pub struct Either<A, B>(pub bool, pub A, pub B);
|
||||
impl<A, B> Either<A, B> {
|
||||
/// Create a ternary condition.
|
||||
pub const fn new (c: bool, a: A, b: B) -> Self {
|
||||
Self(c, a, b)
|
||||
}
|
||||
}
|
||||
#[cfg(feature = "dsl")]
|
||||
impl<A, T: Dsl<bool> + Dsl<A>> Namespace<T> for When<A> {
|
||||
fn take_from <'source> (
|
||||
|
|
@ -55,31 +46,3 @@ impl<E: Output, A: Render<E>> Content<E> for When<A> {
|
|||
if *cond { item.render(to) }
|
||||
}
|
||||
}
|
||||
#[cfg(feature = "dsl")]
|
||||
impl<A, B, T: Dsl<bool> + Dsl<A> + Dsl<B>> Namespace<T> for Either<A, B> {
|
||||
fn take_from <'source> (
|
||||
state: &T,
|
||||
token: &mut TokenIter<'source>
|
||||
) -> Perhaps<Self> {
|
||||
if let Some(Token { value: Value::Key("either"), .. }) = token.peek() {
|
||||
let base = token.clone();
|
||||
let _ = token.next().unwrap();
|
||||
return Ok(Some(Self(
|
||||
state.take_or_fail(token, "either: no condition")?,
|
||||
state.take_or_fail(token, "either: no content 1")?,
|
||||
state.take_or_fail(token, "either: no content 2")?,
|
||||
)))
|
||||
}
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
impl<E: Output, A: Render<E>, B: Render<E>> Content<E> for Either<A, B> {
|
||||
fn layout (&self, to: E::Area) -> E::Area {
|
||||
let Self(cond, a, b) = self;
|
||||
if *cond { a.layout(to) } else { b.layout(to) }
|
||||
}
|
||||
fn render (&self, to: &mut E) {
|
||||
let Self(cond, a, b) = self;
|
||||
if *cond { a.render(to) } else { b.render(to) }
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue