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
pub mod depth_first;
pub mod null_forest;
pub use self::depth_first::{Bocage, Traversal};
pub use self::null_forest::NullForest;
use cfg::Symbol;
use item::CompletedItem;
pub trait Forest<'a> {
type NodeRef: Copy + 'a;
type NodeBuilder: NodeBuilder<NodeRef=Self::NodeRef>;
type LeafValue: 'a;
fn build(&'a self, num_children: usize) -> Self::NodeBuilder;
fn leaf(&'a self, token: Symbol, pos: u32, value: Self::LeafValue) -> Self::NodeRef;
fn nulling(&'a self, token: Symbol) -> Self::NodeRef;
}
pub trait NodeBuilder {
type NodeRef;
fn push(&mut self, item: CompletedItem<Self::NodeRef>);
fn sum(&mut self, origin: u32) -> Self::NodeRef;
fn reserve(&mut self, len: usize);
}
impl<'f, F> Forest<'f> for &'f F where F: Forest<'f> {
type NodeRef = F::NodeRef;
type NodeBuilder = F::NodeBuilder;
type LeafValue = F::LeafValue;
fn build(&'f self, num_children: usize) -> Self::NodeBuilder {
(**self).build(num_children)
}
fn leaf(&'f self, token: Symbol, pos: u32, value: Self::LeafValue) -> Self::NodeRef {
(**self).leaf(token, pos, value)
}
fn nulling(&'f self, token: Symbol) -> Self::NodeRef {
(**self).nulling(token)
}
}