emmylua_parser/syntax/node/lua/
stat.rs

1use crate::{
2    kind::{LuaSyntaxKind, LuaTokenKind},
3    syntax::{
4        comment_trait::LuaCommentOwner,
5        node::LuaNameToken,
6        traits::{LuaAstChildren, LuaAstNode, LuaAstTokenChildren},
7    },
8    LuaSyntaxNode,
9};
10
11use super::{
12    expr::{LuaCallExpr, LuaClosureExpr, LuaExpr, LuaVarExpr},
13    LuaBlock, LuaLocalName,
14};
15
16#[derive(Debug, Clone, PartialEq, Eq, Hash)]
17pub enum LuaStat {
18    LocalStat(LuaLocalStat),
19    AssignStat(LuaAssignStat),
20    CallExprStat(LuaCallExprStat),
21    FuncStat(LuaFuncStat),
22    LocalFuncStat(LuaLocalFuncStat),
23    IfStat(LuaIfStat),
24    WhileStat(LuaWhileStat),
25    DoStat(LuaDoStat),
26    ForStat(LuaForStat),
27    ForRangeStat(LuaForRangeStat),
28    RepeatStat(LuaRepeatStat),
29    BreakStat(LuaBreakStat),
30    ReturnStat(LuaReturnStat),
31    GotoStat(LuaGotoStat),
32    LabelStat(LuaLabelStat),
33    EmptyStat(LuaEmptyStat),
34}
35
36impl LuaAstNode for LuaStat {
37    fn syntax(&self) -> &LuaSyntaxNode {
38        match self {
39            LuaStat::LocalStat(node) => node.syntax(),
40            LuaStat::AssignStat(node) => node.syntax(),
41            LuaStat::CallExprStat(node) => node.syntax(),
42            LuaStat::FuncStat(node) => node.syntax(),
43            LuaStat::LocalFuncStat(node) => node.syntax(),
44            LuaStat::IfStat(node) => node.syntax(),
45            LuaStat::WhileStat(node) => node.syntax(),
46            LuaStat::DoStat(node) => node.syntax(),
47            LuaStat::ForStat(node) => node.syntax(),
48            LuaStat::ForRangeStat(node) => node.syntax(),
49            LuaStat::RepeatStat(node) => node.syntax(),
50            LuaStat::BreakStat(node) => node.syntax(),
51            LuaStat::ReturnStat(node) => node.syntax(),
52            LuaStat::GotoStat(node) => node.syntax(),
53            LuaStat::LabelStat(node) => node.syntax(),
54            LuaStat::EmptyStat(node) => node.syntax(),
55        }
56    }
57
58    fn can_cast(kind: LuaSyntaxKind) -> bool
59    where
60        Self: Sized,
61    {
62        match kind {
63            LuaSyntaxKind::LocalStat => true,
64            LuaSyntaxKind::AssignStat => true,
65            LuaSyntaxKind::CallExprStat => true,
66            LuaSyntaxKind::FuncStat => true,
67            LuaSyntaxKind::LocalFuncStat => true,
68            LuaSyntaxKind::IfStat => true,
69            LuaSyntaxKind::WhileStat => true,
70            LuaSyntaxKind::DoStat => true,
71            LuaSyntaxKind::ForStat => true,
72            LuaSyntaxKind::ForRangeStat => true,
73            LuaSyntaxKind::RepeatStat => true,
74            LuaSyntaxKind::BreakStat => true,
75            LuaSyntaxKind::ReturnStat => true,
76            LuaSyntaxKind::GotoStat => true,
77            LuaSyntaxKind::LabelStat => true,
78            LuaSyntaxKind::EmptyStat => true,
79            _ => false,
80        }
81    }
82
83    fn cast(syntax: LuaSyntaxNode) -> Option<Self>
84    where
85        Self: Sized,
86    {
87        match syntax.kind().into() {
88            LuaSyntaxKind::LocalStat => Some(LuaStat::LocalStat(LuaLocalStat::cast(syntax)?)),
89            LuaSyntaxKind::AssignStat => Some(LuaStat::AssignStat(LuaAssignStat::cast(syntax)?)),
90            LuaSyntaxKind::CallExprStat => {
91                Some(LuaStat::CallExprStat(LuaCallExprStat::cast(syntax)?))
92            }
93            LuaSyntaxKind::FuncStat => Some(LuaStat::FuncStat(LuaFuncStat::cast(syntax)?)),
94            LuaSyntaxKind::LocalFuncStat => {
95                Some(LuaStat::LocalFuncStat(LuaLocalFuncStat::cast(syntax)?))
96            }
97            LuaSyntaxKind::IfStat => Some(LuaStat::IfStat(LuaIfStat::cast(syntax)?)),
98            LuaSyntaxKind::WhileStat => Some(LuaStat::WhileStat(LuaWhileStat::cast(syntax)?)),
99            LuaSyntaxKind::DoStat => Some(LuaStat::DoStat(LuaDoStat::cast(syntax)?)),
100            LuaSyntaxKind::ForStat => Some(LuaStat::ForStat(LuaForStat::cast(syntax)?)),
101            LuaSyntaxKind::ForRangeStat => {
102                Some(LuaStat::ForRangeStat(LuaForRangeStat::cast(syntax)?))
103            }
104            LuaSyntaxKind::RepeatStat => Some(LuaStat::RepeatStat(LuaRepeatStat::cast(syntax)?)),
105            LuaSyntaxKind::BreakStat => Some(LuaStat::BreakStat(LuaBreakStat::cast(syntax)?)),
106            LuaSyntaxKind::ReturnStat => Some(LuaStat::ReturnStat(LuaReturnStat::cast(syntax)?)),
107            LuaSyntaxKind::GotoStat => Some(LuaStat::GotoStat(LuaGotoStat::cast(syntax)?)),
108            LuaSyntaxKind::LabelStat => Some(LuaStat::LabelStat(LuaLabelStat::cast(syntax)?)),
109            LuaSyntaxKind::EmptyStat => Some(LuaStat::EmptyStat(LuaEmptyStat::cast(syntax)?)),
110            _ => None,
111        }
112    }
113}
114
115impl LuaCommentOwner for LuaStat {}
116
117impl LuaStat {
118    pub fn get_parent_block(&self) -> Option<LuaBlock> {
119        LuaBlock::cast(self.syntax().parent()?)
120    }
121}
122
123#[derive(Debug, Clone, PartialEq, Eq, Hash)]
124pub struct LuaLocalStat {
125    syntax: LuaSyntaxNode,
126}
127
128impl LuaAstNode for LuaLocalStat {
129    fn syntax(&self) -> &LuaSyntaxNode {
130        &self.syntax
131    }
132
133    fn can_cast(kind: LuaSyntaxKind) -> bool
134    where
135        Self: Sized,
136    {
137        kind == LuaSyntaxKind::LocalStat
138    }
139
140    fn cast(syntax: LuaSyntaxNode) -> Option<Self>
141    where
142        Self: Sized,
143    {
144        if syntax.kind() == LuaSyntaxKind::LocalStat.into() {
145            Some(Self { syntax })
146        } else {
147            None
148        }
149    }
150}
151
152impl LuaCommentOwner for LuaLocalStat {}
153
154impl LuaLocalStat {
155    pub fn get_local_name_list(&self) -> LuaAstChildren<LuaLocalName> {
156        self.children()
157    }
158
159    pub fn get_value_exprs(&self) -> LuaAstChildren<LuaExpr> {
160        self.children()
161    }
162}
163
164#[derive(Debug, Clone, PartialEq, Eq, Hash)]
165pub struct LuaAssignStat {
166    syntax: LuaSyntaxNode,
167}
168
169impl LuaAstNode for LuaAssignStat {
170    fn syntax(&self) -> &LuaSyntaxNode {
171        &self.syntax
172    }
173
174    fn can_cast(kind: LuaSyntaxKind) -> bool
175    where
176        Self: Sized,
177    {
178        kind == LuaSyntaxKind::AssignStat
179    }
180
181    fn cast(syntax: LuaSyntaxNode) -> Option<Self>
182    where
183        Self: Sized,
184    {
185        if syntax.kind() == LuaSyntaxKind::AssignStat.into() {
186            Some(Self { syntax })
187        } else {
188            None
189        }
190    }
191}
192
193impl LuaCommentOwner for LuaAssignStat {}
194
195impl LuaAssignStat {
196    pub fn get_var_and_expr_list(&self) -> (Vec<LuaVarExpr>, Vec<LuaExpr>) {
197        let mut vars = Vec::new();
198        let mut exprs = Vec::new();
199        let mut meet_assign = false;
200        for child in self.syntax.children_with_tokens() {
201            if child.kind() == LuaTokenKind::TkAssign.into() {
202                meet_assign = true;
203            }
204
205            if let Some(node) = child.into_node() {
206                if meet_assign {
207                    if let Some(var) = LuaExpr::cast(node) {
208                        exprs.push(var);
209                    }
210                } else {
211                    if let Some(var) = LuaVarExpr::cast(node) {
212                        vars.push(var);
213                    }
214                }
215            }
216        }
217
218        (vars, exprs)
219    }
220}
221
222#[derive(Debug, Clone, PartialEq, Eq, Hash)]
223pub struct LuaCallExprStat {
224    syntax: LuaSyntaxNode,
225}
226
227impl LuaAstNode for LuaCallExprStat {
228    fn syntax(&self) -> &LuaSyntaxNode {
229        &self.syntax
230    }
231
232    fn can_cast(kind: LuaSyntaxKind) -> bool
233    where
234        Self: Sized,
235    {
236        kind == LuaSyntaxKind::CallExprStat
237    }
238
239    fn cast(syntax: LuaSyntaxNode) -> Option<Self>
240    where
241        Self: Sized,
242    {
243        if syntax.kind() == LuaSyntaxKind::CallExprStat.into() {
244            Some(Self { syntax })
245        } else {
246            None
247        }
248    }
249}
250
251impl LuaCommentOwner for LuaCallExprStat {}
252
253impl LuaCallExprStat {
254    pub fn get_call_expr(&self) -> Option<LuaCallExpr> {
255        self.child()
256    }
257}
258
259#[derive(Debug, Clone, PartialEq, Eq, Hash)]
260pub struct LuaFuncStat {
261    syntax: LuaSyntaxNode,
262}
263
264impl LuaAstNode for LuaFuncStat {
265    fn syntax(&self) -> &LuaSyntaxNode {
266        &self.syntax
267    }
268
269    fn can_cast(kind: LuaSyntaxKind) -> bool
270    where
271        Self: Sized,
272    {
273        kind == LuaSyntaxKind::FuncStat
274    }
275
276    fn cast(syntax: LuaSyntaxNode) -> Option<Self>
277    where
278        Self: Sized,
279    {
280        if syntax.kind() == LuaSyntaxKind::FuncStat.into() {
281            Some(Self { syntax })
282        } else {
283            None
284        }
285    }
286}
287
288impl LuaCommentOwner for LuaFuncStat {}
289
290impl LuaFuncStat {
291    pub fn get_func_name(&self) -> Option<LuaVarExpr> {
292        self.child()
293    }
294
295    pub fn get_closure(&self) -> Option<LuaClosureExpr> {
296        self.child()
297    }
298}
299
300#[derive(Debug, Clone, PartialEq, Eq, Hash)]
301pub struct LuaLocalFuncStat {
302    syntax: LuaSyntaxNode,
303}
304
305impl LuaAstNode for LuaLocalFuncStat {
306    fn syntax(&self) -> &LuaSyntaxNode {
307        &self.syntax
308    }
309
310    fn can_cast(kind: LuaSyntaxKind) -> bool
311    where
312        Self: Sized,
313    {
314        kind == LuaSyntaxKind::LocalFuncStat
315    }
316
317    fn cast(syntax: LuaSyntaxNode) -> Option<Self>
318    where
319        Self: Sized,
320    {
321        if syntax.kind() == LuaSyntaxKind::LocalFuncStat.into() {
322            Some(Self { syntax })
323        } else {
324            None
325        }
326    }
327}
328
329impl LuaCommentOwner for LuaLocalFuncStat {}
330
331impl LuaLocalFuncStat {
332    pub fn get_local_name(&self) -> Option<LuaLocalName> {
333        self.child()
334    }
335
336    pub fn get_closure(&self) -> Option<LuaClosureExpr> {
337        self.child()
338    }
339}
340
341#[derive(Debug, Clone, PartialEq, Eq, Hash)]
342pub struct LuaIfStat {
343    syntax: LuaSyntaxNode,
344}
345
346impl LuaAstNode for LuaIfStat {
347    fn syntax(&self) -> &LuaSyntaxNode {
348        &self.syntax
349    }
350
351    fn can_cast(kind: LuaSyntaxKind) -> bool
352    where
353        Self: Sized,
354    {
355        kind == LuaSyntaxKind::IfStat
356    }
357
358    fn cast(syntax: LuaSyntaxNode) -> Option<Self>
359    where
360        Self: Sized,
361    {
362        if syntax.kind() == LuaSyntaxKind::IfStat.into() {
363            Some(Self { syntax })
364        } else {
365            None
366        }
367    }
368}
369
370impl LuaCommentOwner for LuaIfStat {}
371
372impl LuaIfStat {
373    pub fn get_condition_expr(&self) -> Option<LuaExpr> {
374        self.child()
375    }
376
377    pub fn get_block(&self) -> Option<LuaBlock> {
378        self.child()
379    }
380    
381    pub fn get_else_if_clause_list(&self) -> LuaAstChildren<LuaElseIfClauseStat> {
382        self.children()
383    }
384    
385    pub fn get_else_clause(&self) -> Option<LuaElseClauseStat> {
386        self.child()
387    }
388
389    pub fn get_all_clause(&self) -> LuaAstChildren<LuaIfClauseStat> {
390        self.children()
391    }
392}
393
394#[derive(Debug, Clone, PartialEq, Eq, Hash)]
395pub struct LuaElseIfClauseStat {
396    syntax: LuaSyntaxNode,
397}
398
399impl LuaAstNode for LuaElseIfClauseStat {
400    fn syntax(&self) -> &LuaSyntaxNode {
401        &self.syntax
402    }
403
404    fn can_cast(kind: LuaSyntaxKind) -> bool
405    where
406        Self: Sized,
407    {
408        kind == LuaSyntaxKind::ElseIfClauseStat
409    }
410
411    fn cast(syntax: LuaSyntaxNode) -> Option<Self>
412    where
413        Self: Sized,
414    {
415        if syntax.kind() == LuaSyntaxKind::ElseIfClauseStat.into() {
416            Some(Self { syntax })
417        } else {
418            None
419        }
420    }
421}
422
423impl LuaCommentOwner for LuaElseIfClauseStat {}
424
425impl LuaElseIfClauseStat {
426    pub fn get_condition_expr(&self) -> Option<LuaExpr> {
427        self.child()
428    }
429
430    pub fn get_block(&self) -> Option<LuaBlock> {
431        self.child()
432    }
433}
434
435#[derive(Debug, Clone, PartialEq, Eq, Hash)]
436pub struct LuaElseClauseStat {
437    syntax: LuaSyntaxNode,
438}
439
440impl LuaAstNode for LuaElseClauseStat {
441    fn syntax(&self) -> &LuaSyntaxNode {
442        &self.syntax
443    }
444
445    fn can_cast(kind: LuaSyntaxKind) -> bool
446    where
447        Self: Sized,
448    {
449        kind == LuaSyntaxKind::ElseClauseStat
450    }
451
452    fn cast(syntax: LuaSyntaxNode) -> Option<Self>
453    where
454        Self: Sized,
455    {
456        if syntax.kind() == LuaSyntaxKind::ElseClauseStat.into() {
457            Some(Self { syntax })
458        } else {
459            None
460        }
461    }
462}
463
464impl LuaCommentOwner for LuaElseClauseStat {}
465
466impl LuaElseClauseStat {
467    pub fn get_block(&self) -> Option<LuaBlock> {
468        self.child()
469    }
470}
471
472#[derive(Debug, Clone, PartialEq, Eq, Hash)]
473pub enum LuaIfClauseStat {
474    ElseIf(LuaElseIfClauseStat),
475    Else(LuaElseClauseStat),
476}
477
478impl LuaAstNode for LuaIfClauseStat {
479    fn syntax(&self) -> &LuaSyntaxNode {
480        match self {
481            LuaIfClauseStat::ElseIf(node) => node.syntax(),
482            LuaIfClauseStat::Else(node) => node.syntax(),
483        }
484    }
485
486    fn can_cast(kind: LuaSyntaxKind) -> bool
487    where
488        Self: Sized {
489        LuaElseIfClauseStat::can_cast(kind) || LuaElseClauseStat::can_cast(kind)
490    }
491
492    fn cast(syntax: LuaSyntaxNode) -> Option<Self>
493    where
494        Self: Sized {
495        if LuaElseIfClauseStat::can_cast(syntax.kind().into()) {
496            Some(LuaIfClauseStat::ElseIf(LuaElseIfClauseStat::cast(syntax)?))
497        } else if LuaElseClauseStat::can_cast(syntax.kind().into()) {
498            Some(LuaIfClauseStat::Else(LuaElseClauseStat::cast(syntax)?))
499        } else {
500            None
501        }
502    }
503}
504
505impl LuaCommentOwner for LuaIfClauseStat {}
506
507impl LuaIfClauseStat {
508    pub fn get_parent_if_stat(&self) -> Option<LuaIfStat> {
509        LuaIfStat::cast(self.syntax().parent()?)
510    }
511
512    pub fn get_block(&self) -> Option<LuaBlock> {
513        match self {
514            LuaIfClauseStat::ElseIf(node) => node.get_block(),
515            LuaIfClauseStat::Else(node) => node.get_block(),
516        }
517    }
518
519    pub fn get_condition_expr(&self) -> Option<LuaExpr> {
520        match self {
521            LuaIfClauseStat::ElseIf(node) => node.get_condition_expr(),
522            LuaIfClauseStat::Else(_) => None,
523        }
524    }
525}
526
527#[derive(Debug, Clone, PartialEq, Eq, Hash)]
528pub struct LuaWhileStat {
529    syntax: LuaSyntaxNode,
530}
531
532impl LuaAstNode for LuaWhileStat {
533    fn syntax(&self) -> &LuaSyntaxNode {
534        &self.syntax
535    }
536
537    fn can_cast(kind: LuaSyntaxKind) -> bool
538    where
539        Self: Sized,
540    {
541        kind == LuaSyntaxKind::WhileStat
542    }
543
544    fn cast(syntax: LuaSyntaxNode) -> Option<Self>
545    where
546        Self: Sized,
547    {
548        if syntax.kind() == LuaSyntaxKind::WhileStat.into() {
549            Some(Self { syntax })
550        } else {
551            None
552        }
553    }
554}
555
556impl LuaCommentOwner for LuaWhileStat {}
557
558impl LuaWhileStat {
559    pub fn get_condition_expr(&self) -> Option<LuaExpr> {
560        self.child()
561    }
562
563    pub fn get_block(&self) -> Option<LuaBlock> {
564        self.child()
565    }
566}
567
568#[derive(Debug, Clone, PartialEq, Eq, Hash)]
569pub struct LuaDoStat {
570    syntax: LuaSyntaxNode,
571}
572
573impl LuaAstNode for LuaDoStat {
574    fn syntax(&self) -> &LuaSyntaxNode {
575        &self.syntax
576    }
577
578    fn can_cast(kind: LuaSyntaxKind) -> bool
579    where
580        Self: Sized,
581    {
582        kind == LuaSyntaxKind::DoStat
583    }
584
585    fn cast(syntax: LuaSyntaxNode) -> Option<Self>
586    where
587        Self: Sized,
588    {
589        if syntax.kind() == LuaSyntaxKind::DoStat.into() {
590            Some(Self { syntax })
591        } else {
592            None
593        }
594    }
595}
596
597impl LuaCommentOwner for LuaDoStat {}
598
599impl LuaDoStat {
600    pub fn get_block(&self) -> Option<LuaBlock> {
601        self.child()
602    }
603}
604
605#[derive(Debug, Clone, PartialEq, Eq, Hash)]
606pub struct LuaForStat {
607    syntax: LuaSyntaxNode,
608}
609
610impl LuaAstNode for LuaForStat {
611    fn syntax(&self) -> &LuaSyntaxNode {
612        &self.syntax
613    }
614
615    fn can_cast(kind: LuaSyntaxKind) -> bool
616    where
617        Self: Sized,
618    {
619        kind == LuaSyntaxKind::ForStat
620    }
621
622    fn cast(syntax: LuaSyntaxNode) -> Option<Self>
623    where
624        Self: Sized,
625    {
626        if syntax.kind() == LuaSyntaxKind::ForStat.into() {
627            Some(Self { syntax })
628        } else {
629            None
630        }
631    }
632}
633
634impl LuaCommentOwner for LuaForStat {}
635
636impl LuaForStat {
637    pub fn get_var_name(&self) -> Option<LuaNameToken> {
638        self.token()
639    }
640
641    pub fn get_iter_expr(&self) -> LuaAstChildren<LuaExpr> {
642        self.children()
643    }
644
645    pub fn get_block(&self) -> Option<LuaBlock> {
646        self.child()
647    }
648}
649
650#[derive(Debug, Clone, PartialEq, Eq, Hash)]
651pub struct LuaForRangeStat {
652    syntax: LuaSyntaxNode,
653}
654
655impl LuaAstNode for LuaForRangeStat {
656    fn syntax(&self) -> &LuaSyntaxNode {
657        &self.syntax
658    }
659
660    fn can_cast(kind: LuaSyntaxKind) -> bool
661    where
662        Self: Sized,
663    {
664        kind == LuaSyntaxKind::ForRangeStat
665    }
666
667    fn cast(syntax: LuaSyntaxNode) -> Option<Self>
668    where
669        Self: Sized,
670    {
671        if syntax.kind() == LuaSyntaxKind::ForRangeStat.into() {
672            Some(Self { syntax })
673        } else {
674            None
675        }
676    }
677}
678
679impl LuaCommentOwner for LuaForRangeStat {}
680
681impl LuaForRangeStat {
682    pub fn get_var_name_list(&self) -> LuaAstTokenChildren<LuaNameToken> {
683        self.tokens()
684    }
685
686    pub fn get_expr_list(&self) -> LuaAstChildren<LuaExpr> {
687        self.children()
688    }
689
690    pub fn get_block(&self) -> Option<LuaBlock> {
691        self.child()
692    }
693}
694
695#[derive(Debug, Clone, PartialEq, Eq, Hash)]
696pub struct LuaRepeatStat {
697    syntax: LuaSyntaxNode,
698}
699
700impl LuaAstNode for LuaRepeatStat {
701    fn syntax(&self) -> &LuaSyntaxNode {
702        &self.syntax
703    }
704
705    fn can_cast(kind: LuaSyntaxKind) -> bool
706    where
707        Self: Sized,
708    {
709        kind == LuaSyntaxKind::RepeatStat
710    }
711
712    fn cast(syntax: LuaSyntaxNode) -> Option<Self>
713    where
714        Self: Sized,
715    {
716        if syntax.kind() == LuaSyntaxKind::RepeatStat.into() {
717            Some(Self { syntax })
718        } else {
719            None
720        }
721    }
722}
723
724impl LuaCommentOwner for LuaRepeatStat {}
725
726impl LuaRepeatStat {
727    pub fn get_block(&self) -> Option<LuaBlock> {
728        self.child()
729    }
730
731    pub fn get_condition_expr(&self) -> Option<LuaExpr> {
732        self.child()
733    }
734}
735
736#[derive(Debug, Clone, PartialEq, Eq, Hash)]
737pub struct LuaBreakStat {
738    syntax: LuaSyntaxNode,
739}
740
741impl LuaAstNode for LuaBreakStat {
742    fn syntax(&self) -> &LuaSyntaxNode {
743        &self.syntax
744    }
745
746    fn can_cast(kind: LuaSyntaxKind) -> bool
747    where
748        Self: Sized,
749    {
750        kind == LuaSyntaxKind::BreakStat
751    }
752
753    fn cast(syntax: LuaSyntaxNode) -> Option<Self>
754    where
755        Self: Sized,
756    {
757        if syntax.kind() == LuaSyntaxKind::BreakStat.into() {
758            Some(Self { syntax })
759        } else {
760            None
761        }
762    }
763}
764
765impl LuaCommentOwner for LuaBreakStat {}
766
767#[derive(Debug, Clone, PartialEq, Eq, Hash)]
768pub struct LuaReturnStat {
769    syntax: LuaSyntaxNode,
770}
771
772impl LuaAstNode for LuaReturnStat {
773    fn syntax(&self) -> &LuaSyntaxNode {
774        &self.syntax
775    }
776
777    fn can_cast(kind: LuaSyntaxKind) -> bool
778    where
779        Self: Sized,
780    {
781        kind == LuaSyntaxKind::ReturnStat
782    }
783
784    fn cast(syntax: LuaSyntaxNode) -> Option<Self>
785    where
786        Self: Sized,
787    {
788        if syntax.kind() == LuaSyntaxKind::ReturnStat.into() {
789            Some(Self { syntax })
790        } else {
791            None
792        }
793    }
794}
795
796impl LuaCommentOwner for LuaReturnStat {}
797
798impl LuaReturnStat {
799    pub fn get_expr_list(&self) -> LuaAstChildren<LuaExpr> {
800        self.children()
801    }
802}
803
804#[derive(Debug, Clone, PartialEq, Eq, Hash)]
805pub struct LuaGotoStat {
806    syntax: LuaSyntaxNode,
807}
808
809impl LuaAstNode for LuaGotoStat {
810    fn syntax(&self) -> &LuaSyntaxNode {
811        &self.syntax
812    }
813
814    fn can_cast(kind: LuaSyntaxKind) -> bool
815    where
816        Self: Sized,
817    {
818        kind == LuaSyntaxKind::GotoStat
819    }
820
821    fn cast(syntax: LuaSyntaxNode) -> Option<Self>
822    where
823        Self: Sized,
824    {
825        if syntax.kind() == LuaSyntaxKind::GotoStat.into() {
826            Some(Self { syntax })
827        } else {
828            None
829        }
830    }
831}
832
833impl LuaCommentOwner for LuaGotoStat {}
834
835impl LuaGotoStat {
836    pub fn get_label_name_token(&self) -> Option<LuaNameToken> {
837        self.token()
838    }
839}
840
841#[derive(Debug, Clone, PartialEq, Eq, Hash)]
842pub struct LuaLabelStat {
843    syntax: LuaSyntaxNode,
844}
845
846impl LuaAstNode for LuaLabelStat {
847    fn syntax(&self) -> &LuaSyntaxNode {
848        &self.syntax
849    }
850
851    fn can_cast(kind: LuaSyntaxKind) -> bool
852    where
853        Self: Sized,
854    {
855        kind == LuaSyntaxKind::LabelStat
856    }
857
858    fn cast(syntax: LuaSyntaxNode) -> Option<Self>
859    where
860        Self: Sized,
861    {
862        if syntax.kind() == LuaSyntaxKind::LabelStat.into() {
863            Some(Self { syntax })
864        } else {
865            None
866        }
867    }
868}
869
870impl LuaCommentOwner for LuaLabelStat {}
871
872impl LuaLabelStat {
873    pub fn get_label_name_token(&self) -> Option<LuaNameToken> {
874        self.token()
875    }
876}
877
878#[derive(Debug, Clone, PartialEq, Eq, Hash)]
879pub struct LuaEmptyStat {
880    syntax: LuaSyntaxNode,
881}
882
883impl LuaAstNode for LuaEmptyStat {
884    fn syntax(&self) -> &LuaSyntaxNode {
885        &self.syntax
886    }
887
888    fn can_cast(kind: LuaSyntaxKind) -> bool
889    where
890        Self: Sized,
891    {
892        kind == LuaSyntaxKind::EmptyStat
893    }
894
895    fn cast(syntax: LuaSyntaxNode) -> Option<Self>
896    where
897        Self: Sized,
898    {
899        if syntax.kind() == LuaSyntaxKind::EmptyStat.into() {
900            Some(Self { syntax })
901        } else {
902            None
903        }
904    }
905}
906
907impl LuaCommentOwner for LuaEmptyStat {}