⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 actions.ipp

📁 著名的Parser库Spirit在VC6上的Port
💻 IPP
字号:
/*=============================================================================
    Semantic actions

    Spirit V1.2
    Copyright (c) 2001, Joel de Guzman

    This software is provided 'as-is', without any express or implied
    warranty. In no event will the copyright holder be held liable for
    any damages arising from the use of this software.

    Permission is granted to anyone to use this software for any purpose,
    including commercial applications, and to alter it and redistribute
    it freely, subject to the following restrictions:

    1.  The origin of this software must not be misrepresented; you must
        not claim that you wrote the original software. If you use this
        software in a product, an acknowledgment in the product documentation
        would be appreciated but is not required.

    2.  Altered source versions must be plainly marked as such, and must
        not be misrepresented as being the original software.

    3.  This notice may not be removed or altered from any source
        distribution.

    Acknowledgements:

        Special thanks to Dan Nuffer, John (EBo) David, Chris Uzdavinis,
        and Doug Gregor. These people are most instrumental in steering
        Spirit in the right direction.

        Special thanks also to people who have contributed to the code base
        and sample code, ported Spirit to various platforms and compilers,
        gave suggestions, reported and provided bug fixes. Alexander
        Hirner, Andy Elvey, Bogdan Kushnir, Brett Calcott, Bruce Florman,
        Changzhe Han, Colin McPhail, Hakki Dogusan, Jan Bares, Joseph
        Smith, Martijn W. van der Lee, Raghavendra Satish, Remi Delcos, Tom
        Spilman, Vladimir Prus, W. Scott Dillman, David A. Greene, Bob
        Bailey, Hartmut Kaiser.

        Finally special thanks also to people who gave feedback and
        valuable comments, particularly members of Spirit's Source Forge
        mailing list and boost.org.

    URL: http://spirit.sourceforge.net/

=============================================================================*/
#ifndef SPIRIT_ACTION_IPP
#define SPIRIT_ACTION_IPP

///////////////////////////////////////////////////////////////////////////////

#include "boost/spirit/actions.hpp"
#include "boost/spirit/iterators.hpp"
#include "boost/spirit/rule.hpp"
#include "boost/spirit/spirit_fwd.hpp"

///////////////////////////////////////////////////////////////////////////////
namespace spirit {

///////////////////////////////////////////////////////////////////////////////
//
//  action class implementation
//
///////////////////////////////////////////////////////////////////////////////
template <typename ParserT, typename ActionT, typename DerivedT>
inline base_action<ParserT, ActionT, DerivedT>::base_action(
    ParserT const&  parser,
    ActionT const&   actor_)
:   unary<ParserT>(parser),
    actor(actor_)
{
#if defined(SPIRIT_DEBUG)
    debug.name (parser.debug.name());
#endif 
}

//////////////////////////////////
template <typename ParserT, typename ActionT, typename DerivedT>
template <typename IteratorT>
inline match
base_action<ParserT, ActionT, DerivedT>
    ::parse(IteratorT& first, IteratorT const& last) const
{
    typedef impl::strip_scanner<IteratorT> strip_scanner;
    typename strip_scanner::iterator_type
        begin = strip_scanner::get(first);

    match hit = this->subject().parse(first, last);

    if (hit)
        actor(begin, strip_scanner::get(first));
    return hit;
}

//////////////////////////////////
template <typename ParserT, typename ActionT, typename DerivedT>
template <typename IteratorT, typename MatchTraitsT>
inline typename MatchTraitsT::match_t
base_action<ParserT, ActionT, DerivedT>
    ::ast_parse(IteratorT& first, IteratorT const& last, 
            MatchTraitsT const& mt) const
{
    typedef impl::strip_scanner<IteratorT> strip_scanner;
    typename strip_scanner::iterator_type
        begin = strip_scanner::get(first);

    typename MatchTraitsT::match_t hit = 
        this->subject().ast_parse(first, last, mt);

    if (hit)
        actor(begin, strip_scanner::get(first));
    return hit;
}

template <typename ParserT, typename ActionT>
inline action<ParserT, ActionT>
        ::action(ParserT const&  parser, ActionT const& actor_)
    : base_action<ParserT, ActionT, action<ParserT, ActionT> >(parser, actor_)
{
}

///////////////////////////////////////////////////////////////////////////////
//
//  reference_wrapper class implementation
//
///////////////////////////////////////////////////////////////////////////////
template <typename DerivedT, typename ElementT, typename ActualT>
reference_access<DerivedT, ElementT, ActualT>::operator ElementT&() const
{
    return static_cast<DerivedT const*>(this)->get();
}

//////////////////////////////////
template <typename DerivedT, typename ElementT, typename ActualT>
reference_access<DerivedT, ElementT, ActualT>::operator ActualT&() const
{
    return static_cast<DerivedT const*>(this)->get();
}

//////////////////////////////////
template <typename DerivedT, typename ElementT>
reference_access<DerivedT, ElementT, ElementT>::operator ElementT&() const
{
    return static_cast<DerivedT const*>(this)->get();
}

//////////////////////////////////
template<class T>
inline reference_wrapper<T> const
ref(T& t)
{
    return reference_wrapper<T>(t); //  Generate a reference_wrapper object.
}

//////////////////////////////////
template<typename T>
inline reference_wrapper<T>::reference_wrapper(T& ref_)
:   ref(ref_) {}

//////////////////////////////////
template<typename T>
template <typename TX>
inline void
reference_wrapper<T>::operator()(TX const& val) const
{
    ref = val;
}

//////////////////////////////////
template<typename T>
template <typename IteratorT>
inline void
reference_wrapper<T>::operator()(IteratorT const& begin, 
        IteratorT const& end) const
{
    //  Create an actual_type object given
    //  begin/end iterators.
    actual_type temp(begin, end);

    //  Swap the contents of our newly created
    //  object and the one we are referencing.
    actual_type& aref = ref;
    aref.swap(temp);
}

///////////////////////////////////////////////////////////////////////////////
}   //  namespace Spirit

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -