Skip to main content

veryl_parser/
veryl_grammar.rs

1use crate::veryl_grammar_trait::*;
2use parol_runtime::ParolError;
3use std::fmt::{Debug, Display, Error, Formatter};
4
5#[derive(Debug, Default)]
6pub struct VerylGrammar {
7    pub veryl: Option<Veryl>,
8}
9
10impl VerylGrammar {
11    pub fn new() -> Self {
12        VerylGrammar::default()
13    }
14}
15
16impl Display for Veryl {
17    fn fmt(&self, f: &mut Formatter<'_>) -> std::result::Result<(), Error> {
18        write!(f, "{self:?}")
19    }
20}
21
22impl Display for VerylGrammar {
23    fn fmt(&self, f: &mut Formatter<'_>) -> std::result::Result<(), Error> {
24        match &self.veryl {
25            Some(veryl) => writeln!(f, "{veryl}"),
26            None => write!(f, "No parse result"),
27        }
28    }
29}
30
31impl VerylGrammarTrait for VerylGrammar {
32    /// Semantic action for non-terminal 'Veryl'
33    fn veryl(&mut self, arg: &Veryl) -> Result<(), ParolError> {
34        self.veryl = Some(arg.clone());
35        Ok(())
36    }
37}