gorrosion_gtp/command/
mod.rs1use super::data;
10use super::gtp_type::*;
11use super::input;
12
13#[derive(Debug)]
25pub struct Command {
26 name: String,
27 arguments: <List as data::Data>::Type,
28 response: <MultilineList as data::Data>::Type,
29}
30
31use data::alternatives::Type as Alt;
32use data::collection::Type as Cl;
33use data::list::Type as Lst;
34use data::multiline_list::Type as ML;
35use data::simple_entity::Type as SE;
36
37macro_rules! type_description {
38 ( none ) => {
39 Cl::Empty
40 };
41 ( int ) => {
42 SE::Int
43 };
44 ( float ) => {
45 SE::Float
46 };
47 ( string ) => {
48 SE::String
49 };
50 ( vertex ) => {
51 SE::Vertex
52 };
53 ( color ) => {
54 SE::Color
55 };
56 ( move ) => {
57 SE::Motion
58 };
59 ( boolean ) => {
60 SE::Boolean
61 };
62 ( { } ) => {
63 Cl::Empty
64 };
65 ( { $h:tt $( $t:tt ) * } ) => {
66 Cl::Collection(
67 type_description!($h),
68 Box::new(type_description!( { $($t)* } ))
69 )
70 };
71 ( $f:tt | $s:tt ) => {
72 <Alt as From<_>>::from((
73 type_description!($f),
74 type_description!($s),
75 ))
76 };
77 ( $t:tt * ) => {
78 <Lst as From<_>>::from(type_description!($t))
79 };
80 ( $t:tt & ) => {
81 <ML as From<_>>::from(type_description!($t))
82 };
83 ( $t:tt * & ) => {
84 <ML as From<_>>::from(type_description!($t *))
85 };
86}
87
88#[rustfmt::skip]
90macro_rules! str_to_gtp {
91 ( $e:expr ) => {{
92 let s = $e;
93 let i = input::engine::Input::from(s.as_bytes());
94 let t = data::string::Type::default();
95 let (_, r) = <String as data::Data>::parse(i, &t).unwrap();
96 r
97 }};
98}
99
100macro_rules! command {
122 ($name:expr => ($($args:tt)*) -> ($($resp:tt)*)) => {{
123 let name = str_to_gtp!($name);
124 let arguments = From::from(type_description!($($args)*));
125 let response = From::from(type_description!($($resp)*));
126 Command { name, arguments, response }
127 }};
128}
129
130pub mod administrative;
131pub mod core_play;
132pub mod setup;
133pub mod tournament;
134pub mod regression;
135pub mod debug;