Back to home page

EIC code displayed by LXR

 
 

    


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

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 #ifndef BOOST_SPIRIT_LEX_LEXER_ACTION_HPP
0007 #define BOOST_SPIRIT_LEX_LEXER_ACTION_HPP
0008 
0009 #if defined(_MSC_VER)
0010 #pragma once
0011 #endif
0012 
0013 #include <boost/spirit/home/lex/meta_compiler.hpp>
0014 #include <boost/spirit/home/lex/lexer_type.hpp>
0015 #include <boost/spirit/home/lex/argument.hpp>
0016 #include <boost/spirit/home/lex/lexer/support_functions.hpp>
0017 #include <boost/mpl/if.hpp>
0018 #include <boost/type_traits/remove_const.hpp>
0019 #include <boost/type_traits/is_same.hpp>
0020 
0021 ///////////////////////////////////////////////////////////////////////////////
0022 namespace boost { namespace spirit { namespace lex
0023 {
0024     ///////////////////////////////////////////////////////////////////////////
0025     template <typename Subject, typename Action>
0026     struct action : unary_lexer<action<Subject, Action> >
0027     {
0028         action(Subject const& subject, Action f)
0029           : subject(subject), f(f) {}
0030 
0031         template <typename LexerDef, typename String>
0032         void collect(LexerDef& lexdef, String const& state
0033           , String const& targetstate) const
0034         {
0035             // collect the token definition information for the token_def 
0036             // this action is attached to
0037             subject.collect(lexdef, state, targetstate);
0038         }
0039 
0040         template <typename LexerDef>
0041         void add_actions(LexerDef& lexdef) const
0042         {
0043             // call to add all actions attached further down the hierarchy 
0044             subject.add_actions(lexdef);
0045 
0046             // retrieve the id of the associated token_def and register the 
0047             // given semantic action with the lexer instance
0048             lexdef.add_action(subject.unique_id(), subject.state(), f);
0049         }
0050 
0051         Subject subject;
0052         Action f;
0053     };
0054 
0055 }}}
0056 
0057 ///////////////////////////////////////////////////////////////////////////////
0058 namespace boost { namespace spirit
0059 {
0060     ///////////////////////////////////////////////////////////////////////////
0061     // Karma action meta-compiler
0062     template <>
0063     struct make_component<lex::domain, tag::action>
0064     {
0065         template <typename Sig>
0066         struct result;
0067 
0068         template <typename This, typename Elements, typename Modifiers>
0069         struct result<This(Elements, Modifiers)>
0070         {
0071             typedef typename
0072                 remove_const<typename Elements::car_type>::type
0073             subject_type;
0074 
0075             typedef typename
0076                 remove_const<typename Elements::cdr_type::car_type>::type
0077             action_type;
0078 
0079             typedef lex::action<subject_type, action_type> type;
0080         };
0081 
0082         template <typename Elements>
0083         typename result<make_component(Elements, unused_type)>::type
0084         operator()(Elements const& elements, unused_type) const
0085         {
0086             typename result<make_component(Elements, unused_type)>::type
0087                 result(elements.car, elements.cdr.car);
0088             return result;
0089         }
0090     };
0091 }}
0092 
0093 #endif