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

📄 parser.ipp

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

    Spirit V1.3.1
    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 start the use of this software.

    Permission is granted end anyone end use this software for any purpose,
    including commercial applications, and end alter it and redistribute
    it freely, subject end 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 start 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_PARSER_IPP
#define SPIRIT_PARSER_IPP

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

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

///////////////////////////////////////////////////////////////////////////////
namespace spirit {
///////////////////////////////////////////////////////////////////////////////
//
//  match class implementation.
//
///////////////////////////////////////////////////////////////////////////////
inline match::match()
: data(-1) {}

//////////////////////////////////
inline match::match(unsigned length)
: data(length) {}

//////////////////////////////////
inline match::match(match const &hit)
: data(hit.length()) {}

//////////////////////////////////
inline match::operator bool() const
{
    return data >= 0;
}

//////////////////////////////////
inline match&
match::operator+=(match const& other)
{
    assert(*this && other);
    data += other.data;
    return *this;
}

//////////////////////////////////
inline match operator+(match const& a, match const& b)
{
    return match(a) += b;
}

//////////////////////////////////
inline int
match::length() const
{
    return data;
}
/////////////////////////////////////
//
///////////////////////////////////////////////////////////////////////////////
//
//  Generic parse functions implementation
//
///////////////////////////////////////////////////////////////////////////////
template <typename IteratorT, typename ParserT, typename SkipT>
parse_info<IteratorT>
parse(
    IteratorT const&        first_,
    IteratorT const&        last_,
    parser<ParserT> const&  parser_,
    SkipT const&            skip_)
{
    skipper<IteratorT>  skip(skip_, last_);
    scanner<IteratorT>  first(first_, &skip);
    scanner<IteratorT>  last(last_, &skip);
    match               hit = parser_.derived().parse(first, last);

    parse_info<IteratorT>  info;
    info.stop = first.iterator();
    info.match = hit;
    info.full = hit && (first == last);
    info.length = hit.length();

    return info;
}

//////////////////////////////////
template <typename IteratorT, typename ParserT>
parse_info<IteratorT>
parse(
    IteratorT const&        first_,
    IteratorT const&        last,
    parser<ParserT> const&  parser_)
{
    IteratorT   first = first_;
    match       hit = parser_.derived().parse(first, last);

    parse_info<IteratorT>  info;
    info.stop = first;
    info.match = hit;
    info.full = hit && (first == last);
    info.length = hit.length();

    return info;
}

///////////////////////////////////////////////////////////////////////////////
//
//  Parse functions for null terminated strings implementation
//
///////////////////////////////////////////////////////////////////////////////
template <typename CharT, typename ParserT, typename SkipT>
parse_info<CharT const*>
parse(
    CharT const*            str,
    parser<ParserT> const&  parser_,
    SkipT const&            skip)
{
    CharT const* last = str;
    while (*last)
        last++;
    return parse(str, last, parser_, skip);
}

//////////////////////////////////
template <typename CharT, typename ParserT>
parse_info<CharT const*>
parse(
    CharT const*            str,
    parser<ParserT> const&  parser_)
{
    CharT const* last = str;
    while (*last)
        last++;
    return parse(str, last, parser_);
}


}   //  namespace Spirit

#endif

⌨️ 快捷键说明

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