use heraclitus_compiler::prelude::*; use super::text::*; #[derive(Debug)] pub enum ExprType { Text(Text) } #[derive(Debug)] pub struct Expr { expr: Option> } impl Expr { fn get(&mut self, meta: &mut M, mut module: S, cb: impl Fn(S) -> ExprType) -> SyntaxResult where M: Metadata, S: SyntaxModule { match syntax(meta, &mut module) { Ok(()) => { self.expr = Some(Box::new(cb(module))); Ok(()) } Err(details) => Err(details) } } fn parse_module(&mut self, meta: &mut DefaultMetadata, module: ExprType) -> SyntaxResult { match module { ExprType::Text(md) => self.get(meta, md, ExprType::Text) } } } impl SyntaxModule for Expr { syntax_name!("Expr"); fn new() -> Self { Expr { expr: None } } fn parse(&mut self, meta: &mut DefaultMetadata) -> SyntaxResult { let modules: Vec = vec![ ExprType::Text(Text::new()) ]; let mut err = None; for module in modules { match self.parse_module(meta, module) { Ok(()) => return Ok(()), Err(details) => { err = Some(details); } } } Err(err.unwrap()) } }