Chris@16: // Copyright (c) 2001-2011 Hartmut Kaiser Chris@16: // Copyright (c) 2011 Thomas Heller 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_LEX_ARGUMENT_PHEONIX_MARCH_25_2011_1841PM) Chris@16: #define BOOST_SPIRIT_LEX_ARGUMENT_PHEONIX_MARCH_25_2011_1841PM Chris@16: Chris@16: #if defined(_MSC_VER) Chris@16: #pragma once Chris@16: #endif Chris@16: Chris@16: #include Chris@16: Chris@16: namespace boost { namespace spirit { namespace lex Chris@16: { Chris@16: /////////////////////////////////////////////////////////////////////////// Chris@16: // The value_context is used as a noop Phoenix actor to create the Chris@16: // placeholder '_val' (see below). It is a noop actor because it is used Chris@16: // as a placeholder only, while it is being converted either to a Chris@16: // value_getter (if used as a rvalue) or to a value_setter (if used as a Chris@16: // lvalue). The conversion is achieved by specializing and overloading a Chris@16: // couple of the Phoenix templates from the Phoenix expression composition Chris@16: // engine (see the end of this file). Chris@16: struct value_context Chris@16: { Chris@16: typedef mpl::true_ no_nullary; Chris@16: Chris@16: typedef unused_type result_type; Chris@16: Chris@16: template Chris@16: struct result Chris@16: { Chris@16: typedef unused_type type; Chris@16: }; Chris@16: Chris@16: template Chris@16: unused_type Chris@16: eval(Env const& env) const Chris@16: { Chris@16: return unused; Chris@16: } Chris@16: }; Chris@16: Chris@16: // forward declarations Chris@16: struct value_getter; Chris@16: template struct value_setter; Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////// Chris@16: // The state_context is used as a noop Phoenix actor to create the Chris@16: // placeholder '_state' (see below). It is a noop actor because it is used Chris@16: // as a placeholder only, while it is being converted either to a Chris@16: // state_getter (if used as a rvalue) or to a state_setter (if used as a Chris@16: // lvalue). The conversion is achieved by specializing and overloading a Chris@16: // couple of the Phoenix templates from the Phoenix expression composition Chris@16: // engine (see the end of this file). Chris@16: struct state_context Chris@16: { Chris@16: typedef mpl::true_ no_nullary; Chris@16: Chris@16: typedef unused_type result_type; Chris@16: Chris@16: template Chris@16: struct result Chris@16: { Chris@16: typedef unused_type type; Chris@16: }; Chris@16: Chris@16: template Chris@16: unused_type Chris@16: eval(Env const& env) const Chris@16: { Chris@16: return unused; Chris@16: } Chris@16: }; Chris@16: Chris@16: // forward declarations Chris@16: struct state_getter; Chris@16: template struct state_setter; Chris@16: struct eoi_getter; Chris@16: }}} Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: Chris@16: BOOST_PHOENIX_DEFINE_EXPRESSION( Chris@16: (boost)(spirit)(lex)(value_setter) Chris@16: , (boost::phoenix::meta_grammar) Chris@16: ) Chris@16: Chris@16: BOOST_PHOENIX_DEFINE_EXPRESSION( Chris@16: (boost)(spirit)(lex)(state_setter) Chris@16: , (boost::phoenix::meta_grammar) Chris@16: ) Chris@16: Chris@16: namespace boost { namespace phoenix Chris@16: { Chris@16: namespace result_of Chris@16: { Chris@16: template <> Chris@16: struct is_nullary > Chris@16: : mpl::false_ Chris@16: {}; Chris@16: } Chris@16: Chris@16: template Chris@16: struct is_custom_terminal: mpl::true_ {}; Chris@16: Chris@16: template Chris@16: struct custom_terminal Chris@16: : proto::call< Chris@16: v2_eval( Chris@16: proto::make Chris@16: , proto::call Chris@16: ) Chris@16: > Chris@16: {}; Chris@16: Chris@16: template Chris@16: struct is_nullary::when Chris@16: : proto::make Chris@16: {}; Chris@16: Chris@16: template Chris@16: struct default_actions::when Chris@16: : proto::call< Chris@16: v2_eval( Chris@16: proto::make< Chris@16: spirit::lex::value_setter( Chris@16: proto::_child0 Chris@16: ) Chris@16: > Chris@16: , _env Chris@16: ) Chris@16: > Chris@16: {}; Chris@16: Chris@16: template <> Chris@16: struct actor Chris@16: : boost::phoenix::actor::type> Chris@16: { Chris@16: typedef boost::phoenix::actor< Chris@16: proto::terminal::type Chris@16: > base_type; Chris@16: Chris@16: actor(base_type const & base = base_type()) Chris@16: : base_type(base) Chris@16: {} Chris@16: Chris@16: template Chris@16: typename spirit::lex::expression::value_setter< Chris@16: typename phoenix::as_actor::type>::type const Chris@16: operator=(Expr const & expr) const Chris@16: { Chris@16: return Chris@16: spirit::lex::expression::value_setter< Chris@16: typename phoenix::as_actor::type Chris@16: >::make(phoenix::as_actor::convert(expr)); Chris@16: } Chris@16: }; Chris@16: Chris@16: namespace result_of Chris@16: { Chris@16: template <> Chris@16: struct is_nullary > Chris@16: : mpl::false_ Chris@16: {}; Chris@16: } Chris@16: Chris@16: template Chris@16: struct is_custom_terminal: mpl::true_ {}; Chris@16: Chris@16: template Chris@16: struct custom_terminal Chris@16: : proto::call< Chris@16: v2_eval( Chris@16: proto::make Chris@16: , proto::call Chris@16: ) Chris@16: > Chris@16: {}; Chris@16: Chris@16: template Chris@16: struct is_nullary::when Chris@16: : proto::make Chris@16: {}; Chris@16: Chris@16: template Chris@16: struct default_actions::when Chris@16: : proto::call< Chris@16: v2_eval( Chris@16: proto::make< Chris@16: spirit::lex::state_setter( Chris@16: proto::_child0 Chris@16: ) Chris@16: > Chris@16: , _env Chris@16: ) Chris@16: > Chris@16: {}; Chris@16: Chris@16: template <> Chris@16: struct actor Chris@16: : boost::phoenix::actor::type> Chris@16: { Chris@16: typedef boost::phoenix::actor< Chris@16: proto::terminal::type Chris@16: > base_type; Chris@16: Chris@16: actor(base_type const & base = base_type()) Chris@16: : base_type(base) Chris@16: {} Chris@16: Chris@16: template Chris@16: typename spirit::lex::expression::state_setter< Chris@16: typename phoenix::as_actor::type>::type const Chris@16: operator=(Expr const & expr) const Chris@16: { Chris@16: return Chris@16: spirit::lex::expression::state_setter< Chris@16: typename phoenix::as_actor::type Chris@16: >::make(phoenix::as_actor::convert(expr)); Chris@16: } Chris@16: }; Chris@16: Chris@16: namespace result_of Chris@16: { Chris@16: template <> Chris@16: struct is_nullary > Chris@16: : mpl::false_ Chris@16: {}; Chris@16: } Chris@16: Chris@16: template Chris@16: struct is_custom_terminal: mpl::true_ {}; Chris@16: Chris@16: template Chris@16: struct custom_terminal Chris@16: : proto::call< Chris@16: v2_eval( Chris@16: proto::make Chris@16: , proto::call Chris@16: ) Chris@16: > Chris@16: {}; Chris@16: }} Chris@16: Chris@16: #endif