Back to home page

EIC code displayed by LXR

 
 

    


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

0001 //  Copyright (c) 2001-2011 Hartmut Kaiser
0002 // 
0003 //  Distributed under the Boost Software License, Version 1.0. (See accompanying 
0004 //  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0005 
0006 #if !defined(BOOST_SPIRIT_LEX_LEXER_SEMANTIC_ACTION_DATA_JUN_10_2009_0417PM)
0007 #define BOOST_SPIRIT_LEX_LEXER_SEMANTIC_ACTION_DATA_JUN_10_2009_0417PM
0008 
0009 #if defined(_MSC_VER)
0010 #pragma once
0011 #endif
0012 
0013 #include <boost/spirit/home/lex/lexer/pass_flags.hpp>
0014 #include <boost/mpl/bool.hpp>
0015 #include <boost/function.hpp>
0016 #include <vector>
0017 
0018 namespace boost { namespace spirit { namespace lex { namespace lexertl
0019 { 
0020     namespace detail
0021     {
0022         ///////////////////////////////////////////////////////////////////////
0023         template <typename Iterator, typename SupportsState, typename Data>
0024         struct semantic_actions;
0025 
0026         // This specialization of semantic_actions will be used if the token
0027         // type (lexer definition) does not support states, which simplifies 
0028         // the data structures used to store the semantic action function 
0029         // objects.
0030         template <typename Iterator, typename Data>
0031         struct semantic_actions<Iterator, mpl::false_, Data>
0032         {
0033             typedef void functor_type(Iterator&, Iterator&
0034               , BOOST_SCOPED_ENUM(pass_flags)&, std::size_t&, Data&);
0035             typedef boost::function<functor_type> functor_wrapper_type;
0036 
0037             // add a semantic action function object
0038             template <typename F>
0039             void add_action(std::size_t unique_id, std::size_t, F act) 
0040             {
0041                 if (actions_.size() <= unique_id)
0042                     actions_.resize(unique_id + 1); 
0043 
0044                 actions_[unique_id] = act;
0045             }
0046 
0047             // try to invoke a semantic action for the given token (unique_id)
0048             BOOST_SCOPED_ENUM(pass_flags) invoke_actions(std::size_t /*state*/
0049               , std::size_t& id, std::size_t unique_id, Iterator& end
0050               , Data& data) const
0051             {
0052                 // if there is nothing to invoke, continue with 'match'
0053                 if (unique_id >= actions_.size() || !actions_[unique_id]) 
0054                     return pass_flags::pass_normal;
0055 
0056                 // Note: all arguments might be changed by the invoked semantic 
0057                 //       action
0058                 BOOST_SCOPED_ENUM(pass_flags) match = pass_flags::pass_normal;
0059                 actions_[unique_id](data.get_first(), end, match, id, data);
0060                 return match;
0061             }
0062 
0063             std::vector<functor_wrapper_type> actions_;
0064         }; 
0065 
0066         // This specialization of semantic_actions will be used if the token
0067         // type (lexer definition) needs to support states, resulting in a more
0068         // complex data structure needed for storing the semantic action 
0069         // function objects.
0070         template <typename Iterator, typename Data>
0071         struct semantic_actions<Iterator, mpl::true_, Data>
0072         {
0073             typedef void functor_type(Iterator&, Iterator&
0074               , BOOST_SCOPED_ENUM(pass_flags)&, std::size_t&, Data&);
0075             typedef boost::function<functor_type> functor_wrapper_type;
0076 
0077             // add a semantic action function object
0078             template <typename F>
0079             void add_action(std::size_t unique_id, std::size_t state, F act) 
0080             {
0081                 if (actions_.size() <= state)
0082                     actions_.resize(state + 1); 
0083 
0084                 std::vector<functor_wrapper_type>& actions (actions_[state]);
0085                 if (actions.size() <= unique_id)
0086                     actions.resize(unique_id + 1); 
0087 
0088                 actions[unique_id] = act;
0089             }
0090 
0091             // try to invoke a semantic action for the given token (unique_id)
0092             BOOST_SCOPED_ENUM(pass_flags) invoke_actions(std::size_t state
0093               , std::size_t& id, std::size_t unique_id, Iterator& end
0094               , Data& data) const
0095             {
0096                 // if there is no action defined for this state, return match
0097                 if (state >= actions_.size())
0098                     return pass_flags::pass_normal;
0099 
0100                 // if there is nothing to invoke, continue with 'match'
0101                 std::vector<functor_wrapper_type> const& actions = actions_[state];
0102                 if (unique_id >= actions.size() || !actions[unique_id]) 
0103                     return pass_flags::pass_normal;
0104 
0105                 // set token value 
0106                 data.set_end(end);
0107 
0108                 // Note: all arguments might be changed by the invoked semantic 
0109                 //       action
0110                 BOOST_SCOPED_ENUM(pass_flags) match = pass_flags::pass_normal;
0111                 actions[unique_id](data.get_first(), end, match, id, data);
0112                 return match;
0113             }
0114 
0115             std::vector<std::vector<functor_wrapper_type> > actions_;
0116         }; 
0117     }
0118 
0119 }}}}
0120 
0121 #endif