mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 19:56:42 +01:00
special case numeric literals, and away we go!
This commit is contained in:
parent
228b4bb47c
commit
dc45edf7e0
7 changed files with 114 additions and 133 deletions
|
|
@ -1,6 +1,15 @@
|
|||
use crate::*;
|
||||
/// Implement `EdnProvide` for a type and context
|
||||
#[macro_export] macro_rules! edn_provide {
|
||||
// Provide a value to the EDN template
|
||||
($type:ty:|$self:ident:$State:ty|{ $($pat:pat => $expr:expr),* $(,)? }) => {
|
||||
impl<'a> EdnProvide<'a, $type> for $State {
|
||||
fn get <S: AsRef<str>> (&'a $self, edn: &'a EdnItem<S>) -> Option<$type> {
|
||||
Some(match edn.to_ref() { $(EdnItem::Sym($pat) => $expr,)* _ => return None })
|
||||
}
|
||||
}
|
||||
};
|
||||
// Provide a value more generically
|
||||
($lt:lifetime: $type:ty:|$self:ident:$State:ty|{ $($pat:pat => $expr:expr),* $(,)? }) => {
|
||||
impl<$lt> EdnProvide<$lt, $type> for $State {
|
||||
fn get <S: AsRef<str>> (&$lt $self, edn: &$lt EdnItem<S>) -> Option<$type> {
|
||||
|
|
@ -8,10 +17,15 @@ use crate::*;
|
|||
}
|
||||
}
|
||||
};
|
||||
($type:ty:|$self:ident:$State:ty|{ $($pat:pat => $expr:expr),* $(,)? }) => {
|
||||
// Provide a value that may also be a numeric literal in the EDN
|
||||
(# $type:ty:|$self:ident:$State:ty|{ $($pat:pat => $expr:expr),* $(,)? }) => {
|
||||
impl<'a> EdnProvide<'a, $type> for $State {
|
||||
fn get <S: AsRef<str>> (&'a $self, edn: &'a EdnItem<S>) -> Option<$type> {
|
||||
Some(match edn.to_ref() { $(EdnItem::Sym($pat) => $expr,)* _ => return None })
|
||||
Some(match edn.to_ref() {
|
||||
$(EdnItem::Sym($pat) => $expr,)*
|
||||
EdnItem::Num(n) => n as $type,
|
||||
_ => return None
|
||||
})
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue