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