forked from freeorion/freeorion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEffectParser2.cpp
234 lines (213 loc) · 9.08 KB
/
EffectParser2.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
#include "EffectParser2.h"
#include "ValueRefParser.h"
#include "../Empire/ResourcePool.h"
#include "../universe/Condition.h"
#include "../universe/Effects.h"
#include "../universe/Enums.h"
#include "../universe/ValueRef.h"
#include <boost/phoenix.hpp>
namespace qi = boost::spirit::qi;
namespace phoenix = boost::phoenix;
namespace parse { namespace detail {
effect_parser_rules_2::effect_parser_rules_2(
const parse::lexer& tok, Labeller& label,
const condition_parser_grammar& condition_parser,
const value_ref_grammar<std::string>& string_grammar
) :
effect_parser_rules_2::base_type(start, "effect_parser_rules_2"),
int_rules(tok, label, condition_parser, string_grammar),
double_rules(tok, label, condition_parser, string_grammar),
visibility_rules(tok, label, condition_parser),
planet_type_rules(tok, label, condition_parser),
planet_size_rules(tok, label, condition_parser),
empire_affiliation_type_enum(tok),
set_non_ship_part_meter_type_enum(tok),
set_ship_part_meter_type_enum(tok),
resource_type_enum(tok)
{
qi::_1_type _1;
qi::_2_type _2;
qi::_3_type _3;
qi::_a_type _a;
qi::_b_type _b;
qi::_c_type _c;
qi::_d_type _d;
qi::_e_type _e;
qi::_val_type _val;
qi::eps_type eps;
qi::_pass_type _pass;
using phoenix::new_;
using phoenix::construct;
const boost::phoenix::function<construct_movable> construct_movable_;
const boost::phoenix::function<deconstruct_movable> deconstruct_movable_;
set_meter =
((
/* has some overlap with set_ship_part_meter_type_enum so can't use '>' */
set_non_ship_part_meter_type_enum [ _a = _1 ]
>> label(tok.value_)
)
> double_rules.expr [ _b = _1 ]
> -(label(tok.accountinglabel_) > tok.string) [ _c = _1]
) [ _val = construct_movable_(new_<Effect::SetMeter>(
_a,
deconstruct_movable_(_b, _pass),
_c)) ]
;
set_ship_part_meter
= (( set_ship_part_meter_type_enum
>> label(tok.partname_)) > string_grammar
> label(tok.value_) > double_rules.expr
) [ _val = construct_movable_(new_<Effect::SetShipPartMeter>(
_1,
deconstruct_movable_(_2, _pass),
deconstruct_movable_(_3, _pass))) ]
;
set_empire_stockpile
= tok.SetEmpireStockpile_
> label(tok.resource_) > resource_type_enum [ _a = _1 ]
> (
( label(tok.empire_) > int_rules.expr [ _b = _1 ]
> label(tok.value_) > double_rules.expr [ _val = construct_movable_(new_<Effect::SetEmpireStockpile>(
deconstruct_movable_(_b, _pass),
_a,
deconstruct_movable_(_1, _pass))) ]
)
| (label(tok.value_) > double_rules.expr [ _val = construct_movable_(new_<Effect::SetEmpireStockpile>(
_a,
deconstruct_movable_(_1, _pass))) ]
)
)
;
set_empire_capital
= tok.SetEmpireCapital_
> (
(label(tok.empire_) > int_rules.expr [ _val = construct_movable_(
new_<Effect::SetEmpireCapital>(deconstruct_movable_(_1, _pass))) ])
| eps [ _val = construct_movable_(new_<Effect::SetEmpireCapital>()) ]
)
;
set_planet_type
= tok.SetPlanetType_
> label(tok.type_) > planet_type_rules.expr [ _val = construct_movable_(
new_<Effect::SetPlanetType>(deconstruct_movable_(_1, _pass))) ]
;
set_original_type
= tok.SetOriginalType_
> label(tok.type_) > planet_type_rules.expr [ _val = construct_movable_(
new_<Effect::SetOriginalType>(deconstruct_movable_(_1, _pass))) ]
;
set_planet_size
= tok.SetPlanetSize_
> label(tok.planetsize_) > planet_size_rules.expr [
_val = construct_movable_(new_<Effect::SetPlanetSize>(deconstruct_movable_(_1, _pass))) ]
;
set_focus
= tok.SetFocus_
> label(tok.name_) > string_grammar [
_val = construct_movable_(new_<Effect::SetFocus>(deconstruct_movable_(_1, _pass))) ]
;
set_species
= tok.SetSpecies_
> label(tok.name_) > string_grammar [
_val = construct_movable_(new_<Effect::SetSpecies>(deconstruct_movable_(_1, _pass))) ]
;
set_owner
= tok.SetOwner_
> label(tok.empire_) > int_rules.expr [
_val = construct_movable_(new_<Effect::SetOwner>(deconstruct_movable_(_1, _pass))) ]
;
set_species_opinion
= (
(tok.SetSpeciesOpinion_ [ _d = false ]) |
(tok.SetSpeciesTargetOpinion_ [ _d = true ])
)
> label(tok.species_) > string_grammar [ _a = _1 ]
> (
( label(tok.empire_) > int_rules.expr [ _c = _1 ]
> label(tok.opinion_) > double_rules.expr
[ _val = construct_movable_(new_<Effect::SetSpeciesEmpireOpinion>(
deconstruct_movable_(_a, _pass),
deconstruct_movable_(_c, _pass),
deconstruct_movable_(_1, _pass),
_d)) ])
|
( label(tok.species_) > string_grammar [ _b = _1 ]
> label(tok.opinion_) > double_rules.expr
[ _val = construct_movable_(new_<Effect::SetSpeciesSpeciesOpinion>(
deconstruct_movable_(_a, _pass),
deconstruct_movable_(_b, _pass),
deconstruct_movable_(_1, _pass),
_d)) ])
)
;
set_visibility
= tok.SetVisibility_
> (
(
( // empire id specified, optionally with an affiliation type:
// useful to specify a single recipient empire, or the allies
// or enemies of a single empire
(
( (label(tok.affiliation_) > empire_affiliation_type_enum [ _d = _1 ])
| eps [ _d = EmpireAffiliationType::AFFIL_SELF ]
)
>> label(tok.empire_)
) > int_rules.expr [ _b = _1 ]
)
| ( // no empire id or condition specified, with or without an
// affiliation type: useful to specify no or all empires
( (label(tok.affiliation_) > empire_affiliation_type_enum [ _d = _1 ])
| eps [ _d = EmpireAffiliationType::AFFIL_ANY ]
)
)
)
> label(tok.visibility_) > visibility_rules.expr [ _c = _1 ]
>-(label(tok.condition_) > condition_parser [ _e = _1 ])
) [ _val = construct_movable_(
new_<Effect::SetVisibility>(deconstruct_movable_(_c, _pass),
_d,
deconstruct_movable_(_b, _pass),
deconstruct_movable_(_e, _pass))) ]
;
start
%= set_ship_part_meter
| set_meter
| set_empire_stockpile
| set_empire_capital
| set_planet_type
| set_original_type
| set_planet_size
| set_focus
| set_species
| set_species_opinion
| set_owner
| set_visibility
;
set_meter.name("SetMeter");
set_ship_part_meter.name("SetShipPartMeter");
set_empire_stockpile.name("SetEmpireStockpile");
set_empire_capital.name("SetEmpireCapital");
set_planet_type.name("SetPlanetType");
set_original_type.name("SetOriginalType");
set_planet_size.name("SetPlanetSize");
set_focus.name("SetFocus");
set_species.name("SetSpecies");
set_species_opinion.name("SetSpeciesOpinion");
set_owner.name("SetOwner");
set_visibility.name("SetVisibility");
#if DEBUG_EFFECT_PARSERS
debug(set_meter);
debug(set_ship_part_meter);
debug(set_empire_stockpile);
debug(set_empire_capital);
debug(set_planet_type);
debug(set_original_type);
debug(set_planet_size);
debug(set_focus);
debug(set_species);
debug(set_species_opinion);
debug(set_owner);
debug(set_visibility);
#endif
}
} }