Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-31 10:02:08

0001 /*==============================================================================
0002     Copyright (c) 2006 Tobias Schwinger
0003     http://spirit.sourceforge.net/
0004 
0005   Distributed under the Boost Software License, Version 1.0. (See accompanying
0006   file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0007 ==============================================================================*/
0008 // The comment below contains a unnamed 'namespace {', which is flagged by the
0009 // Boost inspect tool as a violation of common C++ programming rules. Since it's
0010 // in a comment, well, we switch it off :-P
0011 // boostinspect:nounnamed
0012 
0013 //
0014 // About:
0015 // =====
0016 //
0017 // Using a typeof operator or Boost.Typeof to automatically set the type of
0018 // variables (as done in the Spirit example demonstrating typeof) is by far not
0019 // all we can do to tighten up our grammars as there are some significant
0020 // drawbacks of this approach:
0021 // - the types complexity scales with the complexity of the grammar (sooner or
0022 //   later hitting the limits of the compiler),
0023 // - recursive grammars are not possible, and
0024 // - all parser objects are embedded by value.
0025 //
0026 // The Spirit documentation therefore recommends creating custom parser classes
0027 // (derived from the a sub_grammar template):
0028 //
0029 //   http://www.boost.org/libs/spirit/doc/techniques.html#no_rules
0030 //   http://www.boost.org/libs/spirit/doc/techniques.html#typeof
0031 //
0032 // In practice manually applying this technique leads to rather lengthy code and
0033 // overthis requires the user to have a solid understanding of Spirit details.
0034 //
0035 // Here is a generalized, macro-based approach to easily create typeof-based
0036 // grammars that can be recursive and arbitrarily complex.
0037 //
0038 //
0039 // Quick manual:
0040 // ============
0041 //
0042 // 1. Setup
0043 //
0044 // Before the rule parser macro (the protagonist of the facility) can be used
0045 // the user must define the macro BOOST_SPIRIT__NAMESPACE (note the double
0046 // underscore characeter) and setup a registration group for Boost.Typeof.
0047 //
0048 // Examples:
0049 //
0050 //   // should come after regular #includeS
0051 //   #include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP()
0052 //
0053 //   // [...]
0054 //
0055 //   #define BOOST_SPIRIT__NAMESPACE (2,(my_project, my_module))
0056 //   //                             | |     +- outer     +- inner
0057 //   //                  ! space ! -+ |         namespace    namespace
0058 //   //                               |
0059 //   //                               +--- number of nested namespaces
0060 //
0061 //   namespace my_project { namespace my_module {
0062 //
0063 //   // [...]
0064 //
0065 //  ---
0066 //
0067 //   // should come after regular #includeS
0068 //   #include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP()
0069 //
0070 //   // [...]
0071 //
0072 //   #define BOOST_SPIRIT__NAMESPACE (2,(my_project, (anonymous) ))
0073 //
0074 //   namespace my_project { namespace {
0075 //
0076 //   // [...]
0077 //
0078 //  ---
0079 //
0080 //   // should come after regular #includeS
0081 //   #include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP()
0082 //
0083 //   // [...]
0084 //
0085 //
0086 //   #define BOOST_SPIRIT__NAMESPACE -
0087 //   // we're working at root namespace
0088 //
0089 //
0090 // Why do I have to do this?
0091 //
0092 //   Boost.Typeof needs to assign a unique ID for each registration. This ID is
0093 //   created composed of the line number and the registration group. The
0094 //   facility performs Typeof registration and thus requires the source file to
0095 //   have its own registration group. Further Boost.Typeof requires registration
0096 //   to happen at root namespace so we have to close and reopen the namespace
0097 //   we're in.
0098 //
0099 //
0100 // 2. The rule parser macro
0101 //
0102 // A simple rule parser definition looks like that:
0103 //
0104 //   // we're at namespace scope here
0105 //
0106 //   // Skip parser for C/C++ comments and whitespace
0107 //   BOOST_SPIRIT_RULE_PARSER(skipper,
0108 //     -,-,-,
0109 //
0110 //     +(   confix_p("//",*anychar_p,eol_p)
0111 //        | confix_p("/*",*anychar_p,"*/")
0112 //        | space_p
0113 //     )
0114 //   )
0115 //
0116 // Now we can use 'skipper' in other Spirit expressions.
0117 //
0118 // The code above creates a parser (template) class 'skpper_t' and (in this
0119 // case, because there are no parameters) a static const instance 'skipper' of
0120 // that class. The class is automatically registered with Boost.Typeof. The type
0121 // name our parser is skipper_t here.
0122 //
0123 //
0124 // 2.1. Parametrized rule parsers
0125 //
0126 // Rule parser definitions can have parameters.
0127 //
0128 // Parameters are passed to the BOOST_SPIRIT_RULE_PARSER macro as its second
0129 // argument (just pass '-' if there are no parameters) with the following
0130 // format:
0131 //
0132 //   (N,( param1,param2, / ... / paramN ))
0133 //    +-- number of parameters
0134 //
0135 // Example of a whole rule parser:
0136 //
0137 //   BOOST_SPIRIT_RULE_PARSER(new_name,
0138 //     (1,( symbol_table )),-,-,
0139 //
0140 //     lexeme_d[ (alpha_p >> *alnum_p)[ symbol_table.add ] ]
0141 //   )
0142 //
0143 // The expression 'new_name(my_symbols)' parses a string literal and adds it to
0144 // the symbol table 'my_symbols'.
0145 //
0146 // The rule parser macro creates a function template as called 'new_name' that
0147 // takes one parameter of deduced reference type and returns a specialization of
0148 // 'new_name_t' in this case.
0149 //
0150 // Since parsers that require to be fast and lightweight often also require to
0151 // be reentrant, it's quite common to pass in some semantic controller (the
0152 // symbol table in the example above).
0153 // However, parameters are templated so they can be anything (including parsers
0154 // of course) so refactoring tasks can be abstracted with rule parsers as well.
0155 //
0156 //   BOOST_SPIRIT_RULE_PARSER(enumeration_parser,
0157 //     (2,( element_parser, delimiter_parser )),-,-,
0158 //
0159 //     element_parser >> *(delimiter_parser >> element_parser)
0160 //   )
0161 //
0162 // The expression 'enumeration_parser(int_p[ some_action ], ',')' creates a
0163 // parser for a comma-separated list of integers.
0164 //
0165 //
0166 // 2.2. Rule parsrs and semantic actions
0167 //
0168 // While semantic actions can be globally attached to a rule parser or passed
0169 // to a parametrized rule parser as (part of) an argument, even more control is
0170 // possible by using action placeholders. E.g:
0171 //
0172 //   BOOST_SPIRIT_ACTION_PLACEHOLDER(int_action)
0173 //
0174 //   BOOST_SPIRIT_RULE_PARSER(int_list,
0175 //     -,(1,( int_action )),-,
0176 //
0177 //     int_p[ int_action ] >> *(',' >> int_p[ int_action ])
0178 //   )
0179 //
0180 // The expression 'int_list[ my_action ]' parses a comma separated list of
0181 // integers and calls 'my_action' for every integer parsed therein.
0182 //
0183 // Of course multiple actions can be attached to one placeholder as usual (in
0184 // this case 'int_list[ my_action1 ][ my_action2 ] would call two actions).
0185 //
0186 // Further there can be multiple action placeholders for a single rule parser:
0187 //
0188 //   BOOST_SPIRIT_ACTION_PLACEHOLDER(feed_int)
0189 //   BOOST_SPIRIT_ACTION_PLACEHOLDER(next_int)
0190 //
0191 //   BOOST_SPIRIT_RULE_PARSER(int_list,
0192 //     -,(2,( feed_int, next_int )),-,
0193 //
0194 //     int_p[ feed_int ] >> *(',' >> int_p[ next_int ][ feed_int ])
0195 //   )
0196 //
0197 // The expression 'int_list[ (feed_int = my_action1), (next_int = my_action2) ]'
0198 // creates a parser for a comma separated list of integers with the actions
0199 // attached appropriately.
0200 //
0201 //   int_list[ feed_int = my_action1,my_action2, next_int = my_action3 ]
0202 //
0203 // works too (in this case the action placeholder 'feed_int' has two actions
0204 // attached to it).
0205 //
0206 // You can both override and append actions associated with an action
0207 // placeholder:
0208 //
0209 //   var = int_list[ feed_int = my_action1, next_int = my_action2 ]
0210 //
0211 //   // [...]
0212 //
0213 //   ... var[ feed_int = another_action ]
0214 //   // 'another_action' overrides the actions previously attached to 'feed_int'
0215 //
0216 //   ... var[ next_int += another_action ]
0217 //   // 'another_action' is appended to the list of actions attached to
0218 //   // 'next_int'
0219 //
0220 // Action placeholders are not entirely for free -- they add to the size and the
0221 // initialization time of the rule parser. However, the impact on an already
0222 // initialized rule parser instance should be quite small.
0223 //
0224 //
0225 // 2.3. Member variables
0226 //
0227 // You can add member variables to the rule parser class using the third
0228 // parameter of the rule parser macro:
0229 //
0230 //   BOOST_SPIRIT_RULE_PARSER( calc,
0231 //     -,
0232 //     -,
0233 //     (3,( ((subrule<0>),expression,()),
0234 //          ((subrule<1>),term,()),
0235 //          ((subrule<2>),factor,() )) ),
0236 //
0237 //     // [...]
0238 //
0239 // adds three subrules to the rule parser.
0240 // Each parameter must have the following type to allow commas to be handled
0241 // safely from within the preprocessing code:
0242 //
0243 //   ((type)),name,(constructor argument(s)))
0244 //
0245 //
0246 // 2.4. The opaque rule parser
0247 //
0248 // Rule parsers usually are templates. Building large grammars pushes the
0249 // compiler really hard (and eventually to its limits) because of the
0250 // metafunction complexity involved.
0251 // If a rule parser without parameters and action placeholders is defined, a
0252 // non-template class is created. Non-templated rule parsers can also be created
0253 // explicitly by using BOOST_SPIRIT_OPAQUE_RULE_PARSER.
0254 // Opaque rule parsers can have parameters and member variables (note: no action
0255 // placeholders are possible). The parameters of an opaque rule parsers are
0256 // strictly typed, e.g:
0257 //
0258 //   BOOST_SPIRIT_OPAQUE_RULE_PARSER(new_identifier,
0259 //     (1,( ((my_symbol_table_t &),symbol_table) ))
0260 //     ,-,
0261 //     (alpha_p >> *alnum_p) [ symbol_table.add ]
0262 //   )
0263 //
0264 // Note it's also possible to have opaque rule parsers accept parameters of
0265 // non-const reference types which is not possible with regular rule parsers.
0266 //
0267 //
0268 // 3. Utilities for by-reference embedding
0269 //
0270 // When using parsers multiple times or recursively it can be helpful to embed
0271 // them by-reference into the final parser expression.
0272 // For this purpose the library provides a wrapper template 'parser_reference'.
0273 // There is also a function template to create a wrapped parser which can deduce
0274 // the parser's type from its argument.
0275 //
0276 // --- --- - - --- - - --- - - - - --- - - - - - - - - - - - - - - - - - - - - -
0277 #if !defined(BOOST_SPIRIT_UTILITY_RULE_PARSER_HPP_INCLUDED)
0278 #   define BOOST_SPIRIT_UTILITY_RULE_PARSER_HPP_INCLUDED
0279 //==============================================================================
0280 // Dependencies
0281 //==============================================================================
0282 #   include <boost/config.hpp>
0283 #   include <boost/detail/workaround.hpp>
0284 #   include <boost/call_traits.hpp>
0285 #   include <boost/typeof/typeof.hpp>
0286 #   include <boost/spirit/home/classic/namespace.hpp>
0287 #   include <boost/spirit/home/classic/core/parser.hpp>
0288 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
0289 #   include <boost/preprocessor/cat.hpp>
0290 #   include <boost/preprocessor/seq/seq.hpp>
0291 #   include <boost/preprocessor/seq/for_each_i.hpp>
0292 #   include <boost/preprocessor/tuple/eat.hpp>
0293 #   include <boost/preprocessor/tuple/to_seq.hpp>
0294 #   include <boost/preprocessor/array/size.hpp>
0295 #   include <boost/preprocessor/control/if.hpp>
0296 #   include <boost/preprocessor/control/iif.hpp>
0297 #   include <boost/preprocessor/control/expr_iif.hpp>
0298 #   include <boost/preprocessor/logical/or.hpp>
0299 #   include <boost/preprocessor/logical/nor.hpp>
0300 #   include <boost/preprocessor/logical/not.hpp>
0301 #   include <boost/preprocessor/logical/compl.hpp>
0302 #   include <boost/preprocessor/arithmetic/inc.hpp>
0303 #   include <boost/preprocessor/arithmetic/dec.hpp>
0304 #   include <boost/preprocessor/arithmetic/add.hpp>
0305 #   include <boost/preprocessor/detail/is_unary.hpp>
0306 #   include <boost/preprocessor/detail/is_binary.hpp>
0307 #   include <boost/preprocessor/repetition/repeat.hpp>
0308 #   include <boost/preprocessor/repetition/enum_params.hpp>
0309 #   include <boost/preprocessor/repetition/enum_binary_params.hpp>
0310 #   include <boost/preprocessor/repetition/enum_shifted_params.hpp>
0311 #   include <boost/preprocessor/repetition/enum_trailing_params.hpp>
0312 #   include <boost/preprocessor/punctuation/comma.hpp>
0313 #   include <boost/preprocessor/punctuation/comma_if.hpp>
0314 #   include <boost/preprocessor/facilities/empty.hpp>
0315 #   include <boost/preprocessor/facilities/identity.hpp>
0316 #   include <boost/preprocessor/facilities/intercept.hpp>
0317 //==============================================================================
0318 // Interface
0319 //==============================================================================
0320 // Creates a rule parser. Use at namespace scope.
0321 #   define BOOST_SPIRIT_RULE_PARSER(name,params,actions,members,rule)          \
0322       BOOST_SPIRIT_RP_IMPL_I(name,params,actions,members,rule)
0323 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
0324 // Creates a non-templated rule parser. Use at namespace scope.
0325 #   define BOOST_SPIRIT_OPAQUE_RULE_PARSER(name,params,members,rule)           \
0326       BOOST_SPIRIT_RP_OPAQUE_IMPL_I(name,params,members,rule)
0327 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
0328 // Defines an action placeholder. Use at namespace scope.
0329 #   define BOOST_SPIRIT_ACTION_PLACEHOLDER(name)                               \
0330       BOOST_SPIRIT_RP_AP_IMPL(name,::BOOST_SPIRIT_CLASSIC_NS::type_of)
0331 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
0332 // Utilities to embed parsers by reference.
0333 namespace boost
0334 {
0335   namespace spirit
0336   {
0337     BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN
0338 
0339     template<class P> class parser_reference;
0340     template<class P> parser_reference<P> embed_by_reference(parser<P> const &);
0341 
0342     BOOST_SPIRIT_CLASSIC_NAMESPACE_END
0343   }
0344 }
0345 //==============================================================================
0346 // Implementation
0347 //==============================================================================
0348 #include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP()
0349 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
0350 // RP_REGISTER_TEMPLATE
0351 //
0352 // Boost.Typeof registration from within BOOST_SPIRIT__NAMESPACE
0353 #   define BOOST_SPIRIT_RP_REGISTER_TEMPLATE(name,params)                      \
0354       BOOST_SPIRIT_RP_EMIT(NS_CLOSE,BOOST_SPIRIT__NAMESPACE,-)                 \
0355     BOOST_TYPEOF_REGISTER_TEMPLATE(                                            \
0356         BOOST_SPIRIT_RP_EMIT(NS_QUALIFY,BOOST_SPIRIT__NAMESPACE,-) name,       \
0357         params)                                                                \
0358       BOOST_SPIRIT_RP_EMIT(NS_OPEN,BOOST_SPIRIT__NAMESPACE,-)
0359 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
0360 // RP_REGISTER_TYPE
0361 //
0362 // Boost.Typeof registration from within BOOST_SPIRIT__NAMESPACE
0363 #   define BOOST_SPIRIT_RP_REGISTER_TYPE(name)                                 \
0364       BOOST_SPIRIT_RP_EMIT(NS_CLOSE,BOOST_SPIRIT__NAMESPACE,-)                 \
0365     BOOST_TYPEOF_REGISTER_TYPE(                                                \
0366         BOOST_SPIRIT_RP_EMIT(NS_QUALIFY,BOOST_SPIRIT__NAMESPACE,-) name )      \
0367       BOOST_SPIRIT_RP_EMIT(NS_OPEN,BOOST_SPIRIT__NAMESPACE,-)
0368 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
0369 // RP_AP_IMPL
0370 //
0371 // The action placeholder definition
0372 #   define BOOST_SPIRIT_RP_AP_IMPL(name,ns)                                    \
0373       namespace __action_placeholder                                           \
0374       {                                                                        \
0375         struct name                                                            \
0376         {                                                                      \
0377           template<typename Action>                                            \
0378           ns :: action_chain< name, ns :: replace, Action>                     \
0379           operator=(Action const & __a) const                                  \
0380           { return ns :: action_chain< name, ns :: replace, Action>(__a); }    \
0381                                                                                \
0382           template<typename Action>                                            \
0383           ns :: action_chain< name, ns :: append, Action>                      \
0384           operator+=(Action const & __a) const                                 \
0385           { return ns :: action_chain< name, ns :: append, Action> (__a); }    \
0386         };                                                                     \
0387       }                                                                        \
0388       __action_placeholder:: name const name = __action_placeholder:: name ();
0389 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
0390 // RP_IMPL_I
0391 //
0392 // Does some precalculation so RP_IMPL_II can look cleaner
0393 #   define BOOST_SPIRIT_RP_IMPL_I(name,pars,acts,mbrs,expr)                    \
0394       BOOST_SPIRIT_RP_IMPL_II(name, name ## _t ,                               \
0395                               pars, BOOST_SPIRIT_RP_ARRAY_SIZE(pars),          \
0396                               acts, BOOST_SPIRIT_RP_ARRAY_SIZE(acts),          \
0397                               mbrs, BOOST_SPIRIT_RP_ARRAY_SIZE(mbrs), expr)
0398 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
0399 // RP_IMPL_II
0400 #   define BOOST_SPIRIT_RP_IMPL_II(name,name_t,pars,np,acts,na,mbrs,nm,x)      \
0401       BOOST_PP_IIF(BOOST_PP_OR(np,na),BOOST_SPIRIT_RP_IMPL_III,                \
0402                                       BOOST_SPIRIT_RP_OPAQUE_IMPL_II)          \
0403                                          (name,name_t,pars,np,acts,na,mbrs,nm,x)
0404 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
0405 // RP_IMPL_III
0406 //
0407 // The rule parser definition
0408 #   define BOOST_SPIRIT_RP_IMPL_III(name,name_t,pars,np,acts,na,mbrs,nm,x)     \
0409                                                                                \
0410       template< BOOST_SPIRIT_RP_TPL_PARAMS(pars,acts,typename __,1) >          \
0411       class name_t                                                             \
0412         : public ::BOOST_SPIRIT_CLASSIC_NS::parser< name_t                     \
0413                        < BOOST_SPIRIT_RP_TPL_PARAMS(pars,acts,__,0) > >        \
0414       {                                                                        \
0415         class __rule                                                           \
0416         {                                                                      \
0417           BOOST_SPIRIT_RP_EMIT(PM_STATIC,pars,__T)                             \
0418           BOOST_SPIRIT_RP_EMIT(AP_STATIC,acts,-)                               \
0419           BOOST_SPIRIT_RP_EMIT(MV_STATIC,mbrs,BOOST_PP_IDENTITY(typename))     \
0420         public:                                                                \
0421           BOOST_TYPEOF_NESTED_TYPEDEF_TPL(__expr,                              \
0422             ::BOOST_SPIRIT_CLASSIC_NS::type_of::depend_on_type<__Dummy>(x) )   \
0423         };                                                                     \
0424                                                                                \
0425       public:                                                                  \
0426                                                                                \
0427         typedef name_t self_t;                                                 \
0428         typedef typename __rule::__expr::type::parser_category_t               \
0429                                                            parser_category_t;  \
0430                                                                                \
0431         BOOST_PP_EXPR_IIF(BOOST_PP_NOR(np,na),typedef self_t const & embed_t;) \
0432                                                                                \
0433       protected:                                                               \
0434                                                                                \
0435         BOOST_SPIRIT_RP_EMIT(MV_NONSTATIC,mbrs,BOOST_PP_IDENTITY(typename))    \
0436         BOOST_SPIRIT_RP_IF(na,SPIRIT_RP_AP_EXTRA_MBRS,2)(np,na)                \
0437                                                                                \
0438         typename __rule::__expr::type::embed_t __parser;                       \
0439                                                                                \
0440       public:                                                                  \
0441                                                                                \
0442         explicit name_t ( BOOST_SPIRIT_RP_CTOR(PARAMS,pars,np,acts) )          \
0443           : BOOST_SPIRIT_RP_EMIT(MV_CTOR_INIT_LIST,mbrs,-)                     \
0444           BOOST_PP_COMMA_IF(nm)                                                \
0445           BOOST_SPIRIT_RP_IF(na,SPIRIT_RP_CTOR_COMMA,4)(INIT_LIST,pars,np,acts)\
0446             __parser(x)                                                        \
0447         { }                                                                    \
0448                                                                                \
0449         name_t( name_t const & that)                                           \
0450           : BOOST_SPIRIT_RP_EMIT(MV_CTOR_COPY_INIT_LIST,mbrs,that)             \
0451           BOOST_PP_COMMA_IF(nm)                                                \
0452           BOOST_SPIRIT_RP_IF(na,SPIRIT_RP_CTOR_COMMA,4)                        \
0453                                                  (COPY_INIT_LIST,pars,np,acts) \
0454             __parser(that.__parser)                                            \
0455         { }                                                                    \
0456                                                                                \
0457         template<typename Scanner> struct result                               \
0458         {                                                                      \
0459           typedef typename ::BOOST_SPIRIT_CLASSIC_NS::parser_result<                     \
0460                            typename __rule::__expr::type, Scanner>::type type; \
0461         };                                                                     \
0462                                                                                \
0463         template<typename Scanner>                                             \
0464         typename ::BOOST_SPIRIT_CLASSIC_NS::parser_result<self_t, Scanner>::type         \
0465         parse(Scanner const & s) const { return __parser.parse(s); }           \
0466                                                                                \
0467         BOOST_SPIRIT_RP_IF(na,SPIRIT_RP_AP_HANDLER,5)                          \
0468                                   (name_t,np,acts,na,::BOOST_SPIRIT_CLASSIC_NS::type_of) \
0469       };                                                                       \
0470                                                                                \
0471       BOOST_PP_IF(np,BOOST_SPIRIT_RP_GEN_FUNC,BOOST_SPIRIT_RP_GLOB_VAR)        \
0472                                                            (name,name_t,np,na) \
0473       BOOST_SPIRIT_RP_REGISTER_TEMPLATE                                        \
0474         (name_t,BOOST_PP_INC(BOOST_PP_ADD(np,na)))
0475 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
0476 // RP_OPAQUE_IMPL_I
0477 //
0478 #   define BOOST_SPIRIT_RP_OPAQUE_IMPL_I(name,pars,mbrs,expr)                  \
0479       BOOST_SPIRIT_RP_OPAQUE_IMPL_II(name, name ## _t,                         \
0480                                      pars,BOOST_SPIRIT_RP_ARRAY_SIZE(pars),-,-,\
0481                                      mbrs,BOOST_SPIRIT_RP_ARRAY_SIZE(mbrs),expr)
0482 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
0483 // RP_OPAQUE_IMPL_II
0484 //
0485 #   define BOOST_SPIRIT_RP_OPAQUE_IMPL_II(name,name_t,pars,np,_1,_2,mbrs,nm,x) \
0486       class name_t;                                                            \
0487                                                                                \
0488       BOOST_SPIRIT_RP_REGISTER_TYPE(name_t)                                    \
0489                                                                                \
0490       class name_t                                                             \
0491         : public ::BOOST_SPIRIT_CLASSIC_NS::parser< name_t >                             \
0492       {                                                                        \
0493         class __rule                                                           \
0494         {                                                                      \
0495           BOOST_SPIRIT_RP_EMIT(PM_OPAQUE_STATIC,pars,-)                        \
0496           BOOST_SPIRIT_RP_EMIT(MV_STATIC,mbrs,BOOST_PP_EMPTY)                  \
0497         public:                                                                \
0498           BOOST_TYPEOF_NESTED_TYPEDEF(__expr,x)                                \
0499         };                                                                     \
0500                                                                                \
0501       public:                                                                  \
0502                                                                                \
0503         typedef name_t self_t;                                                 \
0504         typedef __rule::__expr::type::parser_category_t parser_category_t;     \
0505         BOOST_PP_EXPR_IIF(BOOST_PP_NOT(np),typedef self_t const & embed_t;)    \
0506                                                                                \
0507       protected:                                                               \
0508                                                                                \
0509         BOOST_SPIRIT_RP_EMIT(MV_NONSTATIC,mbrs,BOOST_PP_EMPTY)                 \
0510                                                                                \
0511         __rule::__expr::type::embed_t __parser;                                \
0512                                                                                \
0513       public:                                                                  \
0514                                                                                \
0515         explicit name_t (BOOST_SPIRIT_RP_EMIT(PM_OPAQUE_CTOR_PARAMS,pars,-))   \
0516           : BOOST_SPIRIT_RP_EMIT(MV_CTOR_INIT_LIST,mbrs,-)                     \
0517             BOOST_PP_COMMA_IF(nm) __parser(x)                                  \
0518         { }                                                                    \
0519                                                                                \
0520         name_t(name_t const & that)                                            \
0521           : BOOST_SPIRIT_RP_EMIT(MV_CTOR_COPY_INIT_LIST,mbrs,that)             \
0522             BOOST_PP_COMMA_IF(nm) __parser(that.__parser)                      \
0523         { }                                                                    \
0524                                                                                \
0525         template<typename Scanner> struct result                               \
0526         {                                                                      \
0527           typedef typename ::BOOST_SPIRIT_CLASSIC_NS::parser_result<                     \
0528                                    __rule::__expr::type, Scanner>::type type;  \
0529         };                                                                     \
0530                                                                                \
0531         template<typename Scanner>                                             \
0532         typename ::BOOST_SPIRIT_CLASSIC_NS::parser_result<self_t, Scanner>::type         \
0533         parse(Scanner const & s) const { return __parser.parse(s); }           \
0534       };                                                                       \
0535                                                                                \
0536       BOOST_PP_IF(np,BOOST_SPIRIT_RP_GEN_OPAQUE,BOOST_SPIRIT_RP_GLOB_OPAQUE)   \
0537                                                          (name,name_t,np,pars)
0538 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
0539 // RP_AP_HANDLER
0540 //
0541 // Part of the rule parser definition for handling action placeholders
0542 #   define BOOST_SPIRIT_RP_AP_HANDLER(name_t,np,acts,na,ns)                    \
0543       private:                                                                 \
0544         template<typename A> struct __rebound_1st                              \
0545         {                                                                      \
0546           typedef name_t < void BOOST_PP_ENUM_TRAILING_PARAMS(np,__T) ,        \
0547             typename ns ::action_concatenator<__A0,A>::type                    \
0548             BOOST_PP_COMMA_IF(BOOST_PP_DEC(na))                                \
0549             BOOST_PP_ENUM_SHIFTED_PARAMS(na,__A)                               \
0550           > type;                                                              \
0551         };                                                                     \
0552                                                                                \
0553         template<typename X> struct __rebound                                  \
0554         {                                                                      \
0555           typedef name_t <                                                     \
0556             void BOOST_PP_ENUM_TRAILING_PARAMS(np,__T)                         \
0557             BOOST_SPIRIT_RP_EMIT(AP_REBOUND_TPL_ARGS,acts,X)                   \
0558           > type;                                                              \
0559         };                                                                     \
0560       public:                                                                  \
0561         template<typename A>                                                   \
0562         typename __rebound_1st<A>::type const operator[](A const & a) const    \
0563         {                                                                      \
0564           return typename __rebound_1st<A>::type (                             \
0565             BOOST_PP_ENUM_PARAMS(np,__p) BOOST_PP_COMMA_IF(np)                 \
0566             ns ::concatenate_actions(__a0,a)                                   \
0567             BOOST_PP_COMMA_IF(BOOST_PP_DEC(na))                                \
0568             BOOST_PP_ENUM_SHIFTED_PARAMS(na,__a) );                            \
0569         }                                                                      \
0570         template<class PH, ns ::action_chain_mode M, typename A>               \
0571         typename __rebound< ns ::action_chain<PH,M,A> >::type const            \
0572         operator[]( ns ::action_chain<PH,M,A> const & x) const                 \
0573         {                                                                      \
0574           return typename __rebound< ns ::action_chain<PH,M,A> >::type (       \
0575             BOOST_PP_ENUM_PARAMS(np,__p) BOOST_PP_COMMA_IF(np)                 \
0576             BOOST_SPIRIT_RP_EMIT(AP_REBOUND_ARGS,acts,x) );                    \
0577         }                                                                      \
0578         template<class Head, class Tail>                                       \
0579         typename __rebound< ns ::action_chains<Head,Tail> >::type const        \
0580         operator[]( ns ::action_chains<Head,Tail> const & x) const             \
0581         {                                                                      \
0582           return typename __rebound< ns ::action_chains<Head,Tail> >::type (   \
0583             BOOST_PP_ENUM_PARAMS(np,__p) BOOST_PP_COMMA_IF(np)                 \
0584             BOOST_SPIRIT_RP_EMIT(AP_REBOUND_ARGS,acts,x) );                    \
0585         }
0586 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
0587 // RP_AP_EXTRA_MBRS
0588 //
0589 // Extra members we need for rebinding if there are action placeholders
0590 #   define BOOST_SPIRIT_RP_AP_EXTRA_MBRS(np,na)                                \
0591       private:                                                                 \
0592         BOOST_PP_REPEAT(np,BOOST_SPIRIT_RP_PM_MBRS,-)                          \
0593         BOOST_PP_REPEAT(na,BOOST_SPIRIT_RP_AP_MBRS,-)
0594 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
0595 // RP_PM_MBRS
0596 //
0597 // Member variables to remember parameters if there are action placeholder
0598 #   define BOOST_SPIRIT_RP_PM_MBRS(z,i,d) __T ## i __p ## i ;
0599 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
0600 // RP_AP_MBRS
0601 //
0602 // Member variables to remember action placeholder substitutes
0603 #   define BOOST_SPIRIT_RP_AP_MBRS(z,i,d) __A ## i __a ## i ;
0604 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
0605 // RP_CTOR
0606 //
0607 // Expands to a fragment of a constructor (parameters or init-list)
0608 #   define BOOST_SPIRIT_RP_CTOR(what,pars,np,acts)                             \
0609       BOOST_SPIRIT_RP_EMIT(PM_CTOR_ ## what,pars,__T)                          \
0610       BOOST_SPIRIT_RP_EMIT(AP_CTOR_ ## what,acts,np)
0611 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
0612 // RP_CTOR_COMMA
0613 //
0614 // RP_CTOR with a trailing comma
0615 #   define BOOST_SPIRIT_RP_CTOR_COMMA(what,pars,np,acts)                       \
0616       BOOST_SPIRIT_RP_CTOR(what,pars,np,acts) ,
0617 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
0618 // RP_TPL_PARAMS
0619 //
0620 // Expands to the template parameters or arguments of the rule parser template
0621 #   define BOOST_SPIRIT_RP_TPL_PARAMS(pars,acts,prefix,defaults)               \
0622       prefix ## Dummy                                                          \
0623       BOOST_SPIRIT_RP_EMIT(PM_TEMPLATE_PARAMS,pars,prefix ## T)                \
0624       BOOST_SPIRIT_RP_EMIT(AP_TEMPLATE_PARAMS,acts,(prefix ## A,defaults))
0625 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
0626 // RP_GEN_FUNC
0627 //
0628 // Generator function
0629 #   define BOOST_SPIRIT_RP_GEN_FUNC(name,name_t,np,na)                         \
0630       template< BOOST_PP_ENUM_PARAMS(np,typename T) >                          \
0631       inline name_t < void BOOST_PP_ENUM_TRAILING_PARAMS(np,T) >               \
0632       name( BOOST_PP_ENUM_BINARY_PARAMS(np,T, const & p) )                     \
0633       { return name_t < void BOOST_PP_ENUM_TRAILING_PARAMS(np,T) >             \
0634                  (BOOST_PP_ENUM_PARAMS(np,p) BOOST_PP_ENUM_TRAILING_PARAMS(na, \
0635                 ::BOOST_SPIRIT_CLASSIC_NS::type_of::nop_functor() BOOST_PP_INTERCEPT) ); \
0636       }
0637 // RP_GEN_OPAQUE
0638 //
0639 // non-templated version for opaque rule parsers.
0640 #   define BOOST_SPIRIT_RP_GEN_OPAQUE(name,name_t,np,pars)                     \
0641       inline name_t name( BOOST_SPIRIT_RP_EMIT(PM_OPAQUE_GEN_PARAMS,pars,p))   \
0642       { return name_t (BOOST_PP_ENUM_PARAMS(np,p)); }
0643 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
0644 // RP_GLOB_VAR
0645 //
0646 // Global variable -- used instead of the generator function if there are no
0647 // parameters
0648 #   define BOOST_SPIRIT_RP_GLOB_VAR(name,name_t,np,na)                         \
0649       static name_t <void> const name = name_t <void>(BOOST_PP_ENUM_PARAMS(na, \
0650                 ::BOOST_SPIRIT_CLASSIC_NS::type_of::nop_functor() BOOST_PP_INTERCEPT) );
0651 
0652 // RP_GLOB_OPAQUE
0653 //
0654 // non-templated version for opaque rule parsers.
0655 #   define BOOST_SPIRIT_RP_GLOB_OPAQUE(name,name_t,np,pars)                    \
0656       static name_t const name = name_t () ;
0657 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
0658 // PP_EMIT operations (fragment emittion based on array input)
0659 
0660 // - - Namespace handling
0661 
0662 // NS_OPEN
0663 #   define BOOST_SPIRIT_RP__NS_OPEN(r,data,i,elem)                             \
0664       namespace BOOST_SPIRIT_RP_OPTIONAL(elem) {
0665 
0666 // NS_QUALIFY
0667 #   define BOOST_SPIRIT_RP__NS_QUALIFY(r,data,i,elem)                          \
0668       BOOST_SPIRIT_RP_OPTIONAL(elem ::)
0669 
0670 // NS_CLOSE
0671 #   define BOOST_SPIRIT_RP__NS_CLOSE(r,data,i,elem) }
0672 
0673 // - - Parameter handling
0674 
0675 // PM_STATIC
0676 #   define BOOST_SPIRIT_RP__PM_STATIC(r,data,i,elem)                           \
0677       static typename ::boost::call_traits< data ## i >::reference elem ;
0678 
0679 // PM_CTOR_PARAMS
0680 #   define BOOST_SPIRIT_RP__PM_CTOR_PARAMS(r,data,i,elem)                      \
0681       BOOST_PP_COMMA_IF(i)                                                     \
0682       typename ::boost::call_traits< data ## i >::param_type elem
0683 
0684 // PM_CTOR_ARGS
0685 #   define BOOST_SPIRIT_RP__PM_CTOR_ARGS(r,data,i,elem)                        \
0686       BOOST_PP_COMMA_IF(i) elem
0687 
0688 // PM_CTOR_INIT_LIST
0689 #   define BOOST_SPIRIT_RP__PM_CTOR_INIT_LIST(r,data,i,elem)                   \
0690       BOOST_PP_COMMA_IF(i) __p ## i ( elem )
0691 
0692 // PM_CTOR_COPY_INIT_LIST
0693 #   define BOOST_SPIRIT_RP__PM_CTOR_COPY_INIT_LIST(r,data,i,elem)              \
0694       BOOST_PP_COMMA_IF(i) __p ## i ( that. __p ## i )
0695 
0696 
0697 // PM_TEMPLATE_PARAMS
0698 #   define BOOST_SPIRIT_RP__PM_TEMPLATE_PARAMS(r,data,i,elem) , data ## i
0699 
0700 // - strictly typed parameters of the opaque rule_parser
0701 
0702 // PM_OPAQUE_STATIC
0703 #   define BOOST_SPIRIT_RP__PM_OPAQUE_STATIC(r,data,i,elem)                    \
0704       static ::boost::call_traits<                                             \
0705           BOOST_SPIRIT_RP_TYPE(BOOST_PP_TUPLE_ELEM(2,0,elem))                  \
0706         >::reference BOOST_PP_TUPLE_ELEM(2,1,elem) ;
0707 
0708 // PM_OPAQUE_CTOR_PARAMS
0709 #   define BOOST_SPIRIT_RP__PM_OPAQUE_CTOR_PARAMS(r,data,i,elem)               \
0710       BOOST_PP_COMMA_IF(i) ::boost::call_traits<                               \
0711           BOOST_SPIRIT_RP_TYPE(BOOST_PP_TUPLE_ELEM(2,0,elem))                  \
0712         >::param_type BOOST_PP_TUPLE_ELEM(2,1,elem)
0713 
0714 // PM_OPAQUE_GEN_PARAMS
0715 #   define BOOST_SPIRIT_RP__PM_OPAQUE_GEN_PARAMS(r,data,i,elem)                \
0716       BOOST_PP_COMMA_IF(i) ::boost::call_traits<                               \
0717           BOOST_SPIRIT_RP_TYPE(BOOST_PP_TUPLE_ELEM(2,0,elem))                  \
0718         >::param_type data ## i
0719 
0720 // - - Member variable handling
0721 
0722 // MV_NONSTATIC
0723 #   define BOOST_SPIRIT_RP__MV_NONSTATIC(r,data,i,elem)                        \
0724       data() BOOST_SPIRIT_RP_TYPE(BOOST_PP_TUPLE_ELEM(3,0,elem))               \
0725         BOOST_PP_TUPLE_ELEM(3,1,elem) ;
0726 
0727 // MV_STATIC
0728 #   define BOOST_SPIRIT_RP__MV_STATIC(r,data,i,elem)                           \
0729       static data() ::boost::call_traits<                                      \
0730             data() BOOST_SPIRIT_RP_TYPE(BOOST_PP_TUPLE_ELEM(3,0,elem))         \
0731         >::reference BOOST_PP_TUPLE_ELEM(3,1,elem) ;
0732 
0733 // MV_CTOR_INIT_LIST
0734 #   define BOOST_SPIRIT_RP__MV_CTOR_INIT_LIST(r,data,i,elem)                   \
0735       BOOST_PP_COMMA_IF(i)                                                     \
0736       BOOST_PP_TUPLE_ELEM(3,1,elem) BOOST_PP_TUPLE_ELEM(3,2,elem)
0737 
0738 // MV_CTOR_COPY_INIT_LIST
0739 #   define BOOST_SPIRIT_RP__MV_CTOR_COPY_INIT_LIST(r,data,i,elem)              \
0740       BOOST_PP_COMMA_IF(i)                                                     \
0741       BOOST_PP_TUPLE_ELEM(3,1,elem) (data . BOOST_PP_TUPLE_ELEM(3,1,elem))
0742 
0743 // - - Action placeholder handling
0744 
0745 // AP_STATIC
0746 #   define BOOST_SPIRIT_RP__AP_STATIC(r,data,i,elem) static __A ## i & elem ;
0747 
0748 // AP_CTOR_PARAMS
0749 #   define BOOST_SPIRIT_RP__AP_CTOR_PARAMS(r,data,i,elem)                      \
0750       BOOST_SPIRIT_RP_COMMA_IF_OR(data,i)                                      \
0751       typename ::boost::call_traits< __A ## i >::param_type elem
0752 
0753 // AP_CTOR_ARGS
0754 #   define BOOST_SPIRIT_RP__AP_CTOR_ARGS(r,data,i,elem)                        \
0755       BOOST_SPIRIT_RP_COMMA_IF_OR(data,i) elem
0756 
0757 // AP_CTOR_INIT_LIST
0758 #   define BOOST_SPIRIT_RP__AP_CTOR_INIT_LIST(r,data,i,elem)                   \
0759       BOOST_SPIRIT_RP_COMMA_IF_OR(data,i) __a ## i ( elem )
0760 
0761 // AP_CTOR_COPY_INIT_LIST
0762 #   define BOOST_SPIRIT_RP__AP_CTOR_COPY_INIT_LIST(r,data,i,elem)              \
0763       BOOST_SPIRIT_RP_COMMA_IF_OR(data,i) __a ## i ( that. __a ## i )
0764 
0765 // AP_TEMPLATE_PARAMS
0766 #   define BOOST_SPIRIT_RP__AP_TEMPLATE_PARAMS(r,data,i,elem)                  \
0767       , BOOST_PP_CAT(BOOST_PP_TUPLE_ELEM(2,0,data),i)                          \
0768       BOOST_PP_EXPR_IIF(BOOST_PP_TUPLE_ELEM(2,1,data),                         \
0769           = ::BOOST_SPIRIT_CLASSIC_NS::type_of::nop_functor)
0770 
0771 // AP_REBOUND_ARGS
0772 #   define BOOST_SPIRIT_RP__AP_REBOUND_ARGS(r,data,i,elem)                     \
0773       BOOST_PP_COMMA_IF(i)                                                     \
0774       ::BOOST_SPIRIT_CLASSIC_NS::type_of::get_placeholdee< __action_placeholder:: elem > \
0775                                                            ( __a ## i , data )
0776 
0777 // AP_REBOUND_TPL_ARGS
0778 #   define BOOST_SPIRIT_RP__AP_REBOUND_TPL_ARGS(r,data,i,elem)                 \
0779       , typename ::BOOST_SPIRIT_CLASSIC_NS::type_of::placeholdee<                        \
0780                   __action_placeholder:: elem , __A ## i, data >::type
0781 
0782 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
0783 // PP_EMIT
0784 //
0785 // Performs one of the operations in the above section on an optional array.
0786 //
0787 #   define BOOST_SPIRIT_RP_EMIT(op, array, data)                               \
0788       BOOST_SPIRIT_RP_ARRAY_FOR_EACH_I(BOOST_SPIRIT_RP__ ## op,data,array)
0789 // --- --- - - --- - - --- - - - - --- - - - - - - - - - - - - - - - - - - - - -
0790 // RP_ARRAY_FOR_EACH_I
0791 //
0792 // Iterates an optional array. That is you can pass e.g.'-' or 'none' to denote
0793 // emptiness.
0794 #   define BOOST_SPIRIT_RP_ARRAY_FOR_EACH_I(macro,data,optional_array)         \
0795       BOOST_PP_IIF(BOOST_PP_IS_BINARY(optional_array),                         \
0796                    BOOST_SPIRIT_RP_ARRAY_FOR_EACH_I_IMPL,                      \
0797                    BOOST_PP_TUPLE_EAT(3))(macro,data,optional_array)
0798 
0799 // RP_ARRAY_FOR_EACH_I_IMPL
0800 #   define BOOST_SPIRIT_RP_ARRAY_FOR_EACH_I_IMPL(macro,data,array)             \
0801       BOOST_SPIRIT_RP_IF(BOOST_PP_ARRAY_SIZE(array),PP_SEQ_FOR_EACH_I,3)       \
0802         (macro,data, BOOST_SPIRIT_RP_IF(BOOST_PP_ARRAY_SIZE(array),            \
0803                                         PP_TUPLE_TO_SEQ,2) array)
0804 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
0805 // RP_ARRAY_SIZE
0806 //
0807 // Expands to the size of an "optional array".
0808 //
0809 // Examples:
0810 //
0811 //   BOOST_SPIRIT_RP_ARRAY_SIZE( (2,(a,b)) ) // 2
0812 //   BOOST_SPIRIT_RP_ARRAY_SIZE( (0,()) )    // 0
0813 //   BOOST_SPIRIT_RP_ARRAY_SIZE( none )      // 0
0814 //   BOOST_SPIRIT_RP_ARRAY_SIZE( - )         // 0
0815 //
0816 #   define BOOST_SPIRIT_RP_ARRAY_SIZE(optional_array)                          \
0817       BOOST_PP_IIF(BOOST_PP_IS_BINARY(optional_array),                         \
0818                    BOOST_PP_ARRAY_SIZE, 0 BOOST_PP_TUPLE_EAT(1))(optional_array)
0819 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
0820 // RP_OPTIONAL
0821 //
0822 // Expands to nothing if the argument is parenthesized.
0823 //
0824 // Examples:
0825 //
0826 //   BOOST_SPIRIT_RP_OPTIONAL( foobar ) // foobar
0827 //   BOOST_SPIRIT_RP_OPTIONAL( (none) ) // evaluates to nothing
0828 //
0829 #   define BOOST_SPIRIT_RP_OPTIONAL(elem)                                      \
0830       BOOST_PP_EXPR_IIF(BOOST_PP_COMPL(BOOST_PP_IS_UNARY(elem)),elem)
0831 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
0832 // RP_COMMA_IF_OR
0833 //
0834 // Expands to nothing if both arguments are zero, otherwise expands to a comma.
0835 //
0836 #   define BOOST_SPIRIT_RP_COMMA_IF_OR(a,b)                                    \
0837       BOOST_PP_IIF(BOOST_PP_OR(a,b),BOOST_PP_COMMA,BOOST_PP_EMPTY)()
0838 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
0839 // RP_IF
0840 //
0841 //   BOOST_SPIRIT_RP_IF(cond,name,arity)
0842 //
0843 // is equivalent to:
0844 //
0845 //   BOOST_PP_IF(cond,BOOST_name,BOOST_PP_TUPLE_EAT(arity))
0846 //
0847 #   define BOOST_SPIRIT_RP_IF(cond,name,arity) \
0848       BOOST_PP_IF(cond,BOOST_ ## name,BOOST_PP_TUPLE_EAT(arity))
0849 
0850 //------------------------------------------------------------------------------
0851 // Wrapper and gernator function to embed a parser by reference
0852 //------------------------------------------------------------------------------
0853 
0854 namespace boost { namespace spirit {
0855 
0856 BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN
0857 
0858   // Wrapper to embed a parser by reference
0859 
0860   template<class P> class parser_reference
0861     : public parser< parser_reference<P> >
0862   {
0863     P const & ref_that;
0864   public:
0865     parser_reference(P & that)
0866     // we allow implicit conversion but forbid temporaries.
0867       : ref_that(that)
0868     { }
0869 
0870     typedef parser_reference<P>           self_t;
0871     typedef self_t const &                embed_t;
0872     typedef typename P::parser_category_t parser_category_t;
0873 
0874     template<typename ScannerT> struct result
0875     { typedef typename P::BOOST_NESTED_TEMPLATE result<ScannerT>::type type; };
0876 
0877     template<typename ScannerT>
0878     typename result<ScannerT>::type
0879     parse(ScannerT const & scan) const
0880     { return this->ref_that.parse(scan); }
0881   };
0882 
0883   template<class P> parser_reference<P>
0884   embed_by_reference(::BOOST_SPIRIT_CLASSIC_NS::parser<P> & p)
0885   { return p; }
0886 
0887 BOOST_SPIRIT_CLASSIC_NAMESPACE_END
0888 
0889 } } // namespace ::BOOST_SPIRIT_CLASSIC_NS
0890 
0891 BOOST_TYPEOF_REGISTER_TEMPLATE(BOOST_SPIRIT_CLASSIC_NS::parser_reference, 1)
0892 
0893 //------------------------------------------------------------------------------
0894 // Expression templates for action placeholders.
0895 //------------------------------------------------------------------------------
0896 
0897 namespace boost { namespace spirit {
0898 
0899 BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN
0900 
0901 namespace type_of {
0902 
0903   // No-operation functor
0904 
0905   struct nop_functor
0906   {
0907     template<typename T>
0908     bool operator()(T const &) const
0909     { return false; }
0910     template<typename T, typename U>
0911     bool operator()(T const &, U const &) const
0912     { return false; }
0913 
0914     typedef bool result_type;
0915   };
0916 
0917   // Composite action
0918 
0919   template<typename Action1, typename Action2>
0920   class composite_action
0921   {
0922     Action1 fnc_a1;
0923     Action2 fnc_a2;
0924   public:
0925     composite_action(Action1 const & a1, Action2 const & a2)
0926       : fnc_a1(a1), fnc_a2(a2)
0927     { }
0928 
0929     template<typename T>
0930     void operator()(T const & inp) const
0931     { fnc_a1(inp); fnc_a2(inp); }
0932 
0933     template<typename T, typename U>
0934     void operator()(T const & inp1, U const inp2) const
0935     { fnc_a1(inp1, inp2); fnc_a2(inp1, inp2); }
0936   };
0937 
0938   // Action concatenation (and optimize away nop_functorS)
0939 
0940   template<typename Action1, typename Action2>
0941   struct action_concatenator
0942   {
0943     typedef composite_action<Action1,Action2> type;
0944 
0945     static type concatenate(Action1 const & a1, Action2 const & a2)
0946     { return composite_action<Action1,Action2>(a1,a2); }
0947   };
0948   template<typename Action> struct action_concatenator<nop_functor, Action>
0949   {
0950     typedef Action type;
0951 
0952     static type concatenate(nop_functor const &, Action const & a)
0953     { return a; }
0954   };
0955   template<typename Action> struct action_concatenator<Action, nop_functor>
0956   {
0957     typedef Action type;
0958 
0959     static type concatenate(Action const & a, nop_functor const &)
0960     { return a; }
0961   };
0962   template<> struct action_concatenator<nop_functor, nop_functor>
0963   {
0964     typedef nop_functor type;
0965 
0966     static type concatenate(nop_functor const &, nop_functor const &)
0967     { return nop_functor(); }
0968   };
0969 
0970   template<typename Action1, typename Action2>
0971   typename action_concatenator<Action1,Action2>::type
0972   concatenate_actions(Action1 const & a1, Action2 const & a2)
0973   {
0974     return action_concatenator<Action1,Action2>::concatenate(a1,a2);
0975   }
0976 
0977   // Action chains
0978 
0979   enum action_chain_mode { replace, append };
0980 
0981   template<class Placeholder, action_chain_mode Mode, typename Action>
0982   class action_chain
0983   {
0984     Action fnc_action;
0985   public:
0986     action_chain(Action const & a)
0987       : fnc_action(a)
0988     { }
0989 
0990     typedef Action action_type;
0991 
0992     Action const & action() const { return fnc_action; }
0993   };
0994 
0995   // This operator adds actions to an action chain definition
0996   template<class PH, action_chain_mode M, typename A1, typename A2>
0997   action_chain<PH, M, typename action_concatenator<A1,A2>::type>
0998   operator, (action_chain<PH,M,A1> const & chain, A2 const & a)
0999   {
1000     return action_chain<PH,M,typename action_concatenator<A1,A2>::type>
1001         ( concatenate_actions(chain.action(), a) );
1002   }
1003 
1004   // Expression template for multiple action chain assignments
1005   template<class ChainOrChains, class LastChain>
1006   class action_chains
1007   {
1008     ChainOrChains obj_head;
1009     LastChain     obj_tail;
1010   public:
1011     action_chains(ChainOrChains const & head, LastChain const & tail)
1012       : obj_head(head), obj_tail(tail)
1013     { }
1014 
1015     typedef ChainOrChains head_type;
1016     typedef LastChain     tail_type;
1017 
1018     head_type const & head() const { return obj_head; }
1019     tail_type const & tail() const { return obj_tail; }
1020   };
1021 
1022   // Action chain concatenation
1023   template<class Head, class Tail>
1024   action_chains<Head,Tail> make_chain(Head const & h, Tail const & t)
1025   { return action_chains<Head,Tail>(h,t); }
1026 
1027   template<class PH1, action_chain_mode M1, typename A1,
1028            class PH2, action_chain_mode M2, typename A2>
1029   action_chains< action_chain<PH1,M1,A1>, action_chain<PH2,M2,A2> >
1030   operator, (action_chain<PH1,M1,A1> const & h,
1031              action_chain<PH2,M2,A2> const & t)
1032   { return make_chain(h,t); }
1033 
1034   template<class Head, class Tail,class PH, action_chain_mode M, typename A>
1035   action_chains< action_chains<Head,Tail>, action_chain<PH,M,A> >
1036   operator, (action_chains<Head,Tail> const & h, action_chain<PH,M,A> const & t)
1037   { return make_chain(h,t); }
1038 
1039 
1040   // Extract the (maybe composite) action associated with an action
1041   // placeholders from the chains with a fold algorithm.
1042   template<class Placeholder, typename StartAction, class NewChainOrChains>
1043   struct placeholdee
1044   {
1045     typedef StartAction type;
1046 
1047     static type get(StartAction const & a, NewChainOrChains const &)
1048     { return a; }
1049   };
1050 
1051   template<class Placeholder, // <-- non-deduced
1052            typename StartAction, class NewChainOrChains>
1053   typename placeholdee<Placeholder,StartAction,NewChainOrChains>::type
1054   get_placeholdee(StartAction const & a, NewChainOrChains const & c)
1055   { return placeholdee<Placeholder,StartAction,NewChainOrChains>::get(a,c); }
1056 
1057   template<class Placeholder, typename StartAction, class Head, class Tail>
1058   struct placeholdee
1059             < Placeholder, StartAction, action_chains<Head,Tail> >
1060   {
1061     typedef typename placeholdee<Placeholder,
1062       typename placeholdee<Placeholder,StartAction,Head>::type, Tail >::type
1063     type;
1064 
1065     static type get(StartAction const & a, action_chains<Head,Tail> const & c)
1066     {
1067       return get_placeholdee<Placeholder>(
1068         get_placeholdee<Placeholder>(a,c.head()), c.tail() );
1069     }
1070   };
1071 
1072   template<class Placeholder, typename StartAction, typename A>
1073   struct placeholdee
1074             < Placeholder, StartAction, action_chain<Placeholder,replace,A> >
1075   {
1076     typedef A type;
1077 
1078     static type get(StartAction const &,
1079                     action_chain<Placeholder,replace,A> const & c)
1080     { return c.action(); }
1081   };
1082 
1083   template<class Placeholder, typename StartAction, typename A>
1084   struct placeholdee
1085             < Placeholder, StartAction, action_chain<Placeholder,append,A> >
1086   {
1087     typedef typename action_concatenator<StartAction,A>::type type;
1088 
1089     static type get(StartAction const & a,
1090                     action_chain<Placeholder,append,A> const & c)
1091     { return concatenate_actions(a,c.action()); }
1092   };
1093 
1094 }
1095 
1096 BOOST_SPIRIT_CLASSIC_NAMESPACE_END
1097 
1098 } } // namespace ::BOOST_SPIRIT_CLASSIC_NS::type_of
1099 
1100 BOOST_TYPEOF_REGISTER_TYPE(BOOST_SPIRIT_CLASSIC_NS::type_of::nop_functor)
1101 BOOST_TYPEOF_REGISTER_TEMPLATE(BOOST_SPIRIT_CLASSIC_NS::type_of::composite_action,2)
1102 
1103 //------------------------------------------------------------------------------
1104 // Misc.utilities
1105 //------------------------------------------------------------------------------
1106 
1107 namespace boost { namespace spirit {
1108 
1109 BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN
1110 
1111 namespace type_of {
1112 
1113   // Utility function to create a dependency to a template argument.
1114 
1115   template<typename T, typename X>
1116   X const & depend_on_type(X const & x)
1117   { return x; }
1118 
1119   // Utility to allow use parenthesized type expressions with commas inside
1120   // as a type within macros. Thanks to Dave Abrahams for telling me this nice
1121   // trick.
1122 
1123   #define BOOST_SPIRIT_RP_TYPE(x) \
1124     ::BOOST_SPIRIT_CLASSIC_NS::type_of::remove_special_fptr \
1125       < ::BOOST_SPIRIT_CLASSIC_NS::type_of::special_result & (*) x >::type
1126 
1127   struct special_result;
1128 
1129   template<typename T> struct remove_special_fptr { };
1130   template<typename T> struct remove_special_fptr< special_result & (*)(T) >
1131   { typedef T type; };
1132 
1133 }
1134 
1135 BOOST_SPIRIT_CLASSIC_NAMESPACE_END
1136 
1137 } } // namespace ::BOOST_SPIRIT_CLASSIC_NS::type_of
1138 
1139 //------------------------------------------------------------------------------
1140 #endif
1141 //------------------------------------------------------------------------------
1142