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

📄 utilities.ipp

📁 著名的Parser库Spirit在VC6上的Port
💻 IPP
📖 第 1 页 / 共 2 页
字号:
/*=============================================================================
    Utilities

    Spirit V1.3.1
    Copyright (c) 2001, Daniel Nuffer
    Copyright (c) 2001, Hartmut Kaiser

    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_UTILITIES_IPP
#define SPIRIT_UTILITIES_IPP

///////////////////////////////////////////////////////////////////////////////
#include <cassert>

#include "boost/spirit/MSVC/utilities.hpp"

///////////////////////////////////////////////////////////////////////////////
//
//  These seem to creep in as macros when using gcc 2.95.2.
//
///////////////////////////////////////////////////////////////////////////////
#ifdef __GNUC__
#ifdef isdigit
#undef isdigit
#endif

#ifdef isxdigit
#undef isxdigit
#endif
#endif

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

/*=============================================================================

    Escape char parser classes implementation [Dan Nuffer]

=============================================================================*/

//
//  escape_char_action class implementation
//
///////////////////////////////////////////////////////////////////////////////
template <typename ParserT, typename ActionT, unsigned long Flags>
inline escape_char_action<ParserT, ActionT, Flags>::escape_char_action(
    ParserT const& subject, ActionT const& actor_)
:   unary<ParserT>(subject),
    actor(actor_) {}


/*=============================================================================

    confix parsers implementation [Hartmut Kaiser]

=============================================================================*/

///////////////////////////////////////////////////////////////////////////////
//
//  confix_parser class implementation
//
///////////////////////////////////////////////////////////////////////////////
namespace impl {

///////////////////////////////////////////////////////////////////////////////
// There is nothing special for plain_parser_category types as ExprT.
    template <>
    struct confix_parser_type<nested, plain_parser_category> {

        template <
            typename IteratorT, typename ThisT,
            typename OpenT, typename ExprT, typename CloseT
        >
        static match
        parse(
            IteratorT& first, IteratorT const& last, ThisT const& this_,
            OpenT const& open, ExprT const& expr, CloseT const& close)
        {
            return (open >> *(this_ | expr - close) >> close).parse(
                    first, last);
        }

    };

    template <>
    struct confix_parser_type<non_nested, plain_parser_category> {

        template <
            typename IteratorT, typename ThisT,
            typename OpenT, typename ExprT, typename CloseT
        >
        static match
        parse(
            IteratorT& first, IteratorT const& last, ThisT const& /*this_*/,
            OpenT const& open, ExprT const& expr, CloseT const& close)
        {
            return (open >> *(expr - close) >> close).parse(first, last);
        }

    };

///////////////////////////////////////////////////////////////////////////////
// action_parser_category types as ExprT require some special handling
    template <>
    struct confix_parser_type<nested, action_parser_category> {

        template <
            typename IteratorT, typename ThisT,
            typename OpenT, typename ExprT, typename CloseT
        >
        static match
        parse(
            IteratorT& first, IteratorT const& last, ThisT const& this_,
            OpenT const& open, ExprT const& expr, CloseT const& close)
        {
            return (
                    open
                >>  (*(this_ | expr.subject() - close))[expr.predicate()]
                >>  close
            ).parse(first, last);
        }

    };

    template <>
    struct confix_parser_type<non_nested, action_parser_category> {

        template <
            typename IteratorT, typename ThisT,
            typename OpenT, typename ExprT, typename CloseT
        >
        static match
        parse(
            IteratorT& first, IteratorT const& last, ThisT const& /*this_*/,
            OpenT const& open, ExprT const& expr, CloseT const& close)
        {
            return (
                    open
                >>  (*(expr.subject() - close))[expr.predicate()]
                >>  close
            ).parse(first, last);
        }

    };
}   // end of namespace impl

///////////////////////////////////////////////////////////////////////////////
//
// confix_parser class implementation
//
///////////////////////////////////////////////////////////////////////////////
template <
    typename OpenT, typename ExprT, typename CloseT,
    typename NestedT, typename CategoryT
>
inline confix_parser<OpenT, ExprT, CloseT, NestedT, CategoryT>::confix_parser(
    OpenT const &open_, ExprT const &expr_, CloseT const &close_) :
    open(open_), expr(expr_), close(close_)
{
}
///////////////////////////////////////////////////////////////////////////////
//
//  Generic generator function for creation of concrete confix parsers
//
///////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////
// 
//  list_action class implementation
//
///////////////////////////////////////////////////////////////////////////////
template <typename ParserT, typename ActionT>
inline 
list_action<ParserT, ActionT>::list_action(
    ParserT const& subject, ActionT const& actor_) :
    unary<ParserT>(subject), actor(actor_)
{
}


///////////////////////////////////////////////////////////////////////////////
// 
//  list_action_iterator class implementation
//
///////////////////////////////////////////////////////////////////////////////
template <typename ParserT, typename IteratorT, typename BaseT>
inline 
list_action_iterator<ParserT, IteratorT, BaseT>::list_action_iterator() :
    parser(0), current(0), last(0), end_marker(true), saw_oneitem(false)
{
}

template <typename ParserT, typename IteratorT, typename BaseT>
inline 
list_action_iterator<ParserT, IteratorT, BaseT>::list_action_iterator(
    ParserT const *parser_, IteratorT &first_, IteratorT const &last_) :
    parser(parser_), current(first_), last(last_), end_marker(true), 
    saw_oneitem(false)
{
    end_marker = !read(true);     // get the first value
}

///////////////////////////////////////////////////////////////////////////////
// functions required for input iterators
template <typename ParserT, typename IteratorT, typename BaseT>
inline BaseT const &
list_action_iterator<ParserT, IteratorT, BaseT>::operator* () const 
{ 
    return value; 
}

template <typename ParserT, typename IteratorT, typename BaseT>
inline list_action_iterator<ParserT, IteratorT, BaseT> &
list_action_iterator<ParserT, IteratorT, BaseT>::operator++() 
{ 
    read(); 
    return *this; 
}

⌨️ 快捷键说明

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