lua_parser/statement/
functiondef.rs

1use crate::Span;
2use crate::SpannedString;
3
4/// function name.
5/// a sequence of identifiers separated by dots, and an optional colon followed by an identifier.
6/// e.g. `a.b.c:d`
7#[derive(Clone, Debug)]
8pub struct FunctionName {
9    /// dot chain
10    pub names: Vec<SpannedString>,
11    /// colon chain at the end
12    pub colon: Option<SpannedString>,
13
14    /// span of the whole function name
15    pub span: Span,
16}
17impl FunctionName {
18    pub fn new(names: Vec<SpannedString>, colon: Option<SpannedString>, span: Span) -> Self {
19        Self { names, colon, span }
20    }
21    /// get the span of the whole function name
22    pub fn span(&self) -> Span {
23        self.span
24    }
25}
26
27/// function definition statement.
28#[derive(Clone, Debug)]
29pub struct StmtFunctionDefinition {
30    pub name: FunctionName,
31    pub body: crate::expression::ExprFunction,
32    pub span: Span,
33}
34impl StmtFunctionDefinition {
35    pub fn new(name: FunctionName, body: crate::expression::ExprFunction, span: Span) -> Self {
36        Self { name, body, span }
37    }
38    /// get the span of the whole function definition statement
39    pub fn span(&self) -> Span {
40        self.span
41    }
42}
43
44/// local function definition statement.
45#[derive(Clone, Debug)]
46pub struct StmtFunctionDefinitionLocal {
47    pub name: SpannedString,
48    pub body: crate::expression::ExprFunction,
49    pub span: Span,
50}
51impl StmtFunctionDefinitionLocal {
52    pub fn new(name: SpannedString, body: crate::expression::ExprFunction, span: Span) -> Self {
53        Self { name, body, span }
54    }
55    /// get the span of the whole local function definition statement
56    pub fn span(&self) -> Span {
57        self.span
58    }
59}