mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2025-12-06 19:56:44 +01:00
wip: finally, informative type errors from the macro
Some checks failed
/ build (push) Has been cancelled
Some checks failed
/ build (push) Has been cancelled
fixin mixin
This commit is contained in:
parent
abc87d3234
commit
583660c330
10 changed files with 152 additions and 205 deletions
|
|
@ -36,33 +36,36 @@ pub enum Alignment { #[default] Center, X, Y, NW, N, NE, E, SE, S, SW, W }
|
|||
pub struct Align<A>(Alignment, A);
|
||||
|
||||
#[cfg(feature = "dsl")]
|
||||
from_dsl!(@a: Align<A>: |state, iter|if let Some(Token { value: Value::Key(key), .. }) = iter.peek() {
|
||||
match key {
|
||||
"align/c"|"align/x"|"align/y"|
|
||||
"align/n"|"align/s"|"align/e"|"align/w"|
|
||||
"align/nw"|"align/sw"|"align/ne"|"align/se" => {
|
||||
let _ = iter.next().unwrap();
|
||||
let content = state.take_or_fail(&mut iter.clone(), ||"expected content")?;
|
||||
return Ok(Some(match key {
|
||||
"align/c" => Self::c(content),
|
||||
"align/x" => Self::x(content),
|
||||
"align/y" => Self::y(content),
|
||||
"align/n" => Self::n(content),
|
||||
"align/s" => Self::s(content),
|
||||
"align/e" => Self::e(content),
|
||||
"align/w" => Self::w(content),
|
||||
"align/nw" => Self::nw(content),
|
||||
"align/ne" => Self::ne(content),
|
||||
"align/sw" => Self::sw(content),
|
||||
"align/se" => Self::se(content),
|
||||
_ => unreachable!()
|
||||
}))
|
||||
},
|
||||
_ => return Ok(None)
|
||||
impl<'n, State: Receive<A>, A: 'n> Provide<'n, State> for Align<A> {
|
||||
fn provide <'source> (state: &State, words: &mut TokenIter<'source>) -> Perhaps<Self> {
|
||||
if let Some(Token { value: Value::Key(key), .. }) = words.peek() {
|
||||
match key {
|
||||
"align/c"|"align/x"|"align/y"|
|
||||
"align/n"|"align/s"|"align/e"|"align/w"|
|
||||
"align/nw"|"align/sw"|"align/ne"|"align/se" => {
|
||||
let _ = words.next().unwrap();
|
||||
let content = state.receive_or_fail(&mut words.clone(), ||"expected content")?;
|
||||
return Ok(Some(match key {
|
||||
"align/c" => Self::c(content),
|
||||
"align/x" => Self::x(content),
|
||||
"align/y" => Self::y(content),
|
||||
"align/n" => Self::n(content),
|
||||
"align/s" => Self::s(content),
|
||||
"align/e" => Self::e(content),
|
||||
"align/w" => Self::w(content),
|
||||
"align/nw" => Self::nw(content),
|
||||
"align/ne" => Self::ne(content),
|
||||
"align/sw" => Self::sw(content),
|
||||
"align/se" => Self::se(content),
|
||||
_ => unreachable!()
|
||||
}))
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
Ok(None)
|
||||
}
|
||||
} else {
|
||||
Ok(None)
|
||||
});
|
||||
}
|
||||
|
||||
impl<A> Align<A> {
|
||||
#[inline] pub const fn c (a: A) -> Self { Self(Alignment::Center, a) }
|
||||
|
|
|
|||
|
|
@ -21,24 +21,28 @@ impl<E: Output, A: Content<E>, B: Content<E>> Content<E> for Bsp<A, B> {
|
|||
}
|
||||
}
|
||||
#[cfg(feature = "dsl")]
|
||||
impl<State: Dsl<A> + Dsl<B> + std::fmt::Debug, A, B> Namespace<State> for Bsp<A, B> {
|
||||
fn take_from <'source> (state: &State, words: &mut TokenIter<'source>) -> Perhaps<Self> {
|
||||
impl<'n, State: Receive<A> + Receive<B>, A: 'n, B: 'n> Provide<'n, State> for Bsp<A, B> {
|
||||
fn provide <'source> (state: &State, words: &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"),
|
||||
..
|
||||
}) = words.peek() {
|
||||
let base = words.clone();
|
||||
let a: A = state.take_or_fail(words, ||"expected content 1")?;
|
||||
let b: B = state.take_or_fail(words, ||"expected content 2")?;
|
||||
return Ok(Some(match words.next() {
|
||||
Some(Token { value: Value::Key("bsp/n"), .. }) => Self::n(a, b),
|
||||
Some(Token { value: Value::Key("bsp/s"), .. }) => Self::s(a, b),
|
||||
Some(Token { value: Value::Key("bsp/e"), .. }) => Self::e(a, b),
|
||||
Some(Token { value: Value::Key("bsp/w"), .. }) => Self::w(a, b),
|
||||
Some(Token { value: Value::Key("bsp/a"), .. }) => Self::a(a, b),
|
||||
Some(Token { value: Value::Key("bsp/b"), .. }) => Self::b(a, b),
|
||||
_ => unreachable!(),
|
||||
}))
|
||||
if let Value::Key(key) = words.next().unwrap().value() {
|
||||
let base = words.clone();
|
||||
let a: A = state.receive_or_fail(words, ||"bsp: expected content 1")?;
|
||||
let b: B = state.receive_or_fail(words, ||"bsp: expected content 2")?;
|
||||
return Ok(Some(match key {
|
||||
"bsp/n" => Self::n(a, b),
|
||||
"bsp/s" => Self::s(a, b),
|
||||
"bsp/e" => Self::e(a, b),
|
||||
"bsp/w" => Self::w(a, b),
|
||||
"bsp/a" => Self::a(a, b),
|
||||
"bsp/b" => Self::b(a, b),
|
||||
_ => unreachable!(),
|
||||
}))
|
||||
} else {
|
||||
unreachable!()
|
||||
}
|
||||
} else {
|
||||
None
|
||||
})
|
||||
|
|
|
|||
|
|
@ -9,18 +9,15 @@ impl<A, B> Either<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> {
|
||||
impl<'n, State: Receive<bool> + Receive<A> + Receive<B>, A: 'n, B: 'n> Provide<'n, State> for Either<A, B> {
|
||||
fn provide <'source> (state: &State, 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")?,
|
||||
state.receive_or_fail(token, ||"either: no condition")?,
|
||||
state.receive_or_fail(token, ||"either: no content 1")?,
|
||||
state.receive_or_fail(token, ||"either: no content 2")?,
|
||||
)))
|
||||
}
|
||||
Ok(None)
|
||||
|
|
|
|||
|
|
@ -33,19 +33,19 @@ macro_rules! transform_xy {
|
|||
#[inline] pub const fn xy (item: A) -> Self { Self::XY(item) }
|
||||
}
|
||||
#[cfg(feature = "dsl")]
|
||||
impl<A, T: Dsl<A>> Namespace<T> for $Enum<A> {
|
||||
fn take_from <'source> (
|
||||
state: &T, token: &mut TokenIter<'source>
|
||||
) -> Perhaps<Self> {
|
||||
impl<'n, A: 'n, T: Receive<A>> Provide<'n, T> for $Enum<A> {
|
||||
fn provide <'source> (state: &T, token: &mut TokenIter<'source>)
|
||||
-> Perhaps<Self>
|
||||
{
|
||||
if let Some(Token { value: Value::Key(k), .. }) = token.peek() {
|
||||
let mut base = token.clone();
|
||||
return Ok(Some(match token.next() {
|
||||
Some(Token{value:Value::Key($x),..}) =>
|
||||
Self::x(state.take_or_fail(token, ||"x: no content")?),
|
||||
Self::x(state.receive_or_fail(token, ||"x: no content")?),
|
||||
Some(Token{value:Value::Key($y),..}) =>
|
||||
Self::y(state.take_or_fail(token, ||"y: no content")?),
|
||||
Self::y(state.receive_or_fail(token, ||"y: no content")?),
|
||||
Some(Token{value:Value::Key($xy),..}) =>
|
||||
Self::xy(state.take_or_fail(token, ||"xy: no content")?),
|
||||
Self::xy(state.receive_or_fail(token, ||"xy: no content")?),
|
||||
_ => unreachable!()
|
||||
}))
|
||||
}
|
||||
|
|
@ -79,25 +79,25 @@ macro_rules! transform_xy_unit {
|
|||
#[inline] pub const fn xy (x: U, y: U, item: A) -> Self { Self::XY(x, y, item) }
|
||||
}
|
||||
#[cfg(feature = "dsl")]
|
||||
impl<A, U: Coordinate, T: Dsl<A> + Dsl<U>> Namespace<T> for $Enum<U, A> {
|
||||
fn take_from <'source> (
|
||||
impl<'n, A: 'n, U: Coordinate + 'n, T: Receive<A> + Receive<U>> Provide<'n, T> for $Enum<U, A> {
|
||||
fn provide <'source> (
|
||||
state: &T, token: &mut TokenIter<'source>
|
||||
) -> Perhaps<Self> {
|
||||
Ok(if let Some(Token { value: Value::Key($x|$y|$xy), .. }) = token.peek() {
|
||||
let mut base = token.clone();
|
||||
Some(match token.next() {
|
||||
Some(Token { value: Value::Key($x), .. }) => Self::x(
|
||||
state.take_or_fail(token, ||"x: no unit")?,
|
||||
state.take_or_fail(token, ||"x: no content")?,
|
||||
state.receive_or_fail(token, ||"x: no unit")?,
|
||||
state.receive_or_fail(token, ||"x: no content")?,
|
||||
),
|
||||
Some(Token { value: Value::Key($y), .. }) => Self::y(
|
||||
state.take_or_fail(token, ||"y: no unit")?,
|
||||
state.take_or_fail(token, ||"y: no content")?,
|
||||
state.receive_or_fail(token, ||"y: no unit")?,
|
||||
state.receive_or_fail(token, ||"y: no content")?,
|
||||
),
|
||||
Some(Token { value: Value::Key($x), .. }) => Self::xy(
|
||||
state.take_or_fail(token, ||"xy: no unit x")?,
|
||||
state.take_or_fail(token, ||"xy: no unit y")?,
|
||||
state.take_or_fail(token, ||"xy: no content")?
|
||||
state.receive_or_fail(token, ||"xy: no unit x")?,
|
||||
state.receive_or_fail(token, ||"xy: no unit y")?,
|
||||
state.receive_or_fail(token, ||"xy: no content")?
|
||||
),
|
||||
_ => unreachable!(),
|
||||
})
|
||||
|
|
|
|||
|
|
@ -9,19 +9,17 @@ impl<A> When<A> {
|
|||
}
|
||||
}
|
||||
#[cfg(feature = "dsl")]
|
||||
impl<A, T: Dsl<bool> + Dsl<A>> Namespace<T> for When<A> {
|
||||
fn take_from <'source> (
|
||||
state: &T,
|
||||
token: &mut TokenIter<'source>
|
||||
) -> Perhaps<Self> {
|
||||
impl<'n, State: Receive<bool> + Receive<A>, A: 'n> Provide<'n, State> for When<A> {
|
||||
fn provide <'source> (state: &State, words: &mut TokenIter<'source>) -> Perhaps<Self> {
|
||||
Ok(if let Some(Token {
|
||||
value: Value::Key("when"),
|
||||
..
|
||||
}) = token.peek() {
|
||||
let base = token.clone();
|
||||
}) = words.peek() {
|
||||
let _ = words.next();
|
||||
let base = words.clone();
|
||||
return Ok(Some(Self(
|
||||
state.take_or_fail(token, ||"cond: no condition")?,
|
||||
state.take_or_fail(token, ||"cond: no content")?,
|
||||
state.receive_or_fail(words, ||"cond: no condition")?,
|
||||
state.receive_or_fail(words, ||"cond: no content")?,
|
||||
)))
|
||||
} else {
|
||||
None
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue