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
use super::*;

mod display;

/// The top level elements in script mode.
#[derive(Clone, PartialEq, Eq, Hash, From)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum StatementKind {
    /// Placeholder for when the parser fails to parse a statement.
    Nothing,
    /// The documentation node, must have acceptor underneath.
    Document(Box<DocumentationList>),
    /// The annotation list node.
    Annotation(Box<AttributeList>),
    /// The namespace declaration node.
    Namespace(Box<NamespaceDeclaration>),
    /// The import statement node.
    Import(Box<ImportStatement>),
    /// The class declaration node.
    Class(Box<ClassDeclaration>),
    /// The union declaration node.
    Union(Box<UnionDeclaration>),
    /// The enumerate declaration node.
    Enumerate(Box<FlagDeclaration>),
    /// The trait declaration node
    Trait(Box<TraitDeclaration>),
    /// The type extension node
    Extends(Box<ExtendsStatement>),
    /// The function declaration node.
    Function(Box<FunctionDeclaration>),
    /// The let bind statement node.
    Variable(Box<LetBindNode>),
    /// The guard statement node.
    Guard(Box<GuardStatement>),
    /// The while loop statement node.
    While(Box<WhileLoop>),
    /// The for loop statement node.
    For(Box<ForLoop>),
    /// The argument argument node.
    Control(Box<ControlNode>),
    /// The argument argument node.
    Expression(Box<ExpressionNode>),
}

/// The valid terms in a class body.
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct StatementContext {}

impl StatementKind {
    /// Create a new expression node
    pub fn expression(body: ExpressionKind, span: Range<u32>) -> Self {
        Self::Expression(Box::new(ExpressionNode { omit: false, body, span: span.clone() }))
    }
    /// Create a new raw text node
    pub fn text<S: ToString>(s: S, span: Range<u32>) -> Self {
        let literal = StringTextNode { text: s.to_string(), span: span.clone() };
        Self::expression(ExpressionKind::Text(Box::new(literal)), span)
    }
}