mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2025-12-06 11:46:42 +01:00
0.8.0: add expose! and impose! macros
This commit is contained in:
parent
34295570a2
commit
1ad2d43d5a
3 changed files with 41 additions and 8 deletions
|
|
@ -10,6 +10,7 @@ pub(crate) use self::ParseError::*;
|
|||
pub(crate) use konst::iter::{ConstIntoIter, IsIteratorKind};
|
||||
pub(crate) use konst::string::{split_at, str_range, char_indices};
|
||||
pub(crate) use std::fmt::Debug;
|
||||
|
||||
/// Static iteration helper.
|
||||
#[macro_export] macro_rules! iterate {
|
||||
($expr:expr => $arg: pat => $body:expr) => {
|
||||
|
|
@ -20,6 +21,7 @@ pub(crate) use std::fmt::Debug;
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Implement the const iterator pattern.
|
||||
#[macro_export] macro_rules! const_iter {
|
||||
($(<$l:lifetime>)?|$self:ident: $Struct:ty| => $Item:ty => $expr:expr) => {
|
||||
|
|
@ -34,6 +36,37 @@ pub(crate) use std::fmt::Debug;
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[macro_export] macro_rules! expose {
|
||||
($([$self:ident:$State:ty] { $($Type:ty => { $($pat:pat => $expr:expr),* $(,)? })* })*) => {
|
||||
$(expose!(@impl [$self: $State] { $($Type => { $($pat => $expr),* })* });)*
|
||||
};
|
||||
(@impl [$self:ident:$State:ty] { $($Type:ty => { $($pat:pat => $expr:expr),* $(,)? })* }) => {
|
||||
$(expose!(@type $Type [$self: $State] => { $($pat => $expr),* });)*
|
||||
};
|
||||
(@type bool [$self:ident: $State:ty] => { $($pat:pat => $expr:expr),* $(,)? }) => {
|
||||
provide_bool!(bool: |$self: $State| { $($pat => $expr),* });
|
||||
};
|
||||
(@type isize [$self:ident: $State:ty] => { $($pat:pat => $expr:expr),* $(,)? }) => {
|
||||
provide_num!(u16: |$self: $State| { $($pat => $expr),* });
|
||||
};
|
||||
(@type usize [$self:ident: $State:ty] => { $($pat:pat => $expr:expr),* $(,)? }) => {
|
||||
provide_num!(usize: |$self: $State| { $($pat => $expr),* });
|
||||
};
|
||||
(@type isize [$self:ident: $State:ty] => { $($pat:pat => $expr:expr),* $(,)? }) => {
|
||||
provide_num!(isize: |$self: $State| { $($pat => $expr),* });
|
||||
};
|
||||
(@type $Type:ty [$self:ident: $State:ty] => { $($pat:pat => $expr:expr),* $(,)? }) => {
|
||||
provide!($Type: |$self: $State| { $($pat => $expr),* });
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export] macro_rules! impose {
|
||||
([$self:ident:$Struct:ty] { $($Command:ty => $variants:tt)* }) => {
|
||||
$(atom_command!($Command: |$self: $Struct| $variants);)*
|
||||
};
|
||||
}
|
||||
|
||||
//#[cfg(test)] #[test] fn test_examples () -> Result<(), ParseError> {
|
||||
//// Let's pretend to render some view.
|
||||
//let source = include_str!("../../tek/src/view_arranger.edn");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue