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