PageRenderTime 26ms CodeModel.GetById 17ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 1ms

/Src/Dependencies/Boost/boost/spirit/home/classic/core/composite/impl/directives.ipp

http://hadesmem.googlecode.com/
C++ Header | 374 lines | 299 code | 53 blank | 22 comment | 1 complexity | c6a03423d07efaae70af6fe8d1052506 MD5 | raw file
  1/*=============================================================================
  2    Copyright (c) 1998-2003 Joel de Guzman
  3    Copyright (c) 2001 Daniel Nuffer
  4    Copyright (c) 2001 Bruce Florman
  5    Copyright (c) 2002 Raghavendra Satish
  6    http://spirit.sourceforge.net/
  7
  8    Use, modification and distribution is subject to the Boost Software
  9    License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
 10    http://www.boost.org/LICENSE_1_0.txt)
 11=============================================================================*/
 12#if !defined(BOOST_SPIRIT_DIRECTIVES_IPP)
 13#define BOOST_SPIRIT_DIRECTIVES_IPP
 14
 15///////////////////////////////////////////////////////////////////////////////
 16#include <boost/spirit/home/classic/core/scanner/skipper.hpp>
 17
 18namespace boost { namespace spirit {
 19
 20BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN
 21
 22    template <typename BaseT>
 23    struct no_skipper_iteration_policy;
 24
 25    template <typename BaseT>
 26    struct inhibit_case_iteration_policy;
 27
 28    template <typename A, typename B>
 29    struct alternative;
 30
 31    template <typename A, typename B>
 32    struct longest_alternative;
 33
 34    template <typename A, typename B>
 35    struct shortest_alternative;
 36
 37    namespace impl
 38    {
 39        template <typename RT, typename ST, typename ScannerT, typename BaseT>
 40        inline RT
 41        contiguous_parser_parse(
 42            ST const& s,
 43            ScannerT const& scan,
 44            skipper_iteration_policy<BaseT> const&)
 45        {
 46            typedef scanner_policies<
 47                no_skipper_iteration_policy<
 48                    BOOST_DEDUCED_TYPENAME ScannerT::iteration_policy_t>,
 49                BOOST_DEDUCED_TYPENAME ScannerT::match_policy_t,
 50                BOOST_DEDUCED_TYPENAME ScannerT::action_policy_t
 51            > policies_t;
 52
 53            scan.skip(scan);
 54            RT hit = s.parse(scan.change_policies(policies_t(scan)));
 55            // We will not do a post skip!!!
 56            return hit;
 57        }
 58
 59        template <typename RT, typename ST, typename ScannerT, typename BaseT>
 60        inline RT
 61        contiguous_parser_parse(
 62            ST const& s,
 63            ScannerT const& scan,
 64            no_skipper_iteration_policy<BaseT> const&)
 65        {
 66            return s.parse(scan);
 67        }
 68
 69        template <typename RT, typename ST, typename ScannerT>
 70        inline RT
 71        contiguous_parser_parse(
 72            ST const& s,
 73            ScannerT const& scan,
 74            iteration_policy const&)
 75        {
 76            return s.parse(scan);
 77        }
 78
 79        template <
 80            typename RT,
 81            typename ParserT,
 82            typename ScannerT,
 83            typename BaseT>
 84        inline RT
 85        implicit_lexeme_parse(
 86            ParserT const& p,
 87            ScannerT const& scan,
 88            skipper_iteration_policy<BaseT> const&)
 89        {
 90            typedef scanner_policies<
 91                no_skipper_iteration_policy<
 92                    BOOST_DEDUCED_TYPENAME ScannerT::iteration_policy_t>,
 93                BOOST_DEDUCED_TYPENAME ScannerT::match_policy_t,
 94                BOOST_DEDUCED_TYPENAME ScannerT::action_policy_t
 95            > policies_t;
 96
 97            scan.skip(scan);
 98            RT hit = p.parse_main(scan.change_policies(policies_t(scan)));
 99            // We will not do a post skip!!!
100            return hit;
101        }
102
103        template <
104            typename RT,
105            typename ParserT,
106            typename ScannerT,
107            typename BaseT>
108        inline RT
109        implicit_lexeme_parse(
110            ParserT const& p,
111            ScannerT const& scan,
112            no_skipper_iteration_policy<BaseT> const&)
113        {
114            return p.parse_main(scan);
115        }
116
117        template <typename RT, typename ParserT, typename ScannerT>
118        inline RT
119        implicit_lexeme_parse(
120            ParserT const& p,
121            ScannerT const& scan,
122            iteration_policy const&)
123        {
124            return p.parse_main(scan);
125        }
126
127        template <typename RT, typename ST, typename ScannerT>
128        inline RT
129        inhibit_case_parser_parse(
130            ST const& s,
131            ScannerT const& scan,
132            iteration_policy const&)
133        {
134            typedef scanner_policies<
135                inhibit_case_iteration_policy<
136                    BOOST_DEDUCED_TYPENAME ScannerT::iteration_policy_t>,
137                BOOST_DEDUCED_TYPENAME ScannerT::match_policy_t,
138                BOOST_DEDUCED_TYPENAME ScannerT::action_policy_t
139            > policies_t;
140
141            return s.parse(scan.change_policies(policies_t(scan)));
142        }
143
144        template <typename RT, typename ST, typename ScannerT, typename BaseT>
145        inline RT
146        inhibit_case_parser_parse(
147            ST const& s,
148            ScannerT const& scan,
149            inhibit_case_iteration_policy<BaseT> const&)
150        {
151            return s.parse(scan);
152        }
153
154#if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
155
156        ///////////////////////////////////////////////////////////////////////
157        //
158        //  from spirit 1.1 (copyright (c) 2001 Bruce Florman)
159        //  various workarounds to support longest and shortest directives
160        //
161        ///////////////////////////////////////////////////////////////////////
162        template <typename T>
163        struct is_alternative
164        {
165        //  Determine at compile time (without partial specialization)
166        //  whether a given type is an instance of the alternative<A,B>
167
168            static T t();
169            template <typename A, typename B>
170            static char test_(alternative<A, B> const&);    // no implementation
171            static int  test_(...);                         // no implementation
172            enum { r = sizeof(char) == sizeof(test_(t())) };
173            typedef mpl::bool_<r> value;
174        };
175
176        template <typename T> struct select_to_longest;
177
178        template <typename T>
179        struct to_longest_alternative
180        {
181            typedef typename select_to_longest<T>::result_t result_t;
182            typedef typename select_to_longest<T>::plain_t  plain_t;
183            typedef typename select_to_longest<T>::choose_t choose_t;
184            static result_t convert(T const& a);
185        };
186
187        template <typename T>
188        struct to_longest_generic
189        {
190            typedef T const&        result_t;
191            typedef T               plain_t;
192            typedef mpl::false_    choose_t;
193        };
194
195        template <typename T>
196        inline T const&
197        to_longest_convert(T const& a, mpl::false_)
198        { return a; }
199
200        template <typename T>
201        struct to_longest_recursive
202        {
203            typedef typename to_longest_alternative<
204                typename T::left_t>::plain_t    a_t;
205            typedef typename to_longest_alternative<
206                typename T::right_t>::plain_t   b_t;
207
208            typedef longest_alternative<a_t, b_t>   result_t;
209
210            typedef result_t    plain_t;
211            typedef mpl::true_ choose_t;
212        };
213
214        template <typename A, typename B>
215        inline typename to_longest_alternative<alternative<A, B> >::result_t
216        to_longest_convert(alternative<A, B> const& alt, mpl::true_)
217        {
218            typedef typename to_longest_alternative<
219                alternative<A, B> >::result_t result_t;
220            return result_t(
221                to_longest_alternative<A>::convert(alt.left()),
222                to_longest_alternative<B>::convert(alt.right()));
223        }
224
225        template <typename T>
226        inline typename to_longest_alternative<T>::result_t
227        to_longest_alternative<T>::convert(T const& a)
228        {
229            return to_longest_convert(
230                a, to_longest_alternative<T>::choose_t());
231        }
232
233        template <typename T>
234        struct select_to_longest
235        {
236            typedef typename mpl::if_<
237                is_alternative<T>           //  IF
238                , to_longest_recursive<T>   //  THEN
239                , to_longest_generic<T>     //  ELSE
240            >::type type;
241
242            typedef typename select_to_longest::type::result_t result_t;
243            typedef typename select_to_longest::type::plain_t  plain_t;
244            typedef typename select_to_longest::type::choose_t choose_t;
245        };
246
247        template <typename T> struct select_to_shortest;
248
249        template <typename T>
250        struct to_shortest_alternative
251        {
252            typedef typename select_to_shortest<T>::result_t    result_t;
253            typedef typename select_to_shortest<T>::plain_t     plain_t;
254            typedef typename select_to_shortest<T>::choose_t    choose_t;
255            static result_t convert(T const& a);
256        };
257
258        template <typename T>
259        struct to_shortest_generic
260        {
261            typedef T const&        result_t;
262            typedef T               plain_t;
263            typedef mpl::false_    choose_t;
264        };
265
266        template <typename T>
267        inline T const&
268        to_shortest_convert(T const& a, mpl::false_) { return a; }
269
270        template <typename T>
271        struct to_shortest_recursive
272        {
273            typedef typename to_shortest_alternative<
274                typename T::left_t>::plain_t    a_t;
275            typedef typename to_shortest_alternative<
276                typename T::right_t>::plain_t   b_t;
277
278            typedef shortest_alternative<a_t, b_t>  result_t;
279
280            typedef result_t        plain_t;
281            typedef mpl::true_     choose_t;
282        };
283
284        template <typename A, typename B>
285        inline typename to_shortest_alternative<alternative<A, B> >::result_t
286        to_shortest_convert(alternative<A, B> const& alt, mpl::true_)
287        {
288            typedef typename to_shortest_alternative<
289                alternative<A, B> >::result_t result_t;
290            return result_t(
291                to_shortest_alternative<A>::convert(alt.left()),
292                to_shortest_alternative<B>::convert(alt.right()));
293        }
294
295        template <typename T>
296        inline typename to_shortest_alternative<T>::result_t
297        to_shortest_alternative<T>::convert(T const& a)
298        {
299            return to_shortest_convert(
300                a, to_shortest_alternative<T>::choose_t());
301        }
302
303        template <typename T>
304        struct select_to_shortest
305        {
306            typedef typename mpl::if_<
307                is_alternative<T>           //  IF
308                , to_shortest_recursive<T>  //  THEN
309                , to_shortest_generic<T>    //  ELSE
310            >::type type;
311
312            typedef typename select_to_shortest::type::result_t result_t;
313            typedef typename select_to_shortest::type::plain_t  plain_t;
314            typedef typename select_to_shortest::type::choose_t choose_t;
315        };
316#else
317        template <typename T>
318        struct to_longest_alternative
319        {
320            typedef T result_t;
321            static result_t const&
322            convert(T const& a)  //  Special (end) case
323            { return a; }
324        };
325
326        template <typename A, typename B>
327        struct to_longest_alternative<alternative<A, B> >
328        {
329            typedef typename to_longest_alternative<A>::result_t    a_t;
330            typedef typename to_longest_alternative<B>::result_t    b_t;
331            typedef longest_alternative<a_t, b_t>                   result_t;
332
333            static result_t
334            convert(alternative<A, B> const& alt) // Recursive case
335            {
336                return result_t(
337                    to_longest_alternative<A>::convert(alt.left()),
338                    to_longest_alternative<B>::convert(alt.right()));
339            }
340        };
341
342        template <typename T>
343        struct to_shortest_alternative
344        {
345            typedef T result_t;
346            static result_t const&
347            convert(T const& a) //  Special (end) case
348            { return a; }
349        };
350
351        template <typename A, typename B>
352        struct to_shortest_alternative<alternative<A, B> >
353        {
354            typedef typename to_shortest_alternative<A>::result_t   a_t;
355            typedef typename to_shortest_alternative<B>::result_t   b_t;
356            typedef shortest_alternative<a_t, b_t>                  result_t;
357
358            static result_t
359            convert(alternative<A, B> const& alt) //  Recursive case
360            {
361                return result_t(
362                    to_shortest_alternative<A>::convert(alt.left()),
363                    to_shortest_alternative<B>::convert(alt.right()));
364            }
365        };
366#endif
367    }
368
369BOOST_SPIRIT_CLASSIC_NAMESPACE_END
370
371}} // namespace boost::spirit
372
373#endif
374