1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
use std::collections::HashMap;

use serde::Serialize;
use serde::de::DeserializeOwned;
use serde_json;

use crate::node_runner::NodeRunner;
use crate::node_token::NodeToken;

pub trait Node {
    fn node_step(&mut self, runner: NodeRunner) -> String;
}

impl<T> Node for Vec<T> where T: Node + Serialize + DeserializeOwned + Default {
    fn node_step(&mut self, mut runner: NodeRunner) -> String {
        match runner.step() {
            NodeToken::ChainIndex (index) => {
                let length = self.len();
                match self.get_mut(index) {
                    Some (item) => item.node_step(runner),
                    None => {
                        return match length {
                             0 => format!("Used index {} on an empty vector", index),
                             1 => format!("Used index {} on a vector of size 1 (try 0)", index),
                             _ => format!("Used index {} on a vector of size {} (try a value between 0-{})", index, length, length-1)
                        }
                    }
                }
            }
            NodeToken::ChainAll => {
                let mut combined = String::from("|");
                for item in self {
                    combined.push_str(item.node_step(runner.clone()).as_ref());
                    combined.push('|');
                }
                combined
            }
            NodeToken::ChainProperty (ref s) if s == "length" => { self.len().node_step(runner) } // TODO: yeah this should really be a command not a property
            NodeToken::Get => {
                serde_json::to_string_pretty(self).unwrap()
            }
            NodeToken::Set (value) => {
                match serde_json::from_str(&value) {
                    Ok(result) => {
                        *self = result;
                        String::from("")
                    }
                    Err(err) => {
                        format!("vector set error: {}", err)
                    }
                }
            }
            NodeToken::InsertIndex (index) => {
                let max_index = self.len();
                if index > max_index {
                    format!("Tried to insert at index {} on a vector of size {} (try a value between 0-{})", index, max_index, max_index)
                }
                else {
                    self.insert(index, T::default());
                    String::new()
                }
            }
            NodeToken::RemoveIndex (index) => {
                let max_index = self.len() - 1;
                if index > max_index {
                    format!("Tried to remove the value at index {} on a vector of size {} (try a value between 0-{})", index, self.len(), max_index)
                }
                else {
                    self.remove(index);
                    String::new()
                }
            }
            NodeToken::SetDefault => {
                *self = vec!();
                String::new()
            }
            NodeToken::Help => {
                String::from(r#"
Vector Help

Commands:
*   help    - display this help
*   get     - display JSON
*   set     - set to JSON
*   insert  - create a new element
*   remove  - remove an element
*   reset   - reset to empty vector

Accessors:
*   [index] - access item at index
*   .length - display number of items"#)
            }
            action => { format!("vector cannot '{:?}'", action) }
        }
    }
}

impl<T> Node for HashMap<String, T> where T: Node + Serialize + DeserializeOwned + Default {
    fn node_step(&mut self, mut runner: NodeRunner) -> String {
        match runner.step() {
            NodeToken::ChainKey (key) => {
                let length = self.len();
                match self.get_mut(&key) {
                    Some (item) => { return item.node_step(runner) }
                    None        => { }
                }
                match length {
                     0 => {
                        format!("Used key '{}' on an empty map.", key)
                     }
                     _ => {
                        format!("Used key '{}' on a map that does not contain it. Try one of: {}", key, format_keys(self))
                    }
                }
            }
            NodeToken::ChainAll => {
                let mut combined = String::from("|");
                let mut pairs: Vec<_> = self.iter_mut().collect();
                pairs.sort_by_key(|x| x.0);
                for (_, item) in pairs {
                    combined.push_str(item.node_step(runner.clone()).as_ref());
                    combined.push('|');
                }
                combined
            }
            NodeToken::GetKeys => {
                format_keys(self)
            }
            NodeToken::ChainProperty (ref s) if s == "length" => { self.len().node_step(runner) } // TODO: yeah this should really be a command not a property
            NodeToken::Get => {
                serde_json::to_string_pretty(self).unwrap()
            }
            NodeToken::Set (value) => {
                match serde_json::from_str(&value) {
                    Ok(result) => {
                        *self = result;
                        String::from("")
                    }
                    Err(err) => {
                        format!("map set error: {}", err)
                    }
                }
            }
            NodeToken::InsertKey (key) => {
                if self.contains_key(&key) {
                    format!("Tried to insert key '{}' on a map that already contains it. Current keys: {}", key, format_keys(self))
                }
                else {
                    self.insert(key, T::default());
                    String::new()
                }
            }
            NodeToken::RemoveKey (key) => {
                if let None = self.remove(&key) {
                    format!("Tried to remove key '{}' on a map that doesnt contain it. Current keys: {}", key, format_keys(self))
                }
                else {
                    String::new()
                }
            }
            NodeToken::SetDefault => {
                *self = HashMap::new();
                String::new()
            }
            NodeToken::Help => {
                String::from(r#"
Map Help

Commands:
*   help    - display this help
*   get     - display JSON
*   getkeys - display keys
*   set     - set to JSON
*   insert  - create a new element
*   remove  - remove an element
*   reset   - reset to empty map

Accessors:
*   [key]   - access item at the string key
*   .length - display number of items"#)
            }
            action => { format!("map cannot '{:?}'", action) }
        }
    }
}

fn format_keys<T>(map: &HashMap<String, T>) -> String {
    let mut key_list: Vec<String> = map.keys().map(|x| format!("'{}'", x)).collect();
    key_list.sort();
    key_list.join(", ")
}

macro_rules! tuple_node {
    ( $( $indexes:tt $types:ident ),* ) => {
        impl <$( $types ),*> Node for ($( $types, )*) where $( $types: Node + Serialize + DeserializeOwned),* {
            fn node_step(&mut self, mut runner: NodeRunner) -> String {
                let name = stringify!{ ($( $types, )*) };
                match runner.step() {
                    NodeToken::ChainIndex (index) => {
                        match index {
                            $(
                                $indexes => self.$indexes.node_step(runner),
                            )*
                            _ => format!("Used index {} on a {}", index, name)
                        }
                    }
                    NodeToken::ChainAll => {
                        let mut combined = String::from("|");
                        $(
                            combined.push_str(self.$indexes.node_step(runner.clone()).as_ref());
                            combined.push('|');
                        )*
                        combined
                    }
                    NodeToken::Get => {
                        serde_json::to_string_pretty(self).unwrap()
                    }
                    NodeToken::Set (value) => {
                        match serde_json::from_str(&value) {
                            Ok (result) => {
                                *self = result;
                                String::from("")
                            }
                            Err (err) => {
                                format!("{} set error: {}", name, err)
                            }
                        }
                    }
                    NodeToken::Help => {
                        String::from(r#"
Tuple Help

Commands:
*   help - display this help
*   get  - display JSON
*   set  - set to JSON

Accessors:
*   [index] - access item at index"#)
                    }
                    action => { format!("{} cannot '{:?}'", name, action) }
                }
            }
        }
    }
}

tuple_node!(0 T0);
tuple_node!(0 T0, 1 T1);
tuple_node!(0 T0, 1 T1, 2 T2);
tuple_node!(0 T0, 1 T1, 2 T2, 3 T3);
tuple_node!(0 T0, 1 T1, 2 T2, 3 T3, 4 T4);
tuple_node!(0 T0, 1 T1, 2 T2, 3 T3, 4 T4, 5 T5);
tuple_node!(0 T0, 1 T1, 2 T2, 3 T3, 4 T4, 5 T5, 6 T6);
tuple_node!(0 T0, 1 T1, 2 T2, 3 T3, 4 T4, 5 T5, 6 T6, 7 T7);
tuple_node!(0 T0, 1 T1, 2 T2, 3 T3, 4 T4, 5 T5, 6 T6, 7 T7, 8 T8);
tuple_node!(0 T0, 1 T1, 2 T2, 3 T3, 4 T4, 5 T5, 6 T6, 7 T7, 8 T8, 9 T9);
tuple_node!(0 T0, 1 T1, 2 T2, 3 T3, 4 T4, 5 T5, 6 T6, 7 T7, 8 T8, 9 T9, 10 T10);
tuple_node!(0 T0, 1 T1, 2 T2, 3 T3, 4 T4, 5 T5, 6 T6, 7 T7, 8 T8, 9 T9, 10 T10, 11 T11);
tuple_node!(0 T0, 1 T1, 2 T2, 3 T3, 4 T4, 5 T5, 6 T6, 7 T7, 8 T8, 9 T9, 10 T10, 11 T11, 12 T12);
tuple_node!(0 T0, 1 T1, 2 T2, 3 T3, 4 T4, 5 T5, 6 T6, 7 T7, 8 T8, 9 T9, 10 T10, 11 T11, 12 T12, 13 T13);
tuple_node!(0 T0, 1 T1, 2 T2, 3 T3, 4 T4, 5 T5, 6 T6, 7 T7, 8 T8, 9 T9, 10 T10, 11 T11, 12 T12, 13 T13, 14 T14);
tuple_node!(0 T0, 1 T1, 2 T2, 3 T3, 4 T4, 5 T5, 6 T6, 7 T7, 8 T8, 9 T9, 10 T10, 11 T11, 12 T12, 13 T13, 14 T14, 15 T15);

macro_rules! array_node {
    ( $length:expr ) => {
        impl<T> Node for [T; $length] where T: Node + Serialize + DeserializeOwned {
            fn node_step(&mut self, mut runner: NodeRunner) -> String {
                let length = stringify!{ $length };
                match runner.step() {
                    NodeToken::ChainIndex (index) => {
                        #[allow(unused_comparisons)] // comparison becomes useless on array of size 0
                        if index < $length {
                            self[index].node_step(runner)
                        } else {
                            format!("Used index {} on an array of length {}", index, length)
                        }
                    }
                    NodeToken::ChainAll => {
                        let mut combined = String::from("|");
                        for i in 0..$length {
                            combined.push_str(self[i].node_step(runner.clone()).as_ref());
                            combined.push('|');
                        }
                        combined
                    }
                    NodeToken::Get => {
                        serde_json::to_string_pretty(self).unwrap()
                    }
                    NodeToken::Set (value) => {
                        match serde_json::from_str(&value) {
                            Ok (result) => {
                                *self = result;
                                String::from("")
                            }
                            Err (err) => {
                                format!("array set error: {}", err)
                            }
                        }
                    }
                    NodeToken::Help => {
                        String::from(r#"
Array Help

Commands:
*   help - display this help
*   get  - display JSON
*   set  - set to JSON

Accessors:
*   [index] - access item at index"#)
                    }
                    action => { format!("array cannot '{:?}'", action) }
                }
            }
        }
    }
}

array_node!(0);
array_node!(1);
array_node!(2);
array_node!(3);
array_node!(4);
array_node!(5);
array_node!(6);
array_node!(7);
array_node!(8);
array_node!(9);
array_node!(10);
array_node!(11);
array_node!(12);
array_node!(13);
array_node!(14);
array_node!(15);
array_node!(16);

impl Node for bool {
    fn node_step(&mut self, mut runner: NodeRunner) -> String {
        match runner.step() {
            NodeToken::Get         => { if *self { String::from("true") } else { String::from("false") } }
            NodeToken::Set (value) => { *self = value.as_str() == "true"; String::from("") }
            NodeToken::Help        => {
                String::from(r#"
Bool Help

Valid values: true or false

Commands:
*   help - display this help
*   get  - display value
*   set  - set to value"#)
            }
            action => { format!("bool cannot '{:?}'", action) }
        }
    }
}

impl Node for String {
    fn node_step(&mut self, mut runner: NodeRunner) -> String {
        match runner.step() {
            NodeToken::Get => { (*self).clone() }
            NodeToken::Set (value) => { *self = value; String::from("") }
            NodeToken::CopyFrom => {
                let copy = Some (self.clone());
                unsafe {
                    STRING_COPY = copy;
                }
                String::new()
            }
            NodeToken::PasteTo => {
                let paste = unsafe { STRING_COPY.clone() };
                match paste {
                    Some (value) => {
                        *self = value;
                        String::new()
                    }
                    None => {
                        String::from("String has not been copied")
                    }
                }
            }
            NodeToken::Help => {
                String::from(r#"
String Help

Valid values: Anything

Commands:
*   help  - display this help
*   copy  - copy this value
*   paste - paste the copied value here
*   get   - display value
*   set   - set to value"#)
            }
            action => { format!("String cannot '{:?}'", action) }
        }
    }
}

static mut STRING_COPY: Option<String> = None;

impl<T> Node for Option<T> where T: Node + Serialize + DeserializeOwned + Default {
    fn node_step(&mut self, mut runner: NodeRunner) -> String {
        match runner.step() {
            NodeToken::ChainProperty (ref s) if s == "value" => {
                if let &mut Some(ref mut value) = self {
                    value.node_step(runner)
                }
                else {
                    String::from("Option contains no value")
                }
            }
            NodeToken::Get => {
                serde_json::to_string_pretty(self).unwrap()
            }
            NodeToken::Set (value) => {
                match serde_json::from_str(&value) {
                    Ok(result) => {
                        *self = result;
                        String::from("")
                    }
                    Err(err) => {
                        format!("Option set error: {}", err)
                    }
                }
            }
            NodeToken::Insert => {
                *self = Some(T::default());
                String::new()
            }
            NodeToken::Remove => {
                *self = None;
                String::new()
            }
            NodeToken::SetDefault => {
                *self = None;
                String::new()
            }
            NodeToken::Help => {
                String::from(r#"
Option Help

Commands:
*   help    - display this help
*   get     - display JSON
*   set     - set to JSON
*   insert  - set to a value
*   remove  - remove value
*   reset   - remove value

Accessors:
*   .value - the stored value"#)
            }
            action => { format!("Option cannot '{:?}'", action) }
        }
    }
}

macro_rules! int_node {
    ($e:ty, $valid_values:tt) => {
        impl Node for $e {
            fn node_step(&mut self, mut runner: NodeRunner) -> String {
                match runner.step() {
                    NodeToken::Get => { (*self).to_string() }
                    NodeToken::Set (value) => {
                        match value.parse() {
                            Ok (value) => {
                                *self = value;
                                String::from("")
                            }
                            Err(_) => {
                                format!("Invalid value for {} (needs to be: {})", stringify! { $e }, $valid_values)
                            }
                        }
                    }
                    NodeToken::Help => {
                        format!(r#"
{} Help

Valid values: {}

Commands:
*   help             - display this help
*   copy             - copy this value
*   paste            - paste the copied value here
*   get              - display value
*   set      $NUMBER - set to $NUMBER
*   add      $NUMBER - adds $NUMBER to this number
*   subtract $NUMBER - subtracts $NUMBER from this number
*   multiply $NUMBER - multiply this number with $NUMBER
*   divide   $NUMBER - divide this number by $NUMBER"#,
                            stringify! { $e },
                            $valid_values
                        )
                    }
                    NodeToken::CopyFrom => {
                        let num_copy = match stringify! { $e } {
                            "f32" | "f64" => NumStore::Float (*self as f64),
                            _             => NumStore::Int   (*self as u64)
                        };
                        unsafe {
                            NUM_COPY = num_copy;
                        }
                        String::from("")
                    }
                    NodeToken::PasteTo => {
                        let num_copy = unsafe { NUM_COPY.clone() };
                        match num_copy {
                            NumStore::Int (value) => {
                                *self = value as $e;
                                String::from("")
                            }
                            NumStore::Float (value) => {
                                *self = value as $e;
                                String::from("")
                            }
                            NumStore::None => {
                                String::from("A number has not been copied")
                            }
                        }
                    }
                    NodeToken::Custom (action, args) => {
                        match action.as_ref() {
                            "add" => {
                                if let Some(arg0) = args.get(0) {
                                    if let Ok(number) = arg0.parse() {
                                        *self = (*self).saturating_add(number);
                                        String::from("")
                                    } else {
                                        format!("Invalid value for {} (needs to be: {})", stringify! { $e }, $valid_values)
                                    }
                                } else {
                                    format!("No value for {} (needs to be: {})", stringify! { $e }, $valid_values)
                                }
                            }
                            "subtract" => {
                                if let Some(arg0) = args.get(0) {
                                    if let Ok(number) = arg0.parse() {
                                        *self = (*self).saturating_sub(number);
                                        String::from("")
                                    } else {
                                        format!("Invalid value for {} (needs to be: {})", stringify! { $e }, $valid_values)
                                    }
                                } else {
                                    format!("No value for {} (needs to be: {})", stringify! { $e }, $valid_values)
                                }
                            }
                            "multiply" => {
                                if let Some(arg0) = args.get(0) {
                                    if let Ok(number) = arg0.parse() {
                                        *self = (*self).saturating_mul(number);
                                        String::from("")
                                    } else {
                                        format!("Invalid value for {} (needs to be: {})", stringify! { $e }, $valid_values)
                                    }
                                } else {
                                    format!("No value for {} (needs to be: {})", stringify! { $e }, $valid_values)
                                }
                            }
                            "divide" => {
                                if let Some(arg0) = args.get(0) {
                                    if let Ok(number) = arg0.parse() {
                                        if let Some(number) = (*self).checked_div(number) {
                                            *self = number;
                                            String::from("")
                                        } else {
                                            format!("Invalid value for {} (needs to be: {}, excluding 0)", stringify! { $e }, $valid_values)
                                        }
                                    } else {
                                        format!("Invalid value for {} (needs to be: {}, excluding 0)", stringify! { $e }, $valid_values)
                                    }
                                } else {
                                    format!("No value for {} (needs to be: {})", stringify! { $e }, $valid_values)
                                }
                            }
                            _ => {
                                format!("{} cannot '{}'", stringify! { $e }, action)
                            }
                        }
                    }
                    action => { format!("{} cannot '{:?}'", stringify! { $e }, action) }
                }
            }
        }
    }
}

macro_rules! float_node {
    ($e:ty, $valid_values:tt) => {
        impl Node for $e {
            fn node_step(&mut self, mut runner: NodeRunner) -> String {
                match runner.step() {
                    NodeToken::Get => { (*self).to_string() }
                    NodeToken::Set (value) => {
                        match value.parse() {
                            Ok (value) => {
                                *self = value;
                                String::from("")
                            }
                            Err(_) => {
                                format!("Invalid value for {} (needs to be: {})", stringify! { $e }, $valid_values)
                            }
                        }
                    }
                    NodeToken::Help => {
                        format!(r#"
{} Help

Valid values: {}

Commands:
*   help             - display this help
*   copy             - copy this value
*   paste            - paste the copied value here
*   get              - display value
*   set      $NUMBER - set to $NUMBER
*   add      $NUMBER - adds $NUMBER to this number
*   subtract $NUMBER - subtracts $NUMBER from this number
*   multiply $NUMBER - multiply this number with $NUMBER
*   divide   $NUMBER - divide this number by $NUMBER"#,
                            stringify! { $e },
                            $valid_values
                        )
                    }
                    NodeToken::CopyFrom => {
                        let num_copy = match stringify! { $e } {
                            "f32" | "f64" => NumStore::Float (*self as f64),
                            _             => NumStore::Int   (*self as u64)
                        };
                        unsafe {
                            NUM_COPY = num_copy;
                        }
                        String::from("")
                    }
                    NodeToken::PasteTo => {
                        let num_copy = unsafe { NUM_COPY.clone() };
                        match num_copy {
                            NumStore::Int (value) => {
                                *self = value as $e;
                                String::from("")
                            }
                            NumStore::Float (value) => {
                                *self = value as $e;
                                String::from("")
                            }
                            NumStore::None => {
                                String::from("A number has not been copied")
                            }
                        }
                    }
                    NodeToken::Custom (action, args) => {
                        match action.as_ref() {
                            "add" => {
                                if let Some(arg0) = args.get(0) {
                                    if let Ok(number) = arg0.parse::<$e>() {
                                        *self += number;
                                        String::from("")
                                    } else {
                                        format!("Invalid value for {} (needs to be: {})", stringify! { $e }, $valid_values)
                                    }
                                } else {
                                    format!("No value for {} (needs to be: {})", stringify! { $e }, $valid_values)
                                }
                            }
                            "subtract" => {
                                if let Some(arg0) = args.get(0) {
                                    if let Ok(number) = arg0.parse::<$e>() {
                                        *self -= number;
                                        String::from("")
                                    } else {
                                        format!("Invalid value for {} (needs to be: {})", stringify! { $e }, $valid_values)
                                    }
                                } else {
                                    format!("No value for {} (needs to be: {})", stringify! { $e }, $valid_values)
                                }
                            }
                            "multiply" => {
                                if let Some(arg0) = args.get(0) {
                                    if let Ok(number) = arg0.parse::<$e>() {
                                        *self *= number;
                                        String::from("")
                                    } else {
                                        format!("Invalid value for {} (needs to be: {})", stringify! { $e }, $valid_values)
                                    }
                                } else {
                                    format!("No value for {} (needs to be: {})", stringify! { $e }, $valid_values)
                                }
                            }
                            "divide" => {
                                if let Some(arg0) = args.get(0) {
                                    if let Ok(number) = arg0.parse::<$e>() {
                                        *self /= number;
                                        String::from("")
                                    } else {
                                        format!("Invalid value for {} (needs to be: {})", stringify! { $e }, $valid_values)
                                    }
                                } else {
                                    format!("No value for {} (needs to be: {})", stringify! { $e }, $valid_values)
                                }
                            }
                            _ => {
                                format!("{} cannot '{}'", stringify! { $e }, action)
                            }
                        }
                    }
                    action => { format!("{} cannot '{:?}'", stringify! { $e }, action) }
                }
            }
        }
    }
}

#[derive(Clone)]
enum NumStore {
    Int   (u64),
    Float (f64),
    None,
}

static mut NUM_COPY: NumStore = NumStore::None;

int_node!(i64, "A number from –9,223,372,036,854,775,808 to 9,223,372,036,854,775,807");
int_node!(u64, "A number from 0 to 18,446,744,073,709,551,615");
int_node!(i32, "A number from –2,147,483,648 to 2,147,483,647");
int_node!(u32, "A number from 0 to 4,294,967,295");
int_node!(i16, "A number from –32,768 to –32,767");
int_node!(u16, "A number from 0 to 65,535");
int_node!(i8, "A number from -128 to 127");
int_node!(u8, "A number from 0 to 255");
int_node!(isize, "A number from –9,223,372,036,854,775,808 to 9,223,372,036,854,775,807");
int_node!(usize, "A number from 0 to 18,446,744,073,709,551,615");

// TODO: Not sure how to best present possible values for the floats
float_node!(f32, "A number with a decimal point");
float_node!(f64, "A higher precision number with a decimal point");