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