galvan_ast/item/
statement.rs

1use galvan_ast_macro::{AstNode, PrintAst};
2use typeunion::type_union;
3
4use super::*;
5use crate::item::closure::Closure;
6use crate::{AstNode, PrintAst, Span};
7
8#[derive(Clone, Debug, PartialEq, Eq, AstNode)]
9pub struct Body {
10    pub statements: Vec<Statement>,
11    pub span: Span,
12}
13
14#[derive(Clone, Debug, PartialEq, Eq, AstNode)]
15pub struct Block {
16    pub body: Body,
17    pub span: Span,
18}
19
20#[type_union]
21#[derive(Clone, Debug, PartialEq, Eq, AstNode)]
22pub type Statement = Assignment + Declaration + Expression + Return + Throw + Break + Continue; // + Block;
23
24#[derive(Clone, Debug, PartialEq, Eq, AstNode)]
25pub struct Declaration {
26    pub decl_modifier: DeclModifier,
27    pub identifier: Ident,
28    pub type_annotation: Option<TypeElement>,
29    pub assignment: Option<Expression>,
30    pub span: Span,
31}
32
33#[derive(Clone, Debug, PartialEq, Eq, AstNode)]
34pub struct Return {
35    pub expression: Expression,
36    pub is_explicit: bool,
37    pub span: Span,
38}
39
40#[derive(Clone, Debug, PartialEq, Eq, AstNode)]
41pub struct Throw {
42    pub expression: Expression,
43    pub span: Span,
44}
45
46#[derive(Clone, Debug, PartialEq, Eq, AstNode)]
47pub struct Break {
48    pub span: Span,
49}
50
51#[derive(Clone, Debug, PartialEq, Eq, AstNode)]
52pub struct Continue {
53    pub span: Span,
54}
55
56type Infix = Box<InfixExpression>;
57type Postfix = Box<PostfixExpression>;
58
59#[derive(Clone, Debug, PartialEq, Eq, PrintAst)]
60pub struct Group {
61    pub inner: Box<Expression>,
62}
63
64#[derive(Clone, Debug, PartialEq, Eq, AstNode)]
65pub struct Expression {
66    pub kind: ExpressionKind,
67    pub span: Span,
68}
69
70#[type_union]
71#[derive(Clone, Debug, PartialEq, Eq, PrintAst)]
72pub type ExpressionKind = ElseExpression
73    + FunctionCall
74    + Infix
75    + Postfix
76    + CollectionLiteral
77    + ConstructorCall
78    + EnumAccess
79    + Literal
80    + Ident
81    + Closure
82    + Group;
83
84#[derive(Clone, Debug, PartialEq, Eq, AstNode)]
85pub struct EnumAccess {
86    pub target: TypeIdent,
87    pub case: TypeIdent,
88    pub span: Span,
89}