xdy 0.13.0

Complex RPG dice expression evaluator with histogram support.
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
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
//! # AST visitor tests
//!
//! Herein are tests for the iterative driver behind
//! [`ASTVisitor`]: the order in which it calls a visitor, the outputs that it
//! hands each method, where it calls
//! [`visit_expression`](ASTVisitor::visit_expression), how it stops on error,
//! and that it survives deep nesting on a small stack.

use pretty_assertions::assert_eq;

use super::ast::{DEPTH, Nesting, nest};
use crate::{Parser, ast::*, support::on_small_stack};

////////////////////////////////////////////////////////////////////////////////
//                                Call order.                                 //
////////////////////////////////////////////////////////////////////////////////

/// Ensure that a walk enters every node before its children, visits every
/// node after its children with their outputs in source order, and finishes
/// every expression slot, but not the dice beneath a drop clause, with
/// [`visit_expression`](ASTVisitor::visit_expression).
#[test]
fn test_visitor_order()
{
	let ast = Parser::parse(
		"{x}: {a}@([1:{x}]) + (2D6 drop lowest 1 drop highest) * -3D[1, 2] / 4 \
		 - 5 % 6 ^ 7"
	)
	.unwrap();
	let mut tracer = Tracer::default();
	let output = ast.accept(&mut tracer).unwrap();
	assert_eq!(
		output,
		"fn <<<{a}@(<[<1>:<{x}>]>)> + <<<(<<2>D<6> drop lowest <1> drop \
		 highest>)> * <-<<3>D[1, 2]>>> / <4>>> - <<5> % <<6> ^ <7>>>>"
	);
	assert_eq!(
		tracer.entered,
		[
			"function",
			"sub",
			"add",
			"binding",
			"range",
			"constant",
			"variable",
			"div",
			"mul",
			"group",
			"drop_highest",
			"drop_lowest",
			"standard_dice",
			"constant",
			"constant",
			"constant",
			"neg",
			"custom_dice",
			"constant",
			"constant",
			"mod",
			"constant",
			"exp",
			"constant",
			"constant"
		]
	);
}

/// Ensure that a walk from a [`DiceExpression`] or an
/// [`ArithmeticExpression`] does not finish its root with
/// [`visit_expression`](ASTVisitor::visit_expression), since neither fills a
/// slot of type [`Expression`], but that a walk from an [`Expression`] does.
#[test]
fn test_visitor_roots()
{
	let ast = Parser::parse("3D6 drop lowest").unwrap();
	let Expression::Dice(dice) = &ast.body
	else
	{
		unreachable!()
	};
	assert_eq!(
		dice.accept(&mut Tracer::default()).unwrap(),
		"<3>D<6> drop lowest"
	);
	assert_eq!(
		ast.body.accept(&mut Tracer::default()).unwrap(),
		"<<3>D<6> drop lowest>"
	);
	let ast = Parser::parse("1 + 2").unwrap();
	let Expression::Arithmetic(arithmetic) = &ast.body
	else
	{
		unreachable!()
	};
	assert_eq!(
		arithmetic.accept(&mut Tracer::default()).unwrap(),
		"<1> + <2>"
	);
}

/// Ensure that a walk stops at the first error, whether from an `enter_*`
/// hook, a `visit_*` method, or
/// [`visit_expression`](ASTVisitor::visit_expression), and makes no further
/// calls.
#[test]
fn test_visitor_stops_on_error()
{
	let ast = Parser::parse("{a}@(1) + {b} + 2").unwrap();
	for (fail, entered) in [
		("enter binding", &["function", "add", "add", "binding"][..]),
		(
			"visit variable",
			&["function", "add", "add", "binding", "constant", "variable"][..]
		),
		(
			"visit expression",
			&["function", "add", "add", "binding", "constant"][..]
		)
	]
	{
		let mut tracer = Tracer {
			fail: Some(fail),
			..Tracer::default()
		};
		assert_eq!(ast.accept(&mut tracer), Err(fail));
		assert_eq!(tracer.entered, entered, "{}", fail);
		assert_eq!(tracer.calls.last(), Some(&fail));
	}
}

////////////////////////////////////////////////////////////////////////////////
//                               Deep nesting.                                //
////////////////////////////////////////////////////////////////////////////////

