Chris@16: // Copyright (c) 2001-2011 Hartmut Kaiser Chris@16: // Copyright (c) 2001-2011 Joel de Guzman 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(BOOST_SPIRIT_KARMA_META_COMPILER_JANUARY_13_2009_1011AM) Chris@16: #define BOOST_SPIRIT_KARMA_META_COMPILER_JANUARY_13_2009_1011AM 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: namespace boost { namespace spirit Chris@16: { Chris@16: template Chris@16: struct use_terminal >::type> // enables generators Chris@16: : mpl::true_ {}; Chris@16: Chris@16: namespace karma Chris@16: { Chris@16: template Chris@16: struct make_primitive // by default, return it as-is Chris@16: { Chris@16: typedef T result_type; Chris@16: Chris@16: template Chris@16: T_& operator()(T_& val, unused_type) const Chris@16: { Chris@16: return val; Chris@16: } Chris@16: Chris@16: template Chris@16: T_ const& operator()(T_ const& val, unused_type) const Chris@16: { Chris@16: return val; Chris@16: } Chris@16: }; Chris@16: Chris@16: template Chris@16: struct make_composite; Chris@16: Chris@16: template Chris@16: struct make_directive Chris@16: { Chris@16: typedef Body result_type; Chris@16: result_type operator()(unused_type, Body const& body, unused_type) const Chris@16: { Chris@16: return body; // By default, a directive simply returns its subject Chris@16: } Chris@16: }; Chris@16: } Chris@16: Chris@16: // Karma primitive 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 karma::make_primitive< Chris@16: typename remove_const::type Chris@16: , typename remove_reference::type Chris@16: >::result_type type; Chris@16: }; Chris@16: Chris@16: template Chris@16: typename result::type Chris@16: operator()(Elements const& elements, Modifiers const& modifiers) const Chris@16: { Chris@16: typedef typename remove_const::type term; Chris@16: return karma::make_primitive()(elements.car, modifiers); Chris@16: } Chris@16: }; Chris@16: Chris@16: // Karma composite 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: karma::make_composite::type>::result_type Chris@16: type; Chris@16: }; Chris@16: Chris@16: template Chris@16: typename result::type Chris@16: operator()(Elements const& elements, Modifiers const& modifiers) const Chris@16: { Chris@16: return karma::make_composite()( Chris@16: elements, modifiers); Chris@16: } Chris@16: }; Chris@16: Chris@16: // Karma function 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: karma::make_composite< Chris@16: typename remove_const::type, Chris@16: typename Elements::cdr_type, Chris@16: typename remove_reference::type Chris@16: >::result_type Chris@16: type; Chris@16: }; Chris@16: Chris@16: template Chris@16: typename result::type Chris@16: operator()(Elements const& elements, Modifiers const& modifiers) const Chris@16: { Chris@16: return karma::make_composite< Chris@16: typename remove_const::type, Chris@16: typename Elements::cdr_type, Chris@16: Modifiers>()(elements.cdr, modifiers); Chris@16: } Chris@16: }; Chris@16: Chris@16: // Karma directive 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: karma::make_directive< Chris@16: typename remove_const::type, Chris@16: typename remove_const::type, Chris@16: typename remove_reference::type Chris@16: >::result_type Chris@16: type; Chris@16: }; Chris@16: Chris@16: template Chris@16: typename result::type Chris@16: operator()(Elements const& elements, Modifiers const& modifiers) const Chris@16: { Chris@16: return karma::make_directive< Chris@16: typename remove_const::type, Chris@16: typename remove_const::type, Chris@16: Modifiers>()(elements.car, elements.cdr.car, modifiers); Chris@16: } Chris@16: }; Chris@16: Chris@16: }} Chris@16: Chris@16: #endif