1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
use super::*;

impl ControlKind {
    /// Convert to keywords
    pub fn as_str(&self) -> &'static str {
        match self {
            Self::Goto => "goto",
            Self::Raise => "raise",
            Self::Break => "break",
            Self::Continue => "continue",
            Self::Fallthrough => "fallthrough",
            Self::FallthroughUnchecked => "fallthrough!",
            Self::Return => "return",
            Self::Resume => "resume",
            Self::YieldReturn => "yield return",
            Self::YieldBreak => "yield break",
            Self::YieldFrom => "yield from",
            Self::YieldSend => "yield wait",
            Self::Await => "await",
            Self::AwaitNever => "await?",
            Self::AwaitBlockOn => "await!",
        }
    }
}

impl Display for ControlKind {
    fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
        f.write_str(self.as_str())
    }
}

impl Debug for ControlNode {
    fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
        let w = &mut f.debug_struct("Control");
        w.field("kind", &self.kind);
        match &self.label {
            LabelNode::Nearest => {}
            LabelNode::Named(s) => {
                w.field("label", &s.name);
            }
        }
        if let Some(e) = &self.expression {
            w.field("expression", e);
        }
        w.field("span", &self.span);
        w.finish()
    }
}

#[cfg(feature = "pretty-print")]
impl PrettyPrint for RaiseNode {
    fn pretty(&self, theme: &PrettyProvider) -> PrettyTree {
        let mut terms = PrettySequence::new(2);
        terms += theme.keyword("raise");
        terms += " ";
        if let Some(s) = &self.expression {
            terms += s.pretty(theme);
        }
        terms.into()
    }
}
#[cfg(feature = "pretty-print")]
impl PrettyPrint for ControlNode {
    fn pretty(&self, theme: &PrettyProvider) -> PrettyTree {
        let mut terms = PrettySequence::new(3);
        terms += self.r#type.pretty(theme);
        if let Some(s) = &self.expression {
            terms += " ";
            terms += s.pretty(theme);
        }
        terms.into()
    }
}
#[cfg(feature = "pretty-print")]
impl PrettyPrint for ControlKind {
    fn pretty(&self, theme: &PrettyProvider) -> PrettyTree {
        theme.keyword(self.as_str())
    }
}