xenon_codegen/
case.rs

1use crate::{expression::Expression, scope::Scope};
2
3#[derive(Debug, Clone, Default)]
4pub struct Case {
5    pub condition: Expression,
6    pub body: Scope,
7}
8impl Case {
9    pub fn new(condition: Expression, body: Scope) -> Case {
10        Case { condition, body }
11    }
12
13    pub fn is_valid(&self) -> bool {
14        self.condition.is_valid() && self.body.is_valid()
15    }
16}
17impl std::fmt::Display for Case {
18    fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
19        match write!(fmt, "case {} {}", self.condition, self.body) {
20            Ok(_) => (),
21            Err(e) => return Err(e),
22        }
23
24        Ok(())
25    }
26}