1use wast::parser::{Parse, Parser, Result};
2
3use crate::{Expr, SExpr, Section};
4
5#[derive(Debug, Clone, PartialEq, Eq)]
6pub struct Module {
7 sections: Vec<Section>,
8}
9
10impl Module {
11 pub fn with_sections(sections: Vec<Section>) -> Self {
12 Self { sections }
13 }
14}
15
16impl Parse<'_> for Module {
17 fn parse(parser: Parser<'_>) -> Result<Self> {
18 parser.parse::<wast::kw::module>()?;
19
20 let mut sections = Vec::new();
21
22 while !parser.is_empty() {
23 sections.push(parser.parse::<Section>()?)
24 }
25
26 Ok(Self { sections })
27 }
28}
29
30impl SExpr for Module {
31 fn car(&self) -> String {
32 "module".to_owned()
33 }
34
35 fn cdr(&self) -> Vec<Expr> {
36 self.sections.iter().flat_map(|s| s.exprs()).collect()
37 }
38}