1use crate::puppet_lang::{expression::Expression, identifier::LowerIdentifier};
2use serde::Serialize;
3
4#[derive(Clone, Debug, PartialEq, Serialize)]
5pub enum ResourceAttributeVariant<EXTRA> {
6 Name(
7 (
8 crate::puppet_lang::string::Literal<EXTRA>,
9 Expression<EXTRA>,
10 ),
11 ),
12 Group(crate::puppet_lang::expression::Term<EXTRA>),
13}
14
15#[derive(Clone, Debug, PartialEq, Serialize)]
16pub struct ResourceAttribute<EXTRA> {
17 pub value: ResourceAttributeVariant<EXTRA>,
18 pub comment: Vec<crate::puppet_lang::comment::Comment<EXTRA>>,
19}
20
21#[derive(Clone, Debug, PartialEq, Serialize)]
22pub struct Resource<EXTRA> {
23 pub title: Expression<EXTRA>,
24 pub attributes: crate::puppet_lang::List<EXTRA, ResourceAttribute<EXTRA>>,
25 pub extra: EXTRA,
26}
27
28#[derive(Clone, Debug, PartialEq, Serialize)]
29pub struct ResourceSet<EXTRA> {
30 pub name: LowerIdentifier<EXTRA>,
31 pub list: crate::puppet_lang::List<EXTRA, Resource<EXTRA>>,
32 pub is_virtual: bool,
33 pub extra: EXTRA,
34 pub comment: Vec<crate::puppet_lang::comment::Comment<EXTRA>>,
35}
36
37#[derive(Clone, Debug, PartialEq, Serialize)]
38pub struct ConditionAndStatement<EXTRA> {
39 pub condition: Expression<EXTRA>,
40 pub comment_before_elsif_word: Vec<crate::puppet_lang::comment::Comment<EXTRA>>,
41 pub comment_before_body: Vec<crate::puppet_lang::comment::Comment<EXTRA>>,
42 pub body: Box<crate::puppet_lang::List<EXTRA, Statement<EXTRA>>>,
43 pub extra: EXTRA,
44}
45
46#[derive(Clone, Debug, PartialEq, Serialize)]
47pub struct IfElse<EXTRA> {
48 pub condition: ConditionAndStatement<EXTRA>,
49 pub elsif_list: Vec<ConditionAndStatement<EXTRA>>,
50 pub else_block: Option<Box<crate::puppet_lang::List<EXTRA, Statement<EXTRA>>>>,
51 pub comment_before_else_word: Vec<crate::puppet_lang::comment::Comment<EXTRA>>,
52 pub comment_before_else_body: Vec<crate::puppet_lang::comment::Comment<EXTRA>>,
53 pub extra: EXTRA,
54}
55
56#[derive(Clone, Debug, PartialEq, Serialize)]
57pub enum RelationVariant {
58 ExecOrderRight,
59 NotifyRight,
60 ExecOrderLeft,
61 NotifyLeft,
62}
63
64#[derive(Clone, Debug, PartialEq, Serialize)]
65pub struct RelationType<EXTRA> {
66 pub variant: RelationVariant,
67 pub extra: EXTRA,
68}
69
70#[derive(Clone, Debug, PartialEq, Serialize)]
71pub enum RelationEltVariant<EXTRA> {
72 ResourceSet(ResourceSet<EXTRA>),
73 ResourceCollection(crate::puppet_lang::resource_collection::ResourceCollection<EXTRA>),
74}
75
76impl<EXTRA> crate::puppet_lang::ExtraGetter<EXTRA> for RelationEltVariant<EXTRA> {
77 fn extra(&self) -> &EXTRA {
78 match &self {
79 RelationEltVariant::ResourceSet(v) => &v.extra,
80 RelationEltVariant::ResourceCollection(v) => &v.extra,
81 }
82 }
83}
84
85#[derive(Clone, Debug, PartialEq, Serialize)]
86pub struct RelationElt<EXTRA> {
87 pub data: crate::puppet_lang::List<EXTRA, RelationEltVariant<EXTRA>>,
88 pub extra: EXTRA,
89}
90
91#[derive(Clone, Debug, PartialEq, Serialize)]
92pub struct Relation<EXTRA> {
93 pub relation_type: RelationType<EXTRA>,
94 pub relation_to: Box<RelationList<EXTRA>>,
95 pub comment: Vec<crate::puppet_lang::comment::Comment<EXTRA>>,
96}
97
98#[derive(Clone, Debug, PartialEq, Serialize)]
99pub struct RelationList<EXTRA> {
100 pub head: RelationElt<EXTRA>,
101 pub tail: Option<Relation<EXTRA>>,
102 pub extra: EXTRA,
103}
104
105#[derive(Clone, Debug, PartialEq, Serialize)]
106pub struct CaseElement<EXTRA> {
107 pub matches: Vec<crate::puppet_lang::expression::CaseVariant<EXTRA>>,
108 pub body: Box<crate::puppet_lang::List<EXTRA, Statement<EXTRA>>>,
109 pub extra: EXTRA,
110 pub comment: Vec<crate::puppet_lang::comment::Comment<EXTRA>>,
111}
112
113#[derive(Clone, Debug, PartialEq, Serialize)]
114pub struct Case<EXTRA> {
115 pub condition: Expression<EXTRA>,
116 pub elements: crate::puppet_lang::List<EXTRA, CaseElement<EXTRA>>,
117 pub extra: EXTRA,
118}
119
120#[derive(Clone, Debug, PartialEq, Serialize)]
121pub struct ResourceDefaults<EXTRA> {
122 pub name: String,
123 pub args: crate::puppet_lang::List<
124 EXTRA,
125 (
126 crate::puppet_lang::expression::Term<EXTRA>,
127 Expression<EXTRA>,
128 ),
129 >,
130 pub extra: EXTRA,
131}
132
133#[derive(Clone, Debug, PartialEq, Serialize)]
134pub enum StatementVariant<EXTRA> {
135 Expression(crate::puppet_lang::expression::Expression<EXTRA>),
136 RelationList(RelationList<EXTRA>),
137 IfElse(IfElse<EXTRA>),
138 Unless(ConditionAndStatement<EXTRA>),
139 Case(Case<EXTRA>),
140 Toplevel(crate::puppet_lang::toplevel::Toplevel<EXTRA>),
141 ResourceDefaults(ResourceDefaults<EXTRA>),
142}
143
144#[derive(Clone, Debug, PartialEq, Serialize)]
145pub struct Statement<EXTRA> {
146 pub value: StatementVariant<EXTRA>,
147 pub comment: Vec<crate::puppet_lang::comment::Comment<EXTRA>>,
148}
149
150impl<EXTRA> crate::puppet_lang::ExtraGetter<EXTRA> for Statement<EXTRA> {
151 fn extra(&self) -> &EXTRA {
152 match &self.value {
153 StatementVariant::Expression(v) => &v.extra,
154 StatementVariant::RelationList(v) => &v.extra,
155 StatementVariant::IfElse(v) => &v.extra,
156 StatementVariant::Unless(v) => &v.extra,
157 StatementVariant::Case(v) => &v.extra,
158 StatementVariant::Toplevel(v) => &v.extra,
159 StatementVariant::ResourceDefaults(v) => &v.extra,
160 }
161 }
162}