1use crate::*;
2
3pub trait Ast: Sized {
4 fn parse(iter: &mut impl Iterator<Item = Node>) -> Option<Self>;
5}
6
7impl<T> Ast for Vec<T>
8where
9 T: Ast,
10{
11 fn parse(iter: &mut impl Iterator<Item = Node>) -> Option<Self> {
12 let res: Self = iter
13 .filter_map(|node| {
14 let nodes = node.iter().cloned().collect::<Vec<Node>>();
15 Ast::parse(&mut nodes.into_iter())
16 })
17 .collect();
18
19 Some(res)
20 }
21}
22
23impl<T> Ast for Box<T>
24where
25 T: Ast,
26{
27 fn parse(iter: &mut impl Iterator<Item = Node>) -> Option<Self> {
28 T::parse(iter).map(Box::new)
29 }
30}