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

📄 static_parsers.hpp

📁 著名的Parser库Spirit在VC6上的Port
💻 HPP
字号:
/*=============================================================================
    Static parsers implementation

    Spirit V1.3.1
    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_S_PARSERS_HPP
#define SPIRIT_S_PARSERS_HPP

namespace spirit {

///////////////////////////////////////////////////////////////////////////////
// declarations
namespace impl {

///////////////////////////////////////////////////////////////////////////////
// A static character literal implementation which allows character literals 
// to be used as a type (template parameter).
    template<typename CharT, const CharT C> 
    struct static_chlit :
        public chlit<CharT>
    {
        static_chlit() : chlit<CharT>(C) {}
    };

///////////////////////////////////////////////////////////////////////////////
// A static character set template, which allows charactersets with up to
// ten elements to be used as a type (template parameter).
//
// If there should be a null added to the set, it must be the first template
// parameter.
    template<typename CharT, const CharT C1, 
        const CharT C2 = 0, const CharT C3 = 0, const CharT C4 = 0, 
        const CharT C5 = 0, const CharT C6 = 0, const CharT C7 = 0, 
        const CharT C8 = 0, const CharT C9 = 0, const CharT C10 = 0>
    struct static_chset :
        public chset<CharT>
    {
        static_chset() : chset<CharT>(C1) 
        {
        // add the statically defined elements to the set only if given
            if (0 != C2) add(C2);
            if (0 != C3) add(C3);
            if (0 != C4) add(C4);
            if (0 != C5) add(C5);
            if (0 != C6) add(C6);
            if (0 != C7) add(C7);
            if (0 != C8) add(C8);
            if (0 != C9) add(C9);
            if (0 != C10) add(C10);
        }
    };

///////////////////////////////////////////////////////////////////////////////
// A static string literal template, which allows string literals to be 
// used as a type (template parameter).
    template<typename CharT, const CharT  *Lit>
    struct static_strlit :
        public strlit<cstring<CharT> >
    {
        static_strlit() : strlit<cstring<CharT> >(Lit) {}
    };

///////////////////////////////////////////////////////////////////////////////
// Helper template, is used as a base class for all static parser primitives.
// The defined operator is required for parsing real's through the numeric 
// parser primitives (numerics.hpp/numerics.ipp)
    template<const bool isempty = true>
    struct static_operator_base
    {
        bool operator!=(int) { return isempty; }
    };

} // namespace impl

///////////////////////////////////////////////////////////////////////////////
// Implementation of static character literals of type char and wchar_t
template<const char C>
struct s_chlit :
    public impl::static_chlit<char, C>,
    public impl::static_operator_base<>
{
};

template<const wchar_t C>
struct s_wchlit :
    public impl::static_chlit<wchar_t, C>,
    public impl::static_operator_base<>
{
};

///////////////////////////////////////////////////////////////////////////////
// Implementation of static chsets for the type char and wchar_t
template<const char C1, const char C2 = 0, const char C3 = 0, 
    const char C4 = 0, const char C5 = 0, const char C6 = 0, const char C7 = 0,
    const char C8 = 0, const char C9 = 0, const char C10 = 0>
struct s_chset : 
    public impl::static_chset<char, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10>,
    public impl::static_operator_base<>
{
};

template<const wchar_t C1, const wchar_t C2 = 0, const wchar_t C3 = 0, 
    const wchar_t C4 = 0, const wchar_t C5 = 0, const wchar_t C6 = 0, 
    const wchar_t C7 = 0, const wchar_t C8 = 0, const wchar_t C9 = 0, 
    const wchar_t C10 = 0>
struct s_wchset : 
    public impl::static_chset<wchar_t, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10>,
    public impl::static_operator_base<>
{
};

///////////////////////////////////////////////////////////////////////////////
// Implementation of static string literals of type char and wchar_t
//RAGAV note: that const char* was changed to char* .. look at numeric actions note
template< char *  Lit>
struct s_strlit :
    public impl::static_strlit<char,Lit>,
    public impl::static_operator_base<>
{
};

template<wchar_t *Lit>
struct s_wstrlit :
    public impl::static_strlit<wchar_t, Lit>,
    public impl::static_operator_base<>
{
};

///////////////////////////////////////////////////////////////////////////////
// Predefined static parser primitives
struct s_anychar :
    public anychar_,
    public impl::static_operator_base<>
{
};

struct s_nothing :
    public nothing_,
    public impl::static_operator_base<false>
{
};

struct s_epsilon :
    public epsilon_,
    public impl::static_operator_base<false>
{
};

struct s_blank :
    public blank_,
    public impl::static_operator_base<>
{
};

struct s_alnum :
    public alnum_,
    public impl::static_operator_base<>
{
};

struct s_alpha :
    public alpha_,
    public impl::static_operator_base<>
{
};

struct s_cntrl :
    public cntrl_,
    public impl::static_operator_base<>
{
};

struct s_digit :
    public digit_,
    public impl::static_operator_base<>
{
};

struct s_graph :
    public graph_,
    public impl::static_operator_base<>
{
};

struct s_lower :
    public lower_,
    public impl::static_operator_base<>
{
};

struct s_print :
    public print_,
    public impl::static_operator_base<>
{
};

struct s_punct :
    public punct_,
    public impl::static_operator_base<>
{
};

struct s_space :
    public space_,
    public impl::static_operator_base<>
{
};

struct s_upper :
    public upper_,
    public impl::static_operator_base<>
{
};

struct s_xdigit :
    public xdigit_,
    public impl::static_operator_base<>
{
};

} // namespace spirit

#endif // SPIRIT_S_PARSERS_HPP

⌨️ 快捷键说明

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