1use pest::iterators::Pair;
2
3use super::{Position, Rule, Statement};
4
5#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
6pub struct Block<T> {
7 pub block: Vec<Statement<T>>,
8 pub position: Position,
9 pub info: T,
10}
11
12impl Block<()> {
13 pub fn from_pair(pair: Pair<Rule>, file: &str) -> Block<()> {
14 assert_eq!(pair.as_rule(), Rule::block);
15
16 let (line, col) = pair.line_col();
17
18 let block = pair.into_inner();
19
20 let mut block_ast = vec![];
21
22 for statement in block {
23 block_ast.push(Statement::from_pair(statement, file));
24 }
25
26 Block {
27 block: block_ast,
28 position: (file.to_owned(), line, col),
29 info: (),
30 }
31 }
32}