File: EffectParser4.cpp

package info (click to toggle)
freeorion 0.5.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 194,940 kB
  • sloc: cpp: 186,508; python: 40,969; ansic: 1,164; xml: 719; makefile: 32; sh: 7
file content (202 lines) | stat: -rw-r--r-- 8,263 bytes parent folder | download
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
#include "EffectParser4.h"

#include "ValueRefParser.h"
#include "EnumValueRefRules.h"
#include "../universe/Effects.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_4::effect_parser_rules_4(
        const parse::lexer& tok,
        const effect_parser_grammar& effect_parser,
        Labeller& label,
        const condition_parser_grammar& condition_parser,
        const value_ref_grammar<std::string>& string_grammar
    ) :
        effect_parser_rules_4::base_type(start, "effect_parser_rules_4"),
        int_rules(tok, label, condition_parser, string_grammar),
        double_rules(tok, label, condition_parser, string_grammar),
        star_type_rules(tok, label, condition_parser),
        planet_type_rules(tok, label, condition_parser),
        planet_size_rules(tok, label, condition_parser),
        one_or_more_effects(effect_parser)
    {
        qi::_1_type _1;
        qi::_2_type _2;
        qi::_3_type _3;
        qi::_4_type _4;
        qi::_5_type _5;
        qi::_6_type _6;
        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_;
        const boost::phoenix::function<deconstruct_movable_vector> deconstruct_movable_vector_;

        using phoenix::new_;
        using phoenix::construct;
        using phoenix::push_back;

        create_planet
            =   (   omit_[tok.CreatePlanet_]
                >   label(tok.type_)       > planet_type_rules.expr
                >   label(tok.planetsize_) > planet_size_rules.expr
                > -(label(tok.name_)       > string_grammar)
                > -(label(tok.effects_)    > one_or_more_effects)
                ) [ _val = construct_movable_(new_<Effect::CreatePlanet>(
                    deconstruct_movable_(_1, _pass),
                    deconstruct_movable_(_2, _pass),
                    deconstruct_movable_(_3, _pass),
                    deconstruct_movable_vector_(_4, _pass))) ]
            ;

        create_building
            =   (   omit_[tok.CreateBuilding_]
                    >   label(tok.type_)    > string_grammar
                    > -(label(tok.name_)    > string_grammar )
                    > -(label(tok.effects_) > one_or_more_effects )
                ) [ _val = construct_movable_(new_<Effect::CreateBuilding>(
                    deconstruct_movable_(_1, _pass),
                    deconstruct_movable_(_2, _pass),
                    deconstruct_movable_vector_(_3, _pass))) ]
            ;

        create_ship_1
            =   ((   omit_[tok.CreateShip_]
                 >>  label(tok.designid_)
                 )
                 >   int_rules.expr
                 > -(label(tok.empire_)      >   int_rules.expr)
                 > -(label(tok.species_)     >   string_grammar)
                 > -(label(tok.name_)        >   string_grammar)
                 > -(label(tok.effects_)     >   one_or_more_effects)
                ) [ _val = construct_movable_(new_<Effect::CreateShip>(
                    deconstruct_movable_(_1, _pass),
                    deconstruct_movable_(_2, _pass),
                    deconstruct_movable_(_3, _pass),
                    deconstruct_movable_(_4, _pass),
                    deconstruct_movable_vector_(_5, _pass))) ]
            ;

        create_ship_2
            =   ((   omit_[tok.CreateShip_]
                 >>  label(tok.designname_)  >>  string_grammar
                 )
                 > -(label(tok.empire_)      >   int_rules.expr)
                 > -(label(tok.species_)     >   string_grammar)
                 > -(label(tok.name_)        >   string_grammar)
                 > -(label(tok.effects_)     >   one_or_more_effects)
                ) [ _val = construct_movable_(new_<Effect::CreateShip>(
                    deconstruct_movable_(_1, _pass),
                    deconstruct_movable_(_2, _pass),
                    deconstruct_movable_(_3, _pass),
                    deconstruct_movable_(_4, _pass),
                    deconstruct_movable_vector_(_5, _pass))) ]
            ;

        create_field_1
            =   ((   omit_[tok.CreateField_]
                 >>  label(tok.type_) >> string_grammar
                 >>  label(tok.size_)
                 )
                 >   double_rules.expr
                 > -(label(tok.name_)    > string_grammar)
                 > -(label(tok.effects_) > one_or_more_effects)
                ) [ _val = construct_movable_(new_<Effect::CreateField>(
                    deconstruct_movable_(_1, _pass),
                    deconstruct_movable_(_2, _pass),
                    deconstruct_movable_(_3, _pass),
                    deconstruct_movable_vector_(_4, _pass))) ]
            ;

        create_field_2
            =   ((   omit_[tok.CreateField_]
                 >>  label(tok.type_)    >>  string_grammar
                 >>  label(tok.x_)
                 )
                 >   double_rules.expr
                 >   label(tok.y_)       >   double_rules.expr
                 >   label(tok.size_)    >   double_rules.expr
                 > -(label(tok.name_)    >   string_grammar )
                 > -(label(tok.effects_) > one_or_more_effects )
                ) [ _val = construct_movable_(new_<Effect::CreateField>(
                    deconstruct_movable_(_1, _pass),
                    deconstruct_movable_(_2, _pass),
                    deconstruct_movable_(_3, _pass),
                    deconstruct_movable_(_4, _pass),
                    deconstruct_movable_(_5, _pass),
                    deconstruct_movable_vector_(_6, _pass))) ]
            ;

        create_system_1
            =   ((   omit_[tok.CreateSystem_]
                 >>  label(tok.type_)
                 )
                 >   star_type_rules.expr 
                 >   label(tok.x_)       >   double_rules.expr
                 >   label(tok.y_)       >   double_rules.expr
                 > -(label(tok.name_)    >   string_grammar)
                 > -(label(tok.effects_) > one_or_more_effects)
                ) [ _val = construct_movable_(new_<Effect::CreateSystem>(
                    deconstruct_movable_(_1, _pass),
                    deconstruct_movable_(_2, _pass),
                    deconstruct_movable_(_3, _pass),
                    deconstruct_movable_(_4, _pass),
                    deconstruct_movable_vector_(_5, _pass))) ]
            ;

        create_system_2
            =   ((   omit_[tok.CreateSystem_]
                 >>  label(tok.x_)
                 )
                 >   double_rules.expr 
                 >   label(tok.y_)       >   double_rules.expr
                 > -(label(tok.name_)    >   string_grammar)
                 > -(label(tok.effects_) > one_or_more_effects)
                ) [ _val = construct_movable_(new_<Effect::CreateSystem>(
                    deconstruct_movable_(_1, _pass),
                    deconstruct_movable_(_2, _pass),
                    deconstruct_movable_(_3, _pass),
                    deconstruct_movable_vector_(_4, _pass))) ]
            ;

        start
            %=  create_planet
            |   create_building
            |   create_ship_1
            |   create_ship_2
            |   create_field_1
            |   create_field_2
            |   create_system_1
            |   create_system_2
            ;

        create_planet.name("CreatePlanet");
        create_building.name("CreateBuilding");
        create_ship_1.name("CreateShip");
        create_ship_2.name("CreateShip");
        create_field_1.name("CreateField");
        create_field_2.name("CreateField");
        create_system_1.name("CreateSystem");
        create_system_2.name("CreateSystem");

#if DEBUG_EFFECT_PARSERS
        debug(create_planet);
        debug(create_building);
        debug(create_ship_1);
        debug(create_ship_2);
        debug(create_field_1);
        debug(create_field_2);
        debug(create_system_1);
        debug(create_system_2);
#endif
    }

} }