/// Ensure that a walk survives a deep chain of every nesting construct on a
/// small stack.
#[test]
#[ignore = "stress: run with just stress"]
fn test_visitor_deep()
{
	on_small_stack(|| {
		for nesting in Nesting::ROTATION.into_iter().chain([Nesting::Mixed])
		{
			let expression = nest(nesting, DEPTH, 1);
			let mut counter = Counter::default();
			let nodes = expression.accept(&mut counter).unwrap();
			assert!(nodes > DEPTH, "{:?}", nesting);
			assert_eq!(counter.entered, nodes, "{:?}", nesting);
			assert_eq!(counter.visited, nodes, "{:?}", nesting);
		}
	});
}

////////////////////////////////////////////////////////////////////////////////
//                                  Helpers.                                  //
////////////////////////////////////////////////////////////////////////////////

/// A visitor that renders an AST, wrapping in angle brackets the output of
/// every node that [`visit_expression`](ASTVisitor::visit_expression)
/// finishes, and records its calls. It fails at the call named by
/// [`fail`](Self::fail), if any.
#[derive(Default)]
struct Tracer
{
	/// The node types entered, in order.
	entered: Vec<&'static str>,

	/// Every call, in order, e.g., `enter binding` or `visit expression`.
	calls: Vec<&'static str>,

	/// The call at which to fail, if any.
	fail: Option<&'static str>
}

impl Tracer
{
	/// Record an `enter_*` call.
	///
	/// # Parameters
	/// - `node`: The type of node entered.
	/// - `call`: The name of the call.
	///
	/// # Errors
	/// The name of the call, if it is the one at which to fail.
	fn enter(
		&mut self,
		node: &'static str,
		call: &'static str
	) -> Result<(), &'static str>
	{
		self.entered.push(node);
		self.call(call)
	}

	/// Record a call.
	///
	/// # Parameters
	/// - `call`: The name of the call.
	///
	/// # Errors
	/// The name of the call, if it is the one at which to fail.
	fn call(&mut self, call: &'static str) -> Result<(), &'static str>
	{
		self.calls.push(call);
		match self.fail
		{
			Some(fail) if fail == call => Err(call),
			_ => Ok(())
		}
	}

	/// Record a `visit_*` call and render a drop clause.
	///
	/// # Parameters
	/// - `call`: The name of the call.
	/// - `keyword`: The keyword of the clause, e.g., `lowest`.
	/// - `dice`: The output of the dice.
	/// - `drop`: The output of the drop count, if any.
	///
	/// # Returns
	/// The rendering.
	///
	/// # Errors
	/// The name of the call, if it is the one at which to fail.
	fn drop(
		&mut self,
		call: &'static str,
		keyword: &str,
		dice: String,
		drop: Option<String>
	) -> Result<String, &'static str>
	{
		self.call(call)?;
		Ok(match drop
		{
			Some(drop) => format!("{} drop {} {}", dice, keyword, drop),
			None => format!("{} drop {}", dice, keyword)
		})
	}

	/// Record a `visit_*` call and render a binary operation.
	///
	/// # Parameters
	/// - `call`: The name of the call.
	/// - `operator`: The operator.
	/// - `left`: The output of the left operand.
	/// - `right`: The output of the right operand.
	///
	/// # Returns
	/// The rendering.
	///
	/// # Errors
	/// The name of the call, if it is the one at which to fail.
	fn binary(
		&mut self,
		call: &'static str,
		operator: &str,
		left: String,
		right: String
	) -> Result<String, &'static str>
	{
		self.call(call)?;
		Ok(format!("{} {} {}", left, operator, right))
	}
}

impl<'a, 'src: 'a> ASTVisitor<'a, 'src> for Tracer
{
	type Output = String;
	type Error = &'static str;

	fn enter_function(
		&mut self,
		_node: &'a Function<'src>
	) -> Result<(), Self::Error>
	{
		self.enter("function", "enter function")
	}

	fn enter_group(&mut self, _node: &'a Group<'src>)
	-> Result<(), Self::Error>
	{
		self.enter("group", "enter group")
	}

