mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-08 04:36:45 +01:00
EdnProvide
This commit is contained in:
parent
794d4210c6
commit
fc06fb863b
7 changed files with 126 additions and 61 deletions
34
input/src/edn_command.rs
Normal file
34
input/src/edn_command.rs
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
use crate::*;
|
||||
use EdnItem::*;
|
||||
|
||||
#[macro_export] macro_rules! edn_command {
|
||||
($Command:ty : |$state:ident:$State:ty| {
|
||||
$(($key:literal [$($arg:ident : $type:ty),*] $command:expr))*
|
||||
}) => {
|
||||
impl EdnCommand<$State> for $Command {
|
||||
fn from_edn <'a> ($state: &$State, head: &EdnItem<&str>, tail: &'a [EdnItem<String>]) -> Self {
|
||||
match (head, tail) {
|
||||
$((EdnItem::Key($key), [$($arg),*]) => {
|
||||
$(let $arg: $type = EdnProvide::<$type>::get_or_fail($state, $arg);)*
|
||||
$command
|
||||
},)*
|
||||
_ => panic!("no such command")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Turns an EDN symbol sequence into a command enum variant.
|
||||
pub trait EdnCommand<C>: Command<C> {
|
||||
fn from_edn <'a> (state: &C, head: &EdnItem<&str>, tail: &'a [EdnItem<String>]) -> Self;
|
||||
fn get_isize (state: &C, item: &EdnItem<&str>) -> Option<isize> {
|
||||
None
|
||||
}
|
||||
fn get_usize (state: &C, item: &EdnItem<&str>) -> Option<usize> {
|
||||
None
|
||||
}
|
||||
fn get_bool (state: &C, item: &EdnItem<&str>) -> Option<usize> {
|
||||
None
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue