forked from freeorion/freeorion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConditionParser5.cpp
183 lines (160 loc) · 6.52 KB
/
ConditionParser5.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
#include "ConditionParser5.h"
#include "../universe/Conditions.h"
#include "../universe/ValueRef.h"
#include <boost/phoenix.hpp>
namespace qi = boost::spirit::qi;
namespace phoenix = boost::phoenix;
#if DEBUG_CONDITION_PARSERS
namespace std {
inline ostream& operator<<(ostream& os, const std::vector<condition_payload>&) { return os; }
}
#endif
namespace parse { namespace detail {
condition_parser_rules_5::condition_parser_rules_5(
const parse::lexer& tok,
Labeller& label,
const condition_parser_grammar& condition_parser,
const value_ref_grammar<std::string>& string_grammar
) :
condition_parser_rules_5::base_type(start, "condition_parser_rules_5"),
int_rules(tok, label, condition_parser, string_grammar),
visibility_rules(tok, label, condition_parser)
{
qi::_1_type _1;
qi::_2_type _2;
qi::_3_type _3;
qi::_val_type _val;
qi::eps_type eps;
qi::_pass_type _pass;
qi::omit_type omit_;
const boost::phoenix::function<construct_movable> construct_movable_;
const boost::phoenix::function<deconstruct_movable> deconstruct_movable_;
using phoenix::new_;
using phoenix::construct;
has_special
= ( (tok.HasSpecial_
>> label(tok.name_)) > string_grammar
[ _val = construct_movable_(new_<Condition::HasSpecial>(deconstruct_movable_(_1, _pass))) ]
)
| tok.HasSpecial_ [ _val = construct_movable_(new_<Condition::HasSpecial>()) ]
;
has_tag
= (
(tok.HasTag_
>> label(tok.name_)) > string_grammar
[ _val = construct_movable_(new_<Condition::HasTag>(deconstruct_movable_(_1, _pass))) ]
)
| tok.HasTag_ [ _val = construct_movable_(new_<Condition::HasTag>()) ]
;
owner_has_tech
= tok.OwnerHasTech_
> label(tok.name_) > string_grammar
[ _val = construct_movable_(new_<Condition::OwnerHasTech>(deconstruct_movable_(_1, _pass))) ]
;
empire_adopted_policy1
= (
(omit_[tok.EmpireHasAdoptedPolicy_]
>> label(tok.empire_)) > int_rules.expr
> label(tok.name_) > string_grammar
) [ _val = construct_movable_(new_<Condition::EmpireHasAdoptedPolicy>(
deconstruct_movable_(_1, _pass),
deconstruct_movable_(_2, _pass))) ]
;
empire_adopted_policy2
= (
(omit_[tok.EmpireHasAdoptedPolicy_]
>> label(tok.name_)) > string_grammar
) [ _val = construct_movable_(new_<Condition::EmpireHasAdoptedPolicy>(deconstruct_movable_(_1, _pass))) ]
;
empire_adopted_policy
%= empire_adopted_policy1
| empire_adopted_policy2
;
design_has_hull
= tok.DesignHasHull_
> label(tok.name_) > string_grammar
[ _val = construct_movable_(new_<Condition::DesignHasHull>(deconstruct_movable_(_1, _pass))) ]
;
predefined_design
= (tok.Design_
>> label(tok.name_)) > string_grammar
[ _val = construct_movable_(new_<Condition::PredefinedShipDesign>(deconstruct_movable_(_1, _pass))) ]
;
design_number
= (tok.Design_
>> label(tok.design_)) > int_rules.expr
[ _val = construct_movable_(new_<Condition::NumberedShipDesign>(deconstruct_movable_(_1, _pass))) ]
;
produced_by_empire // TODO: Lose "empire" part.
= tok.ProducedByEmpire_
> label(tok.empire_) > int_rules.expr
[ _val = construct_movable_(new_<Condition::ProducedByEmpire>(deconstruct_movable_(_1, _pass))) ]
;
visible_to_empire // TODO: Lose "empire" part.
= (
omit_[tok.VisibleToEmpire_]
> label(tok.empire_) > int_rules.expr
> -(label(tok.turn_) > int_rules.expr)
> -(label(tok.visibility_) > visibility_rules.expr)
) [ _val = construct_movable_(new_<Condition::VisibleToEmpire>(
deconstruct_movable_(_1, _pass),
deconstruct_movable_(_2, _pass),
deconstruct_movable_(_3, _pass))) ]
;
explored_by_empire // TODO: Lose "empire" part.
= tok.ExploredByEmpire_
> label(tok.empire_) > int_rules.expr
[ _val = construct_movable_(new_<Condition::ExploredByEmpire>(deconstruct_movable_(_1, _pass))) ]
;
resupplyable_by
= tok.ResupplyableBy_
> label(tok.empire_) > int_rules.expr
[ _val = construct_movable_(new_<Condition::FleetSupplyableByEmpire>(deconstruct_movable_(_1, _pass))) ]
;
object_id
= tok.Object_
> label(tok.id_) > int_rules.expr
[ _val = construct_movable_(new_<Condition::ObjectID>(deconstruct_movable_(_1, _pass))) ]
;
start
%= has_special
| has_tag
| owner_has_tech
| empire_adopted_policy
| design_has_hull
| predefined_design
| design_number
| produced_by_empire
| visible_to_empire
| explored_by_empire
| resupplyable_by
| object_id
;
has_special.name("HasSpecial");
has_tag.name("HasTag");
owner_has_tech.name("OwnerHasTech");
empire_adopted_policy.name("EmpireHasAdoptedPolicy");
design_has_hull.name("DesignHasHull");
predefined_design.name("PredefinedDesign");
design_number.name("DesignNumber");
produced_by_empire.name("ProducedByEmpire");
visible_to_empire.name("VisibleToEmpire");
explored_by_empire.name("ExploredByEmpire");
resupplyable_by.name("ResupplyableBy");
object_id.name("ID");
#if DEBUG_CONDITION_PARSERS
debug(has_special);
debug(has_tag);
debug(owner_has_tech);
debug(empire_adopted_policy);
debug(design_has_hull);
debug(predefined_design);
debug(design_number);
debug(produced_by_empire);
debug(visible_to_empire);
debug(explored_by_empire);
debug(resupplyable_by);
debug(object_id);
#endif
}
} }