teo_parser/ast/
node.rs

1use std::collections::BTreeMap;
2use std::fmt::{Display, Formatter};
3use crate::ast::argument::Argument;
4use crate::ast::argument_declaration::{ArgumentDeclaration};
5use crate::ast::argument_list::ArgumentList;
6use crate::ast::argument_list_declaration::ArgumentListDeclaration;
7use crate::ast::arith_expr::{ArithExpr, BinaryOperation, UnaryOperation, UnaryPostfixOperation};
8use crate::ast::availability_flag::AvailabilityFlag;
9use crate::ast::availability_flag_end::AvailabilityFlagEnd;
10use crate::ast::bracket_expression::BracketExpression;
11use crate::ast::code_comment::CodeComment;
12use crate::ast::doc_comment::DocComment;
13use crate::ast::config::Config;
14use crate::ast::config_declaration::ConfigDeclaration;
15use crate::ast::keyword::Keyword;
16use crate::ast::constant_declaration::ConstantDeclaration;
17use crate::ast::data_set::{DataSet, DataSetGroup, DataSetRecord};
18use crate::ast::decorator::Decorator;
19use crate::ast::decorator_declaration::{DecoratorDeclaration, DecoratorDeclarationVariant};
20use crate::ast::empty_decorator::EmptyDecorator;
21use crate::ast::empty_dot::EmptyDot;
22use crate::ast::empty_pipeline::EmptyPipeline;
23use crate::ast::expression::Expression;
24use crate::ast::field::Field;
25use crate::ast::function_declaration::FunctionDeclaration;
26use crate::ast::generics::{GenericsConstraint, GenericsConstraintItem, GenericsDeclaration};
27use crate::ast::group::Group;
28use crate::ast::handler::{HandlerDeclaration, HandlerGroupDeclaration};
29use crate::ast::handler_template_declaration::HandlerTemplateDeclaration;
30use crate::ast::identifier::Identifier;
31use crate::ast::identifier_path::IdentifierPath;
32use crate::ast::import::Import;
33use crate::ast::include_handler_from_template::IncludeHandlerFromTemplate;
34use crate::ast::int_subscript::IntSubscript;
35use crate::ast::interface::InterfaceDeclaration;
36use crate::ast::literals::{ArrayLiteral, BoolLiteral, DictionaryLiteral, EnumVariantLiteral, NullLiteral, NumericLiteral, RegexLiteral, StringLiteral, TupleLiteral};
37use crate::ast::middleware::MiddlewareDeclaration;
38use crate::ast::model::Model;
39use crate::ast::named_expression::NamedExpression;
40use crate::ast::namespace::Namespace;
41use crate::ast::operators::Operator;
42use crate::ast::partial_argument::PartialArgument;
43use crate::ast::partial_argument_declaration::PartialArgumentDeclaration;
44use crate::ast::partial_field::PartialField;
45use crate::ast::pipeline::Pipeline;
46use crate::ast::pipeline_item_declaration::{PipelineItemDeclaration, PipelineItemDeclarationVariant};
47use crate::ast::punctuations::Punctuation;
48use crate::ast::r#enum::{Enum, EnumMember};
49use crate::ast::span::Span;
50use crate::ast::struct_declaration::StructDeclaration;
51use crate::ast::subscript::Subscript;
52use crate::ast::synthesized_shape_declaration::SynthesizedShapeDeclaration;
53use crate::ast::synthesized_shape_field_declaration::SynthesizedShapeFieldDeclaration;
54use crate::ast::type_as_value_expression::TypeAsValueExpression;
55use crate::ast::type_expr::{TypeBinaryOperation, TypedEnum, TypedShape, TypedShapeItem, TypeExpr, TypeGenerics, TypeGroup, TypeItem, TypeSubscript, TypeTuple};
56use crate::ast::unit::Unit;
57use crate::ast::use_middlewares::UseMiddlewaresBlock;
58use crate::availability::Availability;
59use crate::format::Writer;
60use crate::traits::has_availability::HasAvailability;
61use crate::traits::identifiable::Identifiable;
62use crate::traits::named_identifiable::NamedIdentifiable;
63use crate::traits::node_trait::NodeTrait;
64use crate::traits::write::Write;
65
66#[derive(Debug)]
67pub enum Node {
68    Argument(Argument),
69    ArgumentList(ArgumentList),
70    ArgumentListDeclaration(ArgumentListDeclaration),
71    ArgumentDeclaration(ArgumentDeclaration),
72    ArithExpr(ArithExpr),
73    UnaryOperation(UnaryOperation),
74    UnaryPostfixOperation(UnaryPostfixOperation),
75    BinaryOperation(BinaryOperation),
76    AvailabilityFlag(AvailabilityFlag),
77    AvailabilityFlagEnd(AvailabilityFlagEnd),
78    CodeComment(CodeComment),
79    DocComment(DocComment),
80    Config(Config),
81    Keyword(Keyword),
82    ConfigDeclaration(ConfigDeclaration),
83    ConstantDeclaration(ConstantDeclaration),
84    DataSet(DataSet),
85    DataSetGroup(DataSetGroup),
86    DataSetRecord(DataSetRecord),
87    Decorator(Decorator),
88    DecoratorDeclaration(DecoratorDeclaration),
89    DecoratorDeclarationVariant(DecoratorDeclarationVariant),
90    Enum(Enum),
91    EnumMember(EnumMember),
92    Expression(Expression),
93    NamedExpression(NamedExpression),
94    BracketExpression(BracketExpression),
95    Group(Group),
96    NumericLiteral(NumericLiteral),
97    StringLiteral(StringLiteral),
98    RegexLiteral(RegexLiteral),
99    BoolLiteral(BoolLiteral),
100    NullLiteral(NullLiteral),
101    EnumVariantLiteral(EnumVariantLiteral),
102    TupleLiteral(TupleLiteral),
103    ArrayLiteral(ArrayLiteral),
104    DictionaryLiteral(DictionaryLiteral),
105    Identifier(Identifier),
106    Subscript(Subscript),
107    IntSubscript(IntSubscript),
108    Unit(Unit),
109    Pipeline(Pipeline),
110    EmptyPipeline(EmptyPipeline),
111    Field(Field),
112    FunctionDeclaration(FunctionDeclaration),
113    GenericsDeclaration(GenericsDeclaration),
114    GenericsConstraint(GenericsConstraint),
115    GenericsConstraintItem(GenericsConstraintItem),
116    HandlerGroupDeclaration(HandlerGroupDeclaration),
117    HandlerDeclaration(HandlerDeclaration),
118    IdentifierPath(IdentifierPath),
119    Import(Import),
120    InterfaceDeclaration(InterfaceDeclaration),
121    MiddlewareDeclaration(MiddlewareDeclaration),
122    Model(Model),
123    Namespace(Namespace),
124    PipelineItemDeclaration(PipelineItemDeclaration),
125    PipelineItemDeclarationVariant(PipelineItemDeclarationVariant),
126    StructDeclaration(StructDeclaration),
127    TypeExpr(TypeExpr),
128    TypeBinaryOperation(TypeBinaryOperation),
129    TypeGroup(TypeGroup),
130    TypeTuple(TypeTuple),
131    TypeSubscript(TypeSubscript),
132    TypeItem(TypeItem),
133    TypeGenerics(TypeGenerics),
134    UseMiddlewaresBlock(UseMiddlewaresBlock),
135    Punctuation(Punctuation),
136    Operator(Operator),
137    EmptyDot(EmptyDot),
138    PartialField(PartialField),
139    PartialArgumentDeclaration(PartialArgumentDeclaration),
140    PartialArgument(PartialArgument),
141    EmptyDecorator(EmptyDecorator),
142    TypedEnum(TypedEnum),
143    TypedShape(TypedShape),
144    TypedShapeItem(TypedShapeItem),
145    SynthesizedShapeDeclaration(SynthesizedShapeDeclaration),
146    SynthesizedShapeFieldDeclaration(SynthesizedShapeFieldDeclaration),
147    HandlerTemplateDeclaration(HandlerTemplateDeclaration),
148    IncludeHandlerFromTemplate(IncludeHandlerFromTemplate),
149    TypeAsValueExpression(TypeAsValueExpression),
150}
151
152impl Node {
153
154    pub fn is_argument(&self) -> bool {
155        self.as_argument().is_some()
156    }
157
158    pub fn as_argument(&self) -> Option<&Argument> {
159        match self {
160            Node::Argument(c) => Some(c),
161            _ => None,
162        }
163    }
164
165    pub fn is_argument_list(&self) -> bool {
166        self.as_argument_list().is_some()
167    }
168
169    pub fn as_argument_list(&self) -> Option<&ArgumentList> {
170        match self {
171            Node::ArgumentList(c) => Some(c),
172            _ => None,
173        }
174    }
175
176    pub fn is_argument_list_declaration(&self) -> bool {
177        self.as_argument_list_declaration().is_some()
178    }
179
180    pub fn as_argument_list_declaration(&self) -> Option<&ArgumentListDeclaration> {
181        match self {
182            Node::ArgumentListDeclaration(c) => Some(c),
183            _ => None,
184        }
185    }
186
187    pub fn is_argument_declaration(&self) -> bool {
188        self.as_argument_declaration().is_some()
189    }
190
191    pub fn as_argument_declaration(&self) -> Option<&ArgumentDeclaration> {
192        match self {
193            Node::ArgumentDeclaration(c) => Some(c),
194            _ => None,
195        }
196    }
197
198    pub fn is_arith_expr(&self) -> bool {
199        self.as_arith_expr().is_some()
200    }
201
202    pub fn as_arith_expr(&self) -> Option<&ArithExpr> {
203        match self {
204            Node::ArithExpr(c) => Some(c),
205            _ => None,
206        }
207    }
208    
209    pub fn is_unary_operation(&self) -> bool {
210        self.as_unary_operation().is_some()
211    }
212
213    pub fn as_unary_operation(&self) -> Option<&UnaryOperation> {
214        match self {
215            Node::UnaryOperation(c) => Some(c),
216            _ => None,
217        }
218    }
219    
220    pub fn is_unary_postfix_operation(&self) -> bool {
221        self.as_unary_postfix_operation().is_some()
222    }
223
224    pub fn as_unary_postfix_operation(&self) -> Option<&UnaryPostfixOperation> {
225        match self {
226            Node::UnaryPostfixOperation(c) => Some(c),
227            _ => None,
228        }
229    }
230    
231    pub fn is_binary_operation(&self) -> bool {
232        self.as_binary_operation().is_some()
233    }
234
235    pub fn as_binary_operation(&self) -> Option<&BinaryOperation> {
236        match self {
237            Node::BinaryOperation(c) => Some(c),
238            _ => None,
239        }
240    }
241    
242    pub fn is_availability_flag(&self) -> bool {
243        self.as_availability_flag().is_some()
244    }
245
246    pub fn as_availability_flag(&self) -> Option<&AvailabilityFlag> {
247        match self {
248            Node::AvailabilityFlag(c) => Some(c),
249            _ => None,
250        }
251    }
252    
253    pub fn is_availability_flag_end(&self) -> bool {
254        self.as_availability_flag_end().is_some()
255    }
256
257    pub fn as_availability_flag_end(&self) -> Option<&AvailabilityFlagEnd> {
258        match self {
259            Node::AvailabilityFlagEnd(c) => Some(c),
260            _ => None,
261        }
262    }
263    
264    pub fn is_code_comment(&self) -> bool {
265        self.as_code_comment().is_some()
266    }
267
268    pub fn as_code_comment(&self) -> Option<&CodeComment> {
269        match self {
270            Node::CodeComment(c) => Some(c),
271            _ => None,
272        }
273    }
274
275    pub fn is_doc_comment(&self) -> bool {
276        self.as_doc_comment().is_some()
277    }
278
279    pub fn as_doc_comment(&self) -> Option<&DocComment> {
280        match self {
281            Node::DocComment(c) => Some(c),
282            _ => None,
283        }
284    }
285    
286    pub fn is_config(&self) -> bool {
287        self.as_config().is_some()
288    }
289
290    pub fn as_config(&self) -> Option<&Config> {
291        match self {
292            Node::Config(c) => Some(c),
293            _ => None,
294        }
295    }
296
297    pub fn is_keyword(&self) -> bool {
298        self.as_keyword().is_some()
299    }
300
301    pub fn as_keyword(&self) -> Option<&Keyword> {
302        match self {
303            Node::Keyword(c) => Some(c),
304            _ => None,
305        }
306    }
307    
308    pub fn is_config_declaration(&self) -> bool {
309        self.as_config_declaration().is_some()
310    }
311
312    pub fn as_config_declaration(&self) -> Option<&ConfigDeclaration> {
313        match self {
314            Node::ConfigDeclaration(c) => Some(c),
315            _ => None,
316        }
317    }
318
319    pub fn is_constant_declaration(&self) -> bool {
320        self.as_constant_declaration().is_some()
321    }
322
323    pub fn as_constant_declaration(&self) -> Option<&ConstantDeclaration> {
324        match self {
325            Node::ConstantDeclaration(c) => Some(c),
326            _ => None,
327        }
328    }
329
330    pub fn is_data_set(&self) -> bool {
331        self.as_data_set().is_some()
332    }
333
334    pub fn as_data_set(&self) -> Option<&DataSet> {
335        match self {
336            Node::DataSet(c) => Some(c),
337            _ => None,
338        }
339    }
340
341    pub fn is_data_set_group(&self) -> bool {
342        self.as_data_set_group().is_some()
343    }
344
345    pub fn as_data_set_group(&self) -> Option<&DataSetGroup> {
346        match self {
347            Node::DataSetGroup(c) => Some(c),
348            _ => None,
349        }
350    }
351
352    pub fn is_data_set_record(&self) -> bool {
353        self.as_data_set_record().is_some()
354    }
355
356    pub fn as_data_set_record(&self) -> Option<&DataSetRecord> {
357        match self {
358            Node::DataSetRecord(c) => Some(c),
359            _ => None,
360        }
361    }
362
363    pub fn is_decorator(&self) -> bool {
364        self.as_decorator().is_some()
365    }
366
367    pub fn as_decorator(&self) -> Option<&Decorator> {
368        match self {
369            Node::Decorator(c) => Some(c),
370            _ => None,
371        }
372    }
373
374    pub fn is_decorator_declaration(&self) -> bool {
375        self.as_decorator_declaration().is_some()
376    }
377
378    pub fn as_decorator_declaration(&self) -> Option<&DecoratorDeclaration> {
379        match self {
380            Node::DecoratorDeclaration(c) => Some(c),
381            _ => None,
382        }
383    }
384
385    pub fn is_decorator_declaration_variant(&self) -> bool {
386        self.as_decorator_declaration_variant().is_some()
387    }
388
389    pub fn as_decorator_declaration_variant(&self) -> Option<&DecoratorDeclarationVariant> {
390        match self {
391            Node::DecoratorDeclarationVariant(c) => Some(c),
392            _ => None,
393        }
394    }
395
396    pub fn is_enum(&self) -> bool {
397        self.as_enum().is_some()
398    }
399
400    pub fn as_enum(&self) -> Option<&Enum> {
401        match self {
402            Node::Enum(c) => Some(c),
403            _ => None,
404        }
405    }
406
407    pub fn is_enum_member(&self) -> bool {
408        self.as_enum_member().is_some()
409    }
410
411    pub fn as_enum_member(&self) -> Option<&EnumMember> {
412        match self {
413            Node::EnumMember(c) => Some(c),
414            _ => None,
415        }
416    }
417
418    pub fn is_expression(&self) -> bool {
419        self.as_expression().is_some()
420    }
421
422    pub fn as_expression(&self) -> Option<&Expression> {
423        match self {
424            Node::Expression(c) => Some(c),
425            _ => None,
426        }
427    }
428
429    pub fn is_named_expression(&self) -> bool {
430        self.as_named_expression().is_some()
431    }
432
433    pub fn as_named_expression(&self) -> Option<&NamedExpression> {
434        match self {
435            Node::NamedExpression(c) => Some(c),
436            _ => None,
437        }
438    }
439
440    pub fn is_bracket_expression(&self) -> bool {
441        self.as_bracket_expression().is_some()
442    }
443
444    pub fn as_bracket_expression(&self) -> Option<&BracketExpression> {
445        match self {
446            Node::BracketExpression(c) => Some(c),
447            _ => None,
448        }
449    }
450
451    pub fn is_group(&self) -> bool {
452        self.as_group().is_some()
453    }
454
455    pub fn as_group(&self) -> Option<&Group> {
456        match self {
457            Node::Group(c) => Some(c),
458            _ => None,
459        }
460    }
461
462    pub fn is_numeric_literal(&self) -> bool {
463        self.as_numeric_literal().is_some()
464    }
465
466    pub fn as_numeric_literal(&self) -> Option<&NumericLiteral> {
467        match self {
468            Node::NumericLiteral(c) => Some(c),
469            _ => None,
470        }
471    }
472
473    pub fn is_string_literal(&self) -> bool {
474        self.as_string_literal().is_some()
475    }
476
477    pub fn as_string_literal(&self) -> Option<&StringLiteral> {
478        match self {
479            Node::StringLiteral(c) => Some(c),
480            _ => None,
481        }
482    }
483
484    pub fn is_regex_literal(&self) -> bool {
485        self.as_regex_literal().is_some()
486    }
487
488    pub fn as_regex_literal(&self) -> Option<&RegexLiteral> {
489        match self {
490            Node::RegexLiteral(c) => Some(c),
491            _ => None,
492        }
493    }
494
495    pub fn is_bool_literal(&self) -> bool {
496        self.as_bool_literal().is_some()
497    }
498
499    pub fn as_bool_literal(&self) -> Option<&BoolLiteral> {
500        match self {
501            Node::BoolLiteral(c) => Some(c),
502            _ => None,
503        }
504    }
505
506    pub fn is_null_literal(&self) -> bool {
507        self.as_null_literal().is_some()
508    }
509
510    pub fn as_null_literal(&self) -> Option<&NullLiteral> {
511        match self {
512            Node::NullLiteral(c) => Some(c),
513            _ => None,
514        }
515    }
516
517    pub fn is_enum_variant_literal(&self) -> bool {
518        self.as_enum_variant_literal().is_some()
519    }
520
521    pub fn as_enum_variant_literal(&self) -> Option<&EnumVariantLiteral> {
522        match self {
523            Node::EnumVariantLiteral(c) => Some(c),
524            _ => None,
525        }
526    }
527
528    pub fn is_tuple_literal(&self) -> bool {
529        self.as_tuple_literal().is_some()
530    }
531
532    pub fn as_tuple_literal(&self) -> Option<&TupleLiteral> {
533        match self {
534            Node::TupleLiteral(c) => Some(c),
535            _ => None,
536        }
537    }
538
539    pub fn is_array_literal(&self) -> bool {
540        self.as_array_literal().is_some()
541    }
542
543    pub fn as_array_literal(&self) -> Option<&ArrayLiteral> {
544        match self {
545            Node::ArrayLiteral(c) => Some(c),
546            _ => None,
547        }
548    }
549
550    pub fn is_dictionary_literal(&self) -> bool {
551        self.as_dictionary_literal().is_some()
552    }
553
554    pub fn as_dictionary_literal(&self) -> Option<&DictionaryLiteral> {
555        match self {
556            Node::DictionaryLiteral(c) => Some(c),
557            _ => None,
558        }
559    }
560
561    pub fn is_identifier(&self) -> bool {
562        self.as_identifier().is_some()
563    }
564
565    pub fn as_identifier(&self) -> Option<&Identifier> {
566        match self {
567            Node::Identifier(c) => Some(c),
568            _ => None,
569        }
570    }
571
572    pub fn is_subscript(&self) -> bool {
573        self.as_subscript().is_some()
574    }
575
576    pub fn as_subscript(&self) -> Option<&Subscript> {
577        match self {
578            Node::Subscript(c) => Some(c),
579            _ => None,
580        }
581    }
582
583    pub fn is_int_subscript(&self) -> bool {
584        self.as_int_subscript().is_some()
585    }
586
587    pub fn as_int_subscript(&self) -> Option<&IntSubscript> {
588        match self {
589            Node::IntSubscript(c) => Some(c),
590            _ => None,
591        }
592    }
593
594    pub fn is_unit(&self) -> bool {
595        self.as_unit().is_some()
596    }
597
598    pub fn as_unit(&self) -> Option<&Unit> {
599        match self {
600            Node::Unit(c) => Some(c),
601            _ => None,
602        }
603    }
604
605    pub fn is_pipeline(&self) -> bool {
606        self.as_pipeline().is_some()
607    }
608
609    pub fn as_pipeline(&self) -> Option<&Pipeline> {
610        match self {
611            Node::Pipeline(c) => Some(c),
612            _ => None,
613        }
614    }
615
616    pub fn is_empty_pipeline(&self) -> bool {
617        self.as_empty_pipeline().is_some()
618    }
619
620    pub fn as_empty_pipeline(&self) -> Option<&EmptyPipeline> {
621        match self {
622            Node::EmptyPipeline(c) => Some(c),
623            _ => None,
624        }
625    }
626
627    pub fn is_field(&self) -> bool {
628        self.as_field().is_some()
629    }
630
631    pub fn as_field(&self) -> Option<&Field> {
632        match self {
633            Node::Field(c) => Some(c),
634            _ => None,
635        }
636    }
637
638    pub fn is_function_declaration(&self) -> bool {
639        self.as_function_declaration().is_some()
640    }
641
642    pub fn as_function_declaration(&self) -> Option<&FunctionDeclaration> {
643        match self {
644            Node::FunctionDeclaration(c) => Some(c),
645            _ => None,
646        }
647    }
648
649    pub fn is_generics_declaration(&self) -> bool {
650        self.as_generics_declaration().is_some()
651    }
652
653    pub fn as_generics_declaration(&self) -> Option<&GenericsDeclaration> {
654        match self {
655            Node::GenericsDeclaration(c) => Some(c),
656            _ => None,
657        }
658    }
659
660    pub fn is_generics_constraint(&self) -> bool {
661        self.as_generics_constraint().is_some()
662    }
663
664    pub fn as_generics_constraint(&self) -> Option<&GenericsConstraint> {
665        match self {
666            Node::GenericsConstraint(c) => Some(c),
667            _ => None,
668        }
669    }
670
671    pub fn is_generics_constraint_item(&self) -> bool {
672        self.as_generics_constraint_item().is_some()
673    }
674
675    pub fn as_generics_constraint_item(&self) -> Option<&GenericsConstraintItem> {
676        match self {
677            Node::GenericsConstraintItem(c) => Some(c),
678            _ => None,
679        }
680    }
681
682    pub fn is_handler_group_declaration(&self) -> bool {
683        self.as_handler_group_declaration().is_some()
684    }
685
686    pub fn as_handler_group_declaration(&self) -> Option<&HandlerGroupDeclaration> {
687        match self {
688            Node::HandlerGroupDeclaration(c) => Some(c),
689            _ => None,
690        }
691    }
692
693    pub fn is_handler_declaration(&self) -> bool {
694        self.as_handler_declaration().is_some()
695    }
696
697    pub fn as_handler_declaration(&self) -> Option<&HandlerDeclaration> {
698        match self {
699            Node::HandlerDeclaration(c) => Some(c),
700            _ => None,
701        }
702    }
703
704    pub fn is_identifier_path(&self) -> bool {
705        self.as_identifier_path().is_some()
706    }
707
708    pub fn as_identifier_path(&self) -> Option<&IdentifierPath> {
709        match self {
710            Node::IdentifierPath(c) => Some(c),
711            _ => None,
712        }
713    }
714
715    pub fn is_import(&self) -> bool {
716        self.as_import().is_some()
717    }
718
719    pub fn as_import(&self) -> Option<&Import> {
720        match self {
721            Node::Import(c) => Some(c),
722            _ => None,
723        }
724    }
725
726    pub fn is_interface_declaration(&self) -> bool {
727        self.as_interface_declaration().is_some()
728    }
729
730    pub fn as_interface_declaration(&self) -> Option<&InterfaceDeclaration> {
731        match self {
732            Node::InterfaceDeclaration(c) => Some(c),
733            _ => None,
734        }
735    }
736
737    pub fn is_middleware_declaration(&self) -> bool {
738        self.as_middleware_declaration().is_some()
739    }
740
741    pub fn as_middleware_declaration(&self) -> Option<&MiddlewareDeclaration> {
742        match self {
743            Node::MiddlewareDeclaration(c) => Some(c),
744            _ => None,
745        }
746    }
747
748    pub fn is_model(&self) -> bool {
749        self.as_model().is_some()
750    }
751
752    pub fn as_model(&self) -> Option<&Model> {
753        match self {
754            Node::Model(c) => Some(c),
755            _ => None,
756        }
757    }
758
759    pub fn is_namespace(&self) -> bool {
760        self.as_namespace().is_some()
761    }
762
763    pub fn as_namespace(&self) -> Option<&Namespace> {
764        match self {
765            Node::Namespace(c) => Some(c),
766            _ => None,
767        }
768    }
769
770    pub fn is_pipeline_item_declaration(&self) -> bool {
771        self.as_pipeline_item_declaration().is_some()
772    }
773
774    pub fn as_pipeline_item_declaration(&self) -> Option<&PipelineItemDeclaration> {
775        match self {
776            Node::PipelineItemDeclaration(c) => Some(c),
777            _ => None,
778        }
779    }
780
781    pub fn is_pipeline_item_declaration_variant(&self) -> bool {
782        self.as_pipeline_item_declaration_variant().is_some()
783    }
784
785    pub fn as_pipeline_item_declaration_variant(&self) -> Option<&PipelineItemDeclarationVariant> {
786        match self {
787            Node::PipelineItemDeclarationVariant(c) => Some(c),
788            _ => None,
789        }
790    }
791
792    pub fn is_struct_declaration(&self) -> bool {
793        self.as_struct_declaration().is_some()
794    }
795
796    pub fn as_struct_declaration(&self) -> Option<&StructDeclaration> {
797        match self {
798            Node::StructDeclaration(c) => Some(c),
799            _ => None,
800        }
801    }
802
803    pub fn is_type_expr(&self) -> bool {
804        self.as_type_expr().is_some()
805    }
806
807    pub fn as_type_expr(&self) -> Option<&TypeExpr> {
808        match self {
809            Node::TypeExpr(c) => Some(c),
810            _ => None,
811        }
812    }
813
814    pub fn is_type_binary_operation(&self) -> bool {
815        self.as_type_binary_operation().is_some()
816    }
817
818    pub fn as_type_binary_operation(&self) -> Option<&TypeBinaryOperation> {
819        match self {
820            Node::TypeBinaryOperation(c) => Some(c),
821            _ => None,
822        }
823    }
824
825    pub fn is_type_group(&self) -> bool {
826        self.as_type_group().is_some()
827    }
828
829    pub fn as_type_group(&self) -> Option<&TypeGroup> {
830        match self {
831            Node::TypeGroup(c) => Some(c),
832            _ => None,
833        }
834    }
835
836    pub fn is_type_tuple(&self) -> bool {
837        self.as_type_tuple().is_some()
838    }
839
840    pub fn as_type_tuple(&self) -> Option<&TypeTuple> {
841        match self {
842            Node::TypeTuple(c) => Some(c),
843            _ => None,
844        }
845    }
846
847    pub fn is_type_subscript(&self) -> bool {
848        self.as_type_subscript().is_some()
849    }
850
851    pub fn as_type_subscript(&self) -> Option<&TypeSubscript> {
852        match self {
853            Node::TypeSubscript(c) => Some(c),
854            _ => None,
855        }
856    }
857
858    pub fn is_type_item(&self) -> bool {
859        self.as_type_item().is_some()
860    }
861
862    pub fn as_type_item(&self) -> Option<&TypeItem> {
863        match self {
864            Node::TypeItem(c) => Some(c),
865            _ => None,
866        }
867    }
868
869    pub fn is_type_generics(&self) -> bool {
870        self.as_type_generics().is_some()
871    }
872
873    pub fn as_type_generics(&self) -> Option<&TypeGenerics> {
874        match self {
875            Node::TypeGenerics(c) => Some(c),
876            _ => None,
877        }
878    }
879
880    pub fn is_use_middlewares_block(&self) -> bool {
881        self.as_use_middlewares_block().is_some()
882    }
883
884    pub fn as_use_middlewares_block(&self) -> Option<&UseMiddlewaresBlock> {
885        match self {
886            Node::UseMiddlewaresBlock(c) => Some(c),
887           _ => None,
888        }
889    }
890
891    pub fn is_punctuation(&self) -> bool {
892        self.as_punctuation().is_some()
893    }
894
895    pub fn as_punctuation(&self) -> Option<&Punctuation> {
896        match self {
897            Node::Punctuation(c) => Some(c),
898            _ => None,
899        }
900    }
901
902    pub fn is_operator(&self) -> bool {
903        self.as_operator().is_some()
904    }
905
906    pub fn as_operator(&self) -> Option<&Operator> {
907        match self {
908            Node::Operator(c) => Some(c),
909            _ => None,
910        }
911    }
912
913    pub fn is_empty_dot(&self) -> bool {
914        self.as_empty_dot().is_some()
915    }
916
917    pub fn as_empty_dot(&self) -> Option<&EmptyDot> {
918        match self {
919            Node::EmptyDot(c) => Some(c),
920            _ => None,
921        }
922    }
923
924    pub fn is_partial_field(&self) -> bool {
925        self.as_partial_field().is_some()
926    }
927
928    pub fn as_partial_field(&self) -> Option<&PartialField> {
929        match self {
930            Node::PartialField(c) => Some(c),
931            _ => None,
932        }
933    }
934
935    pub fn is_partial_argument_declaration(&self) -> bool {
936        self.as_partial_argument_declaration().is_some()
937    }
938
939    pub fn as_partial_argument_declaration(&self) -> Option<&PartialArgumentDeclaration> {
940        match self {
941            Node::PartialArgumentDeclaration(c) => Some(c),
942            _ => None,
943        }
944    }
945
946    pub fn is_partial_argument(&self) -> bool {
947        self.as_partial_argument().is_some()
948    }
949
950    pub fn as_partial_argument(&self) -> Option<&PartialArgument> {
951        match self {
952            Node::PartialArgument(c) => Some(c),
953            _ => None,
954        }
955    }
956
957    pub fn is_empty_decorator(&self) -> bool {
958        self.as_empty_decorator().is_some()
959    }
960
961    pub fn as_empty_decorator(&self) -> Option<&EmptyDecorator> {
962        match self {
963            Node::EmptyDecorator(c) => Some(c),
964            _ => None,
965        }
966    }
967
968    pub fn is_typed_enum(&self) -> bool {
969        self.as_typed_enum().is_some()
970    }
971
972    pub fn as_typed_enum(&self) -> Option<&TypedEnum> {
973        match self {
974            Node::TypedEnum(c) => Some(c),
975            _ => None,
976        }
977    }
978
979    pub fn is_typed_shape(&self) -> bool {
980        self.as_typed_shape().is_some()
981    }
982
983    pub fn as_typed_shape(&self) -> Option<&TypedShape> {
984        match self {
985            Node::TypedShape(c) => Some(c),
986            _ => None,
987        }
988    }
989
990    pub fn is_typed_shape_item(&self) -> bool {
991        self.as_typed_shape_item().is_some()
992    }
993
994    pub fn as_typed_shape_item(&self) -> Option<&TypedShapeItem> {
995        match self {
996            Node::TypedShapeItem(c) => Some(c),
997            _ => None,
998        }
999    }
1000
1001    pub fn is_synthesized_shape_declaration(&self) -> bool {
1002        self.as_synthesized_shape_declaration().is_some()
1003    }
1004
1005    pub fn as_synthesized_shape_declaration(&self) -> Option<&SynthesizedShapeDeclaration> {
1006        match self {
1007            Node::SynthesizedShapeDeclaration(c) => Some(c),
1008            _ => None,
1009        }
1010    }
1011
1012    pub fn is_synthesized_shape_field_declaration(&self) -> bool {
1013        self.as_synthesized_shape_field_declaration().is_some()
1014    }
1015
1016    pub fn as_synthesized_shape_field_declaration(&self) -> Option<&SynthesizedShapeFieldDeclaration> {
1017        match self {
1018            Node::SynthesizedShapeFieldDeclaration(c) => Some(c),
1019            _ => None,
1020        }
1021    }
1022
1023    pub fn is_handler_template_declaration(&self) -> bool {
1024        self.as_handler_template_declaration().is_some()
1025    }
1026
1027    pub fn as_handler_template_declaration(&self) -> Option<&HandlerTemplateDeclaration> {
1028        match self {
1029            Node::HandlerTemplateDeclaration(c) => Some(c),
1030            _ => None,
1031        }
1032    }
1033
1034    pub fn is_include_handler_from_template(&self) -> bool {
1035        self.as_include_handler_from_template().is_some()
1036    }
1037
1038    pub fn as_include_handler_from_template(&self) -> Option<&IncludeHandlerFromTemplate> {
1039        match self {
1040            Node::IncludeHandlerFromTemplate(c) => Some(c),
1041            _ => None,
1042        }
1043    }
1044
1045    pub fn is_type_as_value_expression(&self) -> bool {
1046        self.as_type_as_value_expression().is_some()
1047    }
1048
1049    pub fn as_type_as_value_expression(&self) -> Option<&TypeAsValueExpression> {
1050        match self {
1051            Node::TypeAsValueExpression(c) => Some(c),
1052            _ => None,
1053        }
1054    }
1055
1056    pub fn as_dyn_node_trait(&self) -> &dyn NodeTrait {
1057        match self {
1058            Node::Argument(n) => n,
1059            Node::ArgumentList(n) => n,
1060            Node::ArgumentListDeclaration(n) => n,
1061            Node::ArgumentDeclaration(n) => n,
1062            Node::ArithExpr(n) => n,
1063            Node::UnaryOperation(n) => n,
1064            Node::UnaryPostfixOperation(n) => n,
1065            Node::BinaryOperation(n) => n,
1066            Node::AvailabilityFlag(n) => n,
1067            Node::AvailabilityFlagEnd(n) => n,
1068            Node::CodeComment(n) => n,
1069            Node::DocComment(n) => n,
1070            Node::Config(n) => n,
1071            Node::Keyword(n) => n,
1072            Node::ConfigDeclaration(n) => n,
1073            Node::ConstantDeclaration(n) => n,
1074            Node::DataSet(n) => n,
1075            Node::DataSetGroup(n) => n,
1076            Node::DataSetRecord(n) => n,
1077            Node::Decorator(n) => n,
1078            Node::DecoratorDeclaration(n) => n,
1079            Node::DecoratorDeclarationVariant(n) => n,
1080            Node::Enum(n) => n,
1081            Node::EnumMember(n) => n,
1082            Node::Expression(n) => n,
1083            Node::NamedExpression(n) => n,
1084            Node::BracketExpression(n) => n,
1085            Node::Group(n) => n,
1086            Node::NumericLiteral(n) => n,
1087            Node::StringLiteral(n) => n,
1088            Node::RegexLiteral(n) => n,
1089            Node::BoolLiteral(n) => n,
1090            Node::NullLiteral(n) => n,
1091            Node::EnumVariantLiteral(n) => n,
1092            Node::TupleLiteral(n) => n,
1093            Node::ArrayLiteral(n) => n,
1094            Node::DictionaryLiteral(n) => n,
1095            Node::Identifier(n) => n,
1096            Node::Subscript(n) => n,
1097            Node::IntSubscript(n) => n,
1098            Node::Unit(n) => n,
1099            Node::Pipeline(n) => n,
1100            Node::EmptyPipeline(n) => n,
1101            Node::Field(n) => n,
1102            Node::FunctionDeclaration(n) => n,
1103            Node::GenericsDeclaration(n) => n,
1104            Node::GenericsConstraint(n) => n,
1105            Node::GenericsConstraintItem(n) => n,
1106            Node::HandlerGroupDeclaration(n) => n,
1107            Node::HandlerDeclaration(n) => n,
1108            Node::IdentifierPath(n) => n,
1109            Node::Import(n) => n,
1110            Node::InterfaceDeclaration(n) => n,
1111            Node::MiddlewareDeclaration(n) => n,
1112            Node::Model(n) => n,
1113            Node::Namespace(n) => n,
1114            Node::PipelineItemDeclaration(n) => n,
1115            Node::PipelineItemDeclarationVariant(n) => n,
1116            Node::StructDeclaration(n) => n,
1117            Node::TypeExpr(n) => n,
1118            Node::TypeBinaryOperation(n) => n,
1119            Node::TypeGroup(n) => n,
1120            Node::TypeTuple(n) => n,
1121            Node::TypeSubscript(n) => n,
1122            Node::TypeItem(n) => n,
1123            Node::TypeGenerics(n) => n,
1124            Node::UseMiddlewaresBlock(n) => n,
1125            Node::Punctuation(n) => n,
1126            Node::Operator(n) => n,
1127            Node::EmptyDot(n) => n,
1128            Node::PartialField(n) => n,
1129            Node::PartialArgumentDeclaration(n) => n,
1130            Node::PartialArgument(n) => n,
1131            Node::EmptyDecorator(n) => n,
1132            Node::TypedEnum(n) => n,
1133            Node::TypedShape(n) => n,
1134            Node::TypedShapeItem(n) => n,
1135            Node::SynthesizedShapeDeclaration(n) => n,
1136            Node::SynthesizedShapeFieldDeclaration(n) => n,
1137            Node::HandlerTemplateDeclaration(n) => n,
1138            Node::IncludeHandlerFromTemplate(n) => n,
1139            Node::TypeAsValueExpression(n) => n,
1140        }
1141    }
1142
1143    pub fn identifier_span(&self) -> Option<Span> {
1144        match self {
1145            Node::ConstantDeclaration(c) => Some(c.identifier().span()),
1146            Node::Enum(e) => Some(e.identifier().span()),
1147            Node::Model(m) => Some(m.identifier().span()),
1148            Node::Config(c) => Some(c.identifier().as_ref().map_or(c.keyword().span(), |i| i.span())),
1149            Node::ConfigDeclaration(c) => Some(c.identifier().span()),
1150            Node::DataSet(d) => Some(d.identifier().span()),
1151            Node::MiddlewareDeclaration(m) => Some(m.identifier().span()),
1152            Node::HandlerGroupDeclaration(a) => Some(a.identifier().span()),
1153            Node::InterfaceDeclaration(i) => Some(i.identifier().span()),
1154            Node::Namespace(n) => Some(n.identifier().span()),
1155            Node::DecoratorDeclaration(d) => Some(d.identifier().span()),
1156            Node::PipelineItemDeclaration(p) => Some(p.identifier().span()),
1157            Node::StructDeclaration(s) => Some(s.identifier().span()),
1158            Node::SynthesizedShapeDeclaration(s) => Some(s.identifier().span()),
1159            _ => None,
1160        }
1161    }
1162
1163    pub fn available_test(&self, availability: Availability) -> bool {
1164        match self {
1165            Node::ConstantDeclaration(t) => t.define_availability().contains(availability),
1166            Node::Enum(t) => t.define_availability().contains(availability),
1167            Node::Model(t) => t.define_availability().contains(availability),
1168            Node::DataSet(t) => t.define_availability().contains(availability),
1169            Node::InterfaceDeclaration(t) => t.define_availability().contains(availability),
1170            Node::DecoratorDeclaration(t) => t.define_availability().contains(availability),
1171            Node::PipelineItemDeclaration(t) => t.define_availability().contains(availability),
1172            Node::StructDeclaration(t) => t.define_availability().contains(availability),
1173            Node::SynthesizedShapeDeclaration(s) => s.define_availability().contains(availability),
1174            _ => true,
1175        }
1176    }
1177
1178    pub fn string_path(&self) -> Option<&Vec<String>> {
1179        match self {
1180            Node::ConstantDeclaration(c) => Some(c.string_path()),
1181            Node::Enum(e) => Some(e.string_path()),
1182            Node::Model(m) => Some(m.string_path()),
1183            Node::Config(c) => Some(c.string_path()),
1184            Node::ConfigDeclaration(c) => Some(c.string_path()),
1185            Node::DataSet(d) => Some(d.string_path()),
1186            Node::MiddlewareDeclaration(m) => Some(m.string_path()),
1187            Node::HandlerGroupDeclaration(h) => Some(h.string_path()),
1188            Node::InterfaceDeclaration(i) => Some(i.string_path()),
1189            Node::Namespace(n) => Some(n.string_path()),
1190            Node::DecoratorDeclaration(d) => Some(d.string_path()),
1191            Node::PipelineItemDeclaration(p) => Some(p.string_path()),
1192            Node::StructDeclaration(s) => Some(s.string_path()),
1193            Node::SynthesizedShapeDeclaration(s) => Some(s.string_path()),
1194            _ => None,
1195        }
1196    }
1197
1198    pub fn str_path(&self) -> Option<Vec<&str>> {
1199        match self {
1200            Node::ConstantDeclaration(c) => Some(c.str_path()),
1201            Node::Enum(e) => Some(e.str_path()),
1202            Node::Model(m) => Some(m.str_path()),
1203            Node::Config(c) => Some(c.str_path()),
1204            Node::ConfigDeclaration(c) => Some(c.str_path()),
1205            Node::DataSet(d) => Some(d.str_path()),
1206            Node::MiddlewareDeclaration(m) => Some(m.str_path()),
1207            Node::HandlerGroupDeclaration(h) => Some(h.str_path()),
1208            Node::InterfaceDeclaration(i) => Some(i.str_path()),
1209            Node::Namespace(n) => Some(n.str_path()),
1210            Node::DecoratorDeclaration(d) => Some(d.str_path()),
1211            Node::PipelineItemDeclaration(p) => Some(p.str_path()),
1212            Node::StructDeclaration(s) => Some(s.str_path()),
1213            Node::SynthesizedShapeDeclaration(s) => Some(s.str_path()),
1214            _ => None,
1215        }
1216    }
1217
1218    pub fn name(&self) -> Option<&str> {
1219        match self {
1220            Node::ConstantDeclaration(c) => Some(c.identifier().name()),
1221            Node::Enum(e) => Some(e.identifier().name()),
1222            Node::Model(m) => Some(m.identifier().name()),
1223            Node::Config(c) => Some(c.name()),
1224            Node::ConfigDeclaration(c) => Some(c.identifier().name()),
1225            Node::DataSet(d) => Some(d.identifier().name()),
1226            Node::MiddlewareDeclaration(m) => Some(m.identifier().name()),
1227            Node::HandlerGroupDeclaration(a) => Some(a.identifier().name()),
1228            Node::InterfaceDeclaration(i) => Some(i.identifier().name()),
1229            Node::Namespace(n) => Some(n.identifier().name()),
1230            Node::DecoratorDeclaration(d) => Some(d.identifier().name()),
1231            Node::PipelineItemDeclaration(p) => Some(p.identifier().name()),
1232            Node::StructDeclaration(s) => Some(s.identifier().name()),
1233            Node::SynthesizedShapeDeclaration(s) => Some(s.identifier().name()),
1234            Node::HandlerDeclaration(h) => Some(h.identifier().name()),
1235            Node::HandlerTemplateDeclaration(h) => Some(h.identifier().name()),
1236            _ => None,
1237        }
1238    }
1239}
1240
1241impl Display for Node {
1242
1243    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
1244        Display::fmt(self.as_dyn_node_trait(), f)
1245    }
1246}
1247
1248impl Identifiable for Node {
1249    fn path(&self) -> &Vec<usize> {
1250        self.as_dyn_node_trait().path()
1251    }
1252
1253    fn source_id(&self) -> usize {
1254        self.as_dyn_node_trait().source_id()
1255    }
1256
1257    fn id(&self) -> usize {
1258        self.as_dyn_node_trait().id()
1259    }
1260}
1261
1262impl NodeTrait for Node {
1263    fn span(&self) -> Span {
1264        self.as_dyn_node_trait().span()
1265    }
1266
1267    fn children(&self) -> Option<&BTreeMap<usize, Node>> {
1268        self.as_dyn_node_trait().children()
1269    }
1270
1271    fn has_children(&self) -> bool {
1272        self.as_dyn_node_trait().has_children()
1273    }
1274
1275    fn child(&self, id: usize) -> Option<&Node> {
1276        self.as_dyn_node_trait().child(id)
1277    }
1278}
1279
1280impl Write for Node {
1281    fn write<'a>(&'a self, writer: &mut Writer<'a>) {
1282        self.as_dyn_node_trait().write(writer)
1283    }
1284
1285    fn write_output_with_default_writer(&self) -> String {
1286        self.as_dyn_node_trait().write_output_with_default_writer()
1287    }
1288
1289    fn prefer_whitespace_before(&self) -> bool {
1290        self.as_dyn_node_trait().prefer_whitespace_before()
1291    }
1292
1293    fn prefer_whitespace_after(&self) -> bool {
1294        self.as_dyn_node_trait().prefer_whitespace_after()
1295    }
1296
1297    fn prefer_always_no_whitespace_before(&self) -> bool {
1298        self.as_dyn_node_trait().prefer_always_no_whitespace_before()
1299    }
1300
1301    fn always_start_on_new_line(&self) -> bool {
1302        self.as_dyn_node_trait().always_start_on_new_line()
1303    }
1304
1305    fn always_end_on_new_line(&self) -> bool {
1306        self.as_dyn_node_trait().always_end_on_new_line()
1307    }
1308
1309    fn is_block_start(&self) -> bool {
1310        self.as_dyn_node_trait().is_block_start()
1311    }
1312
1313    fn is_block_end(&self) -> bool {
1314        self.as_dyn_node_trait().is_block_end()
1315    }
1316
1317    fn is_block_element_delimiter(&self) -> bool {
1318        self.as_dyn_node_trait().is_block_element_delimiter()
1319    }
1320
1321    fn is_block_level_element(&self) -> bool {
1322        self.as_dyn_node_trait().is_block_level_element()
1323    }
1324
1325    fn wrap(&self, content: &str, available_length: usize) -> String {
1326        self.as_dyn_node_trait().wrap(content, available_length)
1327    }
1328}
1329
1330unsafe impl Send for Node { }
1331unsafe impl Sync for Node { }