	fn enter_constant(&mut self, _node: &'a Constant)
	-> Result<(), Self::Error>
	{
		self.enter("constant", "enter constant")
	}

	fn enter_variable(
		&mut self,
		_node: &'a Variable<'src>
	) -> Result<(), Self::Error>
	{
		self.enter("variable", "enter variable")
	}

	fn enter_binding(
		&mut self,
		_node: &'a Binding<'src>
	) -> Result<(), Self::Error>
	{
		self.enter("binding", "enter binding")
	}

	fn enter_range(&mut self, _node: &'a Range<'src>)
	-> Result<(), Self::Error>
	{
		self.enter("range", "enter range")
	}

	fn enter_standard_dice(
		&mut self,
		_node: &'a StandardDice<'src>
	) -> Result<(), Self::Error>
	{
		self.enter("standard_dice", "enter standard_dice")
	}

	fn enter_custom_dice(
		&mut self,
		_node: &'a CustomDice<'src>
	) -> Result<(), Self::Error>
	{
		self.enter("custom_dice", "enter custom_dice")
	}

	fn enter_drop_lowest(
		&mut self,
		_node: &'a DropLowest<'src>
	) -> Result<(), Self::Error>
	{
		self.enter("drop_lowest", "enter drop_lowest")
	}

	fn enter_drop_highest(
		&mut self,
		_node: &'a DropHighest<'src>
	) -> Result<(), Self::Error>
	{
		self.enter("drop_highest", "enter drop_highest")
	}

	fn enter_add(&mut self, _node: &'a Add<'src>) -> Result<(), Self::Error>
	{
		self.enter("add", "enter add")
	}

	fn enter_sub(&mut self, _node: &'a Sub<'src>) -> Result<(), Self::Error>
	{
		self.enter("sub", "enter sub")
	}

	fn enter_mul(&mut self, _node: &'a Mul<'src>) -> Result<(), Self::Error>
	{
		self.enter("mul", "enter mul")
	}

	fn enter_div(&mut self, _node: &'a Div<'src>) -> Result<(), Self::Error>
	{
		self.enter("div", "enter div")
	}

	fn enter_mod(&mut self, _node: &'a Mod<'src>) -> Result<(), Self::Error>
	{
		self.enter("mod", "enter mod")
	}

	fn enter_exp(&mut self, _node: &'a Exp<'src>) -> Result<(), Self::Error>
	{
		self.enter("exp", "enter exp")
	}

	fn enter_neg(&mut self, _node: &'a Neg<'src>) -> Result<(), Self::Error>
	{
		self.enter("neg", "enter neg")
	}

	fn visit_function(
		&mut self,
		_node: &'a Function<'src>,
		body: String
	) -> Result<String, Self::Error>
	{
		self.call("visit function")?;
		Ok(format!("fn {}", body))
	}

	fn visit_group(
		&mut self,
		_node: &'a Group<'src>,
		expression: String
	) -> Result<String, Self::Error>
	{
		self.call("visit group")?;
		Ok(format!("({})", expression))
	}

	fn visit_constant(
		&mut self,
		node: &'a Constant
	) -> Result<String, Self::Error>
	{
		self.call("visit constant")?;
		Ok(node.value.to_string())
	}

	fn visit_variable(
		&mut self,
		node: &'a Variable<'src>
	) -> Result<String, Self::Error>
	{
		self.call("visit variable")?;
		Ok(format!("{{{}}}", node.name))
	}

	fn visit_binding(
		&mut self,
		node: &'a Binding<'src>,
		expression: String
	) -> Result<String, Self::Error>
	{
		self.call("visit binding")?;
		Ok(format!("{{{}}}@({})", node.name, expression))
	}

	fn visit_range(
		&mut self,
		_node: &'a Range<'src>,
		start: String,
		end: String
	) -> Result<String, Self::Error>
	{
		self.call("visit range")?;
		Ok(format!("[{}:{}]", start, end))
	}

	fn visit_standard_dice(
		&mut self,
		_node: &'a StandardDice<'src>,
		count: String,
		faces: String
	) -> Result<String, Self::Error>
	{
		self.call("visit standard_dice")?;
		Ok(format!("{}D{}", count, faces))
	}

	fn visit_custom_dice(
		&mut self,
		node: &'a CustomDice<'src>,
		count: String
	) -> Result<String, Self::Error>
	{
		self.call("visit custom_dice")?;
		Ok(format!("{}D{:?}", count, node.faces))
	}

	fn visit_drop_lowest(
		&mut self,
		_node: &'a DropLowest<'src>,
		dice: String,
		drop: Option<String>
	) -> Result<String, Self::Error>
	{
		self.drop("visit drop_lowest", "lowest", dice, drop)
	}

	fn visit_drop_highest(
		&mut self,
		_node: &'a DropHighest<'src>,
		dice: String,
		drop: Option<String>
	) -> Result<String, Self::Error>
	{
		self.drop("visit drop_highest", "highest", dice, drop)
	}

	fn visit_add(
		&mut self,
		_node: &'a Add<'src>,
		left: String,
		right: String
	) -> Result<String, Self::Error>
	{
		self.binary("visit add", "+", left, right)
	}

	fn visit_sub(
		&mut self,
		_node: &'a Sub<'src>,
		left: String,
		right: String
	) -> Result<String, Self::Error>
	{
		self.binary("visit sub", "-", left, right)
	}

	fn visit_mul(
		&mut self,
		_node: &'a Mul<'src>,
		left: String,
		right: String
	) -> Result<String, Self::Error>
	{
		self.binary("visit mul", "*", left, right)
	}

	fn visit_div(
		&mut self,
		_node: &'a Div<'src>,
		left: String,
		right: String
	) -> Result<String, Self::Error>
	{
		self.binary("visit div", "/", left, right)
	}

	fn visit_mod(
		&mut self,
		_node: &'a Mod<'src>,
		left: String,
		right: String
	) -> Result<String, Self::Error>
	{
		self.binary("visit mod", "%", left, right)
	}

	fn visit_exp(
		&mut self,
		_node: &'a Exp<'src>,
		left: String,
		right: String
	) -> Result<String, Self::Error>
	{
		self.binary("visit exp", "^", left, right)
	}

	fn visit_neg(
		&mut self,
		_node: &'a Neg<'src>,
		operand: String
	) -> Result<String, Self::Error>
	{
		self.call("visit neg")?;
		Ok(format!("-{}", operand))
	}

	fn visit_expression(
		&mut self,
		_node: &'a Expression<'src>,
		output: String
	) -> Result<String, Self::Error>
	{
		self.call("visit expression")?;
		Ok(format!("<{}>", output))
	}
}

/// A visitor that counts the nodes of an AST, both as it enters them and as it
/// visits them. The output of each node is the number of nodes in its subtree.
#[derive(Default)]
struct Counter
{
	/// The number of nodes entered.
	entered: usize,

	/// The number of nodes visited.
	visited: usize
}

impl Counter
{
	/// Record an `enter_*` call.
	///
	/// # Returns
	/// `Ok(())`.
	fn enter(&mut self) -> Result<(), ()>
	{
		self.entered += 1;
		Ok(())
	}

	/// Record a `visit_*` call.
	///
	/// # Parameters
	/// - `children`: The outputs of the node's children.
	///
	/// # Returns
	/// The number of nodes in the node's subtree.
	fn visit(&mut self, children: &[usize]) -> Result<usize, ()>
	{
		self.visited += 1;
		Ok(1 + children.iter().sum::<usize>())
	}
}

impl<'a, 'src: 'a> ASTVisitor<'a, 'src> for Counter
{
	type Output = usize;
	type Error = ();

	fn enter_function(&mut self, _node: &'a Function<'src>) -> Result<(), ()>
	{
		self.enter()
	}

	fn enter_group(&mut self, _node: &'a Group<'src>) -> Result<(), ()>
	{
		self.enter()
	}

	fn enter_constant(&mut self, _node: &'a Constant) -> Result<(), ()>
	{
		self.enter()
	}

	fn enter_variable(&mut self, _node: &'a Variable<'src>) -> Result<(), ()>
	{
		self.enter()
	}

	fn enter_binding(&mut self, _node: &'a Binding<'src>) -> Result<(), ()>
	{
		self.enter()
	}

	fn enter_range(&mut self, _node: &'a Range<'src>) -> Result<(), ()>
	{
		self.enter()
	}

	fn enter_standard_dice(
		&mut self,
		_node: &'a StandardDice<'src>
	) -> Result<(), ()>
	{
		self.enter()
	}

	fn enter_custom_dice(
		&mut self,
		_node: &'a CustomDice<'src>
	) -> Result<(), ()>
	{
		self.enter()
	}

	fn enter_drop_lowest(
		&mut self,
		_node: &'a DropLowest<'src>
	) -> Result<(), ()>
	{
		self.enter()
	}

	fn enter_drop_highest(
		&mut self,
		_node: &'a DropHighest<'src>
	) -> Result<(), ()>
	{
		self.enter()
	}

	fn enter_add(&mut self, _node: &'a Add<'src>) -> Result<(), ()>
	{
		self.enter()
	}

	fn enter_sub(&mut self, _node: &'a Sub<'src>) -> Result<(), ()>
	{
		self.enter()
	}

	fn enter_mul(&mut self, _node: &'a Mul<'src>) -> Result<(), ()>
	{
		self.enter()
	}

	fn enter_div(&mut self, _node: &'a Div<'src>) -> Result<(), ()>
	{
		self.enter()
	}

	fn enter_mod(&mut self, _node: &'a Mod<'src>) -> Result<(), ()>
	{
		self.enter()
	}

	fn enter_exp(&mut self, _node: &'a Exp<'src>) -> Result<(), ()>
	{
		self.enter()
	}

	fn enter_neg(&mut self, _node: &'a Neg<'src>) -> Result<(), ()>
	{
		self.enter()
	}

	fn visit_function(
		&mut self,
		_node: &'a Function<'src>,
		body: usize
	) -> Result<usize, ()>
	{
		self.visit(&[body])
	}

	fn visit_group(
		&mut self,
		_node: &'a Group<'src>,
		expression: usize
	) -> Result<usize, ()>
	{
		self.visit(&[expression])
	}

	fn visit_constant(&mut self, _node: &'a Constant) -> Result<usize, ()>
	{
		self.visit(&[])
	}

	fn visit_variable(&mut self, _node: &'a Variable<'src>)
	-> Result<usize, ()>
	{
		self.visit(&[])
	}

	fn visit_binding(
		&mut self,
		_node: &'a Binding<'src>,
		expression: usize
	) -> Result<usize, ()>
	{
		self.visit(&[expression])
	}

	fn visit_range(
		&mut self,
		_node: &'a Range<'src>,
		start: usize,
		end: usize
	) -> Result<usize, ()>
	{
		self.visit(&[start, end])
	}

	fn visit_standard_dice(
		&mut self,
		_node: &'a StandardDice<'src>,
		count: usize,
		faces: usize
	) -> Result<usize, ()>
	{
		self.visit(&[count, faces])
	}

	fn visit_custom_dice(
		&mut self,
		_node: &'a CustomDice<'src>,
		count: usize
	) -> Result<usize, ()>
	{
		self.visit(&[count])
	}

	fn visit_drop_lowest(
		&mut self,
		_node: &'a DropLowest<'src>,
		dice: usize,
		drop: Option<usize>
	) -> Result<usize, ()>
	{
		self.visit(&[dice, drop.unwrap_or(0)])
	}

	fn visit_drop_highest(
		&mut self,
		_node: &'a DropHighest<'src>,
		dice: usize,
		drop: Option<usize>
	) -> Result<usize, ()>
	{
		self.visit(&[dice, drop.unwrap_or(0)])
	}

	fn visit_add(
		&mut self,
		_node: &'a Add<'src>,
		left: usize,
		right: usize
	) -> Result<usize, ()>
	{
		self.visit(&[left, right])
	}

	fn visit_sub(
		&mut self,
		_node: &'a Sub<'src>,
		left: usize,
		right: usize
	) -> Result<usize, ()>
	{
		self.visit(&[left, right])
	}

	fn visit_mul(
		&mut self,
		_node: &'a Mul<'src>,
		left: usize,
		right: usize
	) -> Result<usize, ()>
	{
		self.visit(&[left, right])
	}

	fn visit_div(
		&mut self,
		_node: &'a Div<'src>,
		left: usize,
		right: usize
	) -> Result<usize, ()>
	{
		self.visit(&[left, right])
	}

	fn visit_mod(
		&mut self,
		_node: &'a Mod<'src>,
		left: usize,
		right: usize
	) -> Result<usize, ()>
	{
		self.visit(&[left, right])
	}

	fn visit_exp(
		&mut self,
		_node: &'a Exp<'src>,
		left: usize,
		right: usize
	) -> Result<usize, ()>
	{
		self.visit(&[left, right])
	}

	fn visit_neg(
		&mut self,
		_node: &'a Neg<'src>,
		operand: usize
	) -> Result<usize, ()>
	{
		self.visit(&[operand])
	}
}