visita/
lib.rs

1
2pub use visita_macros::{node_group, visitor};
3
4// responsible for routing the visit methods to the different nodes
5pub trait NodeFamily<V> : Sized where V : Visitor<Self> {
6	type Data;
7
8	fn accept(&self, v: &mut V) -> V::Output;
9}
10
11// responsible for associating a node to a collection of nodes
12pub trait Node<V> : Sized where V : Visitor<Self::Family> + Visit<Self> {
13	type Family : NodeFamily<V>;
14
15	fn accept(&self, v: &mut V, data: &Data<V, Self>) -> V::Output {
16		v.visit(self, data)
17	}
18}
19
20// responsible for dictating the output of traversing a group of nodes
21pub trait Visitor<F> : Sized where F : NodeFamily<Self> {
22	type Output;
23}
24
25/// Implements the visiting logic for a node
26pub trait Visit<N> : Visitor<N::Family> where N : Node<Self> {
27	fn visit(&mut self, node: &N, data: &Data<Self, N>) -> Self::Output;
28}
29
30/// Shorthand for getting the data type from a node, as it can get quite verbose
31pub type Data<V, N> = <<N as Node<V>>::Family as NodeFamily<V>>::Data;