mxmlextrema_as3parser/tree/
directive.rs1use crate::ns::*;
2use serde::{Serialize, Deserialize};
3
4#[derive(Debug, Clone, Serialize, Deserialize)]
6pub enum Directive {
7 EmptyStatement(EmptyStatement),
8 ExpressionStatement(ExpressionStatement),
9 SuperStatement(SuperStatement),
10 Block(Block),
11 LabeledStatement(LabeledStatement),
12 IfStatement(IfStatement),
13 SwitchStatement(SwitchStatement),
14 SwitchTypeStatement(SwitchTypeStatement),
15 DoStatement(DoStatement),
16 WhileStatement(WhileStatement),
17 ForStatement(ForStatement),
18 ForInStatement(ForInStatement),
19 BreakStatement(BreakStatement),
20 ContinueStatement(ContinueStatement),
21 WithStatement(WithStatement),
22 ReturnStatement(ReturnStatement),
23 ThrowStatement(ThrowStatement),
24 DefaultXmlNamespaceStatement(DefaultXmlNamespaceStatement),
25 TryStatement(TryStatement),
26 Invalidated(InvalidatedNode),
27 ConfigurationDirective(ConfigurationDirective),
28 ImportDirective(ImportDirective),
29 UseNamespaceDirective(UseNamespaceDirective),
30 IncludeDirective(IncludeDirective),
31 PackageConcatDirective(PackageConcatDirective),
32 DirectiveInjection(DirectiveInjectionNode),
33 VariableDefinition(VariableDefinition),
34 FunctionDefinition(FunctionDefinition),
35 ClassDefinition(ClassDefinition),
36 EnumDefinition(EnumDefinition),
37 InterfaceDefinition(InterfaceDefinition),
38 TypeDefinition(TypeDefinition),
39 NamespaceDefinition(NamespaceDefinition),
40}
41
42impl Directive {
43 pub fn location(&self) -> Location {
44 match self {
45 Self::EmptyStatement(d) => d.location.clone(),
46 Self::ExpressionStatement(d) => d.location.clone(),
47 Self::SuperStatement(d) => d.location.clone(),
48 Self::Block(d) => d.location.clone(),
49 Self::LabeledStatement(d) => d.location.clone(),
50 Self::IfStatement(d) => d.location.clone(),
51 Self::SwitchStatement(d) => d.location.clone(),
52 Self::SwitchTypeStatement(d) => d.location.clone(),
53 Self::DoStatement(d) => d.location.clone(),
54 Self::WhileStatement(d) => d.location.clone(),
55 Self::ForStatement(d) => d.location.clone(),
56 Self::ForInStatement(d) => d.location.clone(),
57 Self::BreakStatement(d) => d.location.clone(),
58 Self::ContinueStatement(d) => d.location.clone(),
59 Self::WithStatement(d) => d.location.clone(),
60 Self::ReturnStatement(d) => d.location.clone(),
61 Self::ThrowStatement(d) => d.location.clone(),
62 Self::DefaultXmlNamespaceStatement(d) => d.location.clone(),
63 Self::TryStatement(d) => d.location.clone(),
64 Self::Invalidated(d) => d.location.clone(),
65 Self::ConfigurationDirective(d) => d.location.clone(),
66 Self::ImportDirective(d) => d.location.clone(),
67 Self::UseNamespaceDirective(d) => d.location.clone(),
68 Self::IncludeDirective(d) => d.location.clone(),
69 Self::PackageConcatDirective(d) => d.location.clone(),
70 Self::DirectiveInjection(d) => d.location.clone(),
71 Self::VariableDefinition(d) => d.location.clone(),
72 Self::FunctionDefinition(d) => d.location.clone(),
73 Self::ClassDefinition(d) => d.location.clone(),
74 Self::EnumDefinition(d) => d.location.clone(),
75 Self::InterfaceDefinition(d) => d.location.clone(),
76 Self::TypeDefinition(d) => d.location.clone(),
77 Self::NamespaceDefinition(d) => d.location.clone(),
78 }
79 }
80
81 #[inline(always)]
82 pub fn is_statement(&self) -> bool {
83 !self.is_directive()
84 }
85
86 pub fn is_directive(&self) -> bool {
87 matches!(
88 self,
89 Self::ConfigurationDirective(_) |
90 Self::ImportDirective(_) |
91 Self::UseNamespaceDirective(_) |
92 Self::IncludeDirective(_) |
93 Self::PackageConcatDirective(_) |
94 Self::VariableDefinition(_) |
95 Self::FunctionDefinition(_) |
96 Self::ClassDefinition(_) |
97 Self::EnumDefinition(_) |
98 Self::InterfaceDefinition(_) |
99 Self::TypeDefinition(_) |
100 Self::NamespaceDefinition(_)
101 )
102 }
103}