mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2025-12-07 04:06:48 +01:00
dsl: use only Dsl trait
This commit is contained in:
parent
3bc739328e
commit
90f5699fff
11 changed files with 430 additions and 406 deletions
|
|
@ -21,30 +21,40 @@ impl<E: Output, A: Content<E>, B: Content<E>> Content<E> for Bsp<A, B> {
|
|||
}
|
||||
}
|
||||
#[cfg(feature = "dsl")]
|
||||
try_from_expr!(<'source, 'state, E>: Bsp<RenderBox<'state, E>, RenderBox<'state, E>>: |state, iter| {
|
||||
if let Some(Token { value: Value::Key(key), .. }) = iter.peek() {
|
||||
match key {
|
||||
"bsp/n"|"bsp/s"|"bsp/e"|"bsp/w"|"bsp/a"|"bsp/b" => {
|
||||
let original = iter.clone();
|
||||
let _ = iter.next().unwrap();
|
||||
let c1 = iter.next().unwrap_or_else(||panic!("no content1 specified: {original:?}"));
|
||||
let c2 = iter.next().unwrap_or_else(||panic!("no content2 specified: {original:?}"));
|
||||
let c1 = state.get_content(&c1.value).expect("no content1 provided");
|
||||
let c2 = state.get_content(&c2.value).expect("no content2 provided");
|
||||
return Some(match key {
|
||||
"bsp/n" => Self::n(c1, c2),
|
||||
"bsp/s" => Self::s(c1, c2),
|
||||
"bsp/e" => Self::e(c1, c2),
|
||||
"bsp/w" => Self::w(c1, c2),
|
||||
"bsp/a" => Self::a(c1, c2),
|
||||
"bsp/b" => Self::b(c1, c2),
|
||||
_ => unreachable!(),
|
||||
})
|
||||
},
|
||||
_ => return None
|
||||
}
|
||||
impl<'state, E: Output + 'state, T: ViewContext<'state, E>>
|
||||
FromDsl<'state, T> for Bsp<RenderBox<'state, E>, RenderBox<'state, E>> {
|
||||
fn take_from <'source: 'state> (state: &'state T, iter: &mut TokenIter<'source>) -> Perhaps<Self> {
|
||||
Ok(if let Some(Token {
|
||||
value: Value::Key("bsp/n"|"bsp/s"|"bsp/e"|"bsp/w"|"bsp/a"|"bsp/b"),
|
||||
..
|
||||
}) = iter.peek() {
|
||||
let base = iter.clone();
|
||||
return Ok(Some(match iter.next() {
|
||||
Some(Token { value: Value::Key("bsp/n"), .. }) =>
|
||||
Self::n(state.get_content_or_fail(iter)?,
|
||||
state.get_content_or_fail(iter)?),
|
||||
Some(Token { value: Value::Key("bsp/s"), .. }) =>
|
||||
Self::s(state.get_content_or_fail(iter)?,
|
||||
state.get_content_or_fail(iter)?),
|
||||
Some(Token { value: Value::Key("bsp/e"), .. }) =>
|
||||
Self::e(state.get_content_or_fail(iter)?,
|
||||
state.get_content_or_fail(iter)?),
|
||||
Some(Token { value: Value::Key("bsp/w"), .. }) =>
|
||||
Self::w(state.get_content_or_fail(iter)?,
|
||||
state.get_content_or_fail(iter)?),
|
||||
Some(Token { value: Value::Key("bsp/a"), .. }) =>
|
||||
Self::a(state.get_content_or_fail(iter)?,
|
||||
state.get_content_or_fail(iter)?),
|
||||
Some(Token { value: Value::Key("bsp/b"), .. }) =>
|
||||
Self::b(state.get_content_or_fail(iter)?,
|
||||
state.get_content_or_fail(iter)?),
|
||||
_ => unreachable!(),
|
||||
}))
|
||||
} else {
|
||||
None
|
||||
})
|
||||
}
|
||||
});
|
||||
}
|
||||
impl<A, B> Bsp<A, B> {
|
||||
#[inline] pub const fn n (a: A, b: B) -> Self { Self(North, a, b) }
|
||||
#[inline] pub const fn s (a: A, b: B) -> Self { Self(South, a, b) }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue