lua_parser/statement/
localdecl.rs

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
use crate::Expression;
use crate::Span;
use crate::SpannedString;

/// local variable attribute.
/// either `const` or `close`.
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub enum Attrib {
    Const,
    Close,
}

/// pair of variable name and attribute.
#[derive(Clone, Debug)]
pub struct AttName {
    pub name: SpannedString,
    pub attrib: Option<Attrib>,
    pub span: Span,
}
impl AttName {
    pub fn new(name: SpannedString, attrib: Option<Attrib>, span: Span) -> Self {
        Self { name, attrib, span }
    }
    /// get the span of the whole variable name and attribute.
    pub fn span(&self) -> Span {
        self.span
    }
}

/// local variable declaration.
#[derive(Clone, Debug)]
pub struct StmtLocalDeclaration {
    pub names: Vec<AttName>,
    /// `Some` if the variables are initialized.
    pub values: Option<Vec<Expression>>,

    pub span: Span,
}
impl StmtLocalDeclaration {
    pub fn new(names: Vec<AttName>, values: Option<Vec<Expression>>, span: Span) -> Self {
        Self {
            names,
            values,
            span,
        }
    }
    /// get the span of the whole local variable declaration.
    pub fn span(&self) -> Span {
        self.span
    }
}