// Copyright (c) 2001-2011 Hartmut Kaiser // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #ifndef BOOST_SPIRIT_LEX_LEXER_ACTION_HPP #define BOOST_SPIRIT_LEX_LEXER_ACTION_HPP #if defined(_MSC_VER) #pragma once #endif #include #include #include #include #include #include #include /////////////////////////////////////////////////////////////////////////////// namespace boost { namespace spirit { namespace lex { /////////////////////////////////////////////////////////////////////////// template struct action : unary_lexer > { action(Subject const& subject, Action f) : subject(subject), f(f) {} template void collect(LexerDef& lexdef, String const& state , String const& targetstate) const { // collect the token definition information for the token_def // this action is attached to subject.collect(lexdef, state, targetstate); } template void add_actions(LexerDef& lexdef) const { // call to add all actions attached further down the hierarchy subject.add_actions(lexdef); // retrieve the id of the associated token_def and register the // given semantic action with the lexer instance lexdef.add_action(subject.unique_id(), subject.state(), f); } Subject subject; Action f; // silence MSVC warning C4512: assignment operator could not be generated BOOST_DELETED_FUNCTION(action& operator= (action const&)) }; }}} /////////////////////////////////////////////////////////////////////////////// namespace boost { namespace spirit { /////////////////////////////////////////////////////////////////////////// // Karma action meta-compiler template <> struct make_component { template struct result; template struct result { typedef typename remove_const::type subject_type; typedef typename remove_const::type action_type; typedef lex::action type; }; template typename result::type operator()(Elements const& elements, unused_type) const { typename result::type result(elements.car, elements.cdr.car); return result; } }; }} #endif