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