lua_parser/statement/
if_.rs

1use super::Block;
2use crate::Expression;
3use crate::Span;
4
5/// else-if fragment for if statements
6#[derive(Clone, Debug)]
7pub struct StmtElseIf {
8    pub condition: Expression,
9    pub block: Block,
10    pub span: Span,
11}
12impl StmtElseIf {
13    pub fn new(condition: Expression, block: Block, span: Span) -> Self {
14        Self {
15            condition,
16            block,
17            span,
18        }
19    }
20    /// get the span of the whole else-if fragment
21    pub fn span(&self) -> Span {
22        self.span
23    }
24}
25
26/// if statement
27#[derive(Clone, Debug)]
28pub struct StmtIf {
29    pub condition: Expression,
30    pub block: Block,
31    pub else_ifs: Vec<StmtElseIf>,
32    pub else_block: Option<Block>,
33    pub span: Span,
34}
35impl StmtIf {
36    pub fn new(
37        condition: Expression,
38        block: Block,
39        else_ifs: Vec<StmtElseIf>,
40        else_block: Option<Block>,
41        span: Span,
42    ) -> Self {
43        Self {
44            condition,
45            block,
46            else_ifs,
47            else_block,
48            span,
49        }
50    }
51    /// get the span of the whole if statement
52    pub fn span(&self) -> Span {
53        self.span
54    }
55}