Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/boost/spirit/home/lex/argument.hpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 //  Copyright (c) 2001-2011 Hartmut Kaiser
0002 //  Copyright (c) 2001-2011 Joel de Guzman
0003 //  Copyright (c)      2010 Bryce Lelbach
0004 //  Copyright (c)      2011 Thomas Heller
0005 // 
0006 //  Distributed under the Boost Software License, Version 1.0. (See accompanying 
0007 //  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0008 
0009 #if !defined(BOOST_SPIRIT_LEX_ARGUMENT_JUNE_07_2009_1106AM)
0010 #define BOOST_SPIRIT_LEX_ARGUMENT_JUNE_07_2009_1106AM
0011 
0012 #if defined(_MSC_VER)
0013 #pragma once
0014 #endif
0015 
0016 #include <boost/spirit/home/support/string_traits.hpp>
0017 #include <boost/spirit/home/lex/argument_phoenix.hpp>
0018 #include <boost/fusion/include/at.hpp>
0019 #include <boost/mpl/at.hpp>
0020 #include <boost/mpl/bool.hpp>
0021 #include <boost/phoenix/core/actor.hpp>
0022 #include <boost/phoenix/core/argument.hpp>
0023 #include <boost/type_traits/is_same.hpp>
0024 #include <boost/type_traits/remove_const.hpp>
0025 #include <boost/type_traits/remove_reference.hpp>
0026 
0027 ///////////////////////////////////////////////////////////////////////////////
0028 namespace boost { namespace spirit { namespace lex
0029 {
0030     ///////////////////////////////////////////////////////////////////////////
0031     //  The state_getter is a Phoenix actor used to access the name of the 
0032     //  current lexer state by calling get_state_name() on the context (which 
0033     //  is the 5th parameter to any lexer semantic actions).
0034     //
0035     //  This Phoenix actor is invoked whenever the placeholder '_state' is used
0036     //  as a rvalue inside a lexer semantic action:
0037     //
0038     //      lex::token_def<> identifier = "[a-zA-Z_][a-zA-Z0-9_]*";
0039     //      this->self = identifier [ std::cout << _state ];
0040     //
0041     //  The example shows how to print the lexer state after matching a token
0042     //  'identifier'.
0043     struct state_getter
0044     {
0045         typedef mpl::true_ no_nullary;
0046 
0047         template <typename Env>
0048         struct result
0049         {
0050             typedef
0051                 typename remove_reference<
0052                    typename remove_const<
0053                         typename mpl::at_c<typename Env::args_type, 4>::type
0054                     >::type
0055                 >::type
0056             context_type;
0057 
0058             typedef typename context_type::state_name_type type;
0059         };
0060 
0061         template <typename Env>
0062         typename result<Env>::type
0063         eval(Env const& env) const
0064         {
0065             return fusion::at_c<4>(env.args()).get_state_name();
0066         }
0067     };
0068 
0069     ///////////////////////////////////////////////////////////////////////////
0070     //  The state_setter is a Phoenix actor used to change the name of the 
0071     //  current lexer state by calling set_state_name() on the context (which 
0072     //  is the 5th parameter to any lexer semantic actions).
0073     //
0074     //  This Phoenix actor is invoked whenever the placeholder '_state' is used
0075     //  as a lvalue inside a lexer semantic action:
0076     //
0077     //      lex::token_def<> identifier = "[a-zA-Z_][a-zA-Z0-9_]*";
0078     //      this->self = identifier [ _state = "SOME_LEXER_STATE" ];
0079     //
0080     //  The example shows how to change the lexer state after matching a token
0081     //  'identifier'.
0082     template <typename Actor>
0083     struct state_setter
0084     {
0085         typedef mpl::true_ no_nullary;
0086 
0087         template <typename Env>
0088         struct result
0089         {
0090             typedef void type;
0091         };
0092 
0093         template <typename Env>
0094         void eval(Env const& env) const
0095         {
0096             fusion::at_c<4>(env.args()).set_state_name(
0097                 traits::get_c_string(actor_.eval(env)));
0098         }
0099 
0100         state_setter(Actor const& actor)
0101           : actor_(actor) {}
0102 
0103         Actor actor_;
0104     };
0105 
0106     ///////////////////////////////////////////////////////////////////////////
0107     //  The value_getter is used to create the _val placeholder, which is a 
0108     //  Phoenix actor used to access the value of the current token.
0109     //
0110     //  This Phoenix actor is invoked whenever the placeholder '_val' is used
0111     //  as a rvalue inside a lexer semantic action:
0112     //
0113     //      lex::token_def<> identifier = "[a-zA-Z_][a-zA-Z0-9_]*";
0114     //      this->self = identifier [ std::cout << _val ];
0115     //
0116     //  The example shows how to use _val to print the identifier name (which
0117     //  is the initial token value).
0118     struct value_getter
0119     {
0120         typedef mpl::true_ no_nullary;
0121 
0122         template <typename Env>
0123         struct result
0124         {
0125             typedef
0126                 typename remove_reference<
0127                    typename remove_const<
0128                         typename mpl::at_c<typename Env::args_type, 4>::type
0129                     >::type
0130                 >::type
0131             context_type;
0132 
0133             typedef typename context_type::get_value_type type;
0134         };
0135 
0136         template <typename Env>
0137         typename result<Env>::type 
0138         eval(Env const& env) const
0139         {
0140             return fusion::at_c<4>(env.args()).get_value();
0141         }
0142     };
0143 
0144     ///////////////////////////////////////////////////////////////////////////
0145     //  The value_setter is a Phoenix actor used to change the name of the 
0146     //  current lexer state by calling set_state_name() on the context (which 
0147     //  is the 5th parameter to any lexer semantic actions).
0148     //
0149     //  This Phoenix actor is invoked whenever the placeholder '_val' is used
0150     //  as a lvalue inside a lexer semantic action:
0151     //
0152     //      lex::token_def<> identifier = "[a-zA-Z_][a-zA-Z0-9_]*";
0153     //      this->self = identifier [ _val = "identifier" ];
0154     //
0155     //  The example shows how to change the token value after matching a token
0156     //  'identifier'.
0157     template <typename Actor>
0158     struct value_setter
0159     {
0160         typedef mpl::true_ no_nullary;
0161 
0162         template <typename Env>
0163         struct result
0164         {
0165             typedef void type;
0166         };
0167 
0168         template <typename Env>
0169         void eval(Env const& env) const
0170         {
0171             fusion::at_c<4>(env.args()).set_value(actor_.eval(env));
0172         }
0173 
0174         value_setter(Actor const& actor)
0175           : actor_(actor) {}
0176 
0177         Actor actor_;
0178     };
0179 
0180     ///////////////////////////////////////////////////////////////////////////
0181     //  The eoi_getter is used to create the _eoi placeholder, which is a 
0182     //  Phoenix actor used to access the end of input iterator pointing to the 
0183     //  end of the underlying input sequence.
0184     //
0185     //  This actor is invoked whenever the placeholder '_eoi' is used in a
0186     //  lexer semantic action:
0187     //
0188     //      lex::token_def<> identifier = "[a-zA-Z_][a-zA-Z0-9_]*";
0189     //      this->self = identifier 
0190     //          [ std::cout << construct_<std::string>(_end, _eoi) ];
0191     //
0192     //  The example shows how to use _eoi to print all remaining input after
0193     //  matching a token 'identifier'.
0194     struct eoi_getter
0195     {
0196         typedef mpl::true_ no_nullary;
0197 
0198         template <typename Env>
0199         struct result
0200         {
0201             typedef
0202                 typename remove_reference<
0203                    typename remove_const<
0204                         typename mpl::at_c<typename Env::args_type, 4>::type
0205                     >::type
0206                 >::type
0207             context_type;
0208 
0209             typedef typename context_type::base_iterator_type const& type;
0210         };
0211 
0212         template <typename Env>
0213         typename result<Env>::type 
0214         eval(Env const& env) const
0215         {
0216             return fusion::at_c<4>(env.args()).get_eoi();
0217         }
0218     };
0219 
0220     ///////////////////////////////////////////////////////////////////////////
0221     // '_start' and '_end' may be used to access the start and the end of 
0222     // the matched sequence of the current token
0223     typedef phoenix::arg_names::_1_type _start_type;
0224     typedef phoenix::arg_names::_2_type _end_type;
0225 #ifndef BOOST_SPIRIT_NO_PREDEFINED_TERMINALS
0226     _start_type const _start = _start_type();
0227     _end_type const _end = _end_type();
0228 #endif
0229 
0230     // We are reusing the placeholder '_pass' to access and change the pass
0231     // status of the current match (see support/argument.hpp for its 
0232     // definition).
0233     // typedef phoenix::arg_names::_3_type _pass_type;
0234     using boost::spirit::_pass_type;
0235 #ifndef BOOST_SPIRIT_NO_PREDEFINED_TERMINALS
0236     using boost::spirit::_pass;
0237 #endif
0238 
0239     // '_tokenid' may be used to access and change the tokenid of the current 
0240     // token
0241     typedef phoenix::arg_names::_4_type _tokenid_type;
0242 #ifndef BOOST_SPIRIT_NO_PREDEFINED_TERMINALS
0243     _tokenid_type const _tokenid = _tokenid_type();
0244 #endif
0245 
0246     typedef phoenix::actor<value_context> _val_type;
0247     typedef phoenix::actor<state_context> _state_type;
0248     typedef phoenix::actor<eoi_getter> _eoi_type;
0249 #ifndef BOOST_SPIRIT_NO_PREDEFINED_TERMINALS
0250     // '_val' may be used to access and change the token value of the current
0251     // token
0252     _val_type const _val = _val_type();
0253     // _state may be used to access and change the name of the current lexer 
0254     // state
0255     _state_type const _state = _state_type();
0256     // '_eoi' may be used to access the end of input iterator of the input 
0257     // stream used by the lexer to match tokens from
0258     _eoi_type const _eoi = _eoi_type();
0259 #endif
0260 }}}
0261 
0262 
0263 #undef SPIRIT_DECLARE_ARG
0264 #endif
0265