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

📄 rules.hpp

📁 yard lib, template for regular rule
💻 HPP
字号:

// released into the public domain
// by Christopher Diggins 2004
// http://www.cdiggins.com

#ifndef RULES_HPP_INCLUDED
#define RULES_HPP_INCLUDED

#include "re_ops.hpp"

namespace yard {
    template < char C >
    struct MatchChar {
        static bool Accept(ParserInputStream < char > & stream) {
            return (stream.AdvancePast(C));
        }
    };

    template < char C0, char C1 >
    struct MatchCharRange {
        static bool Accept(ParserInputStream < char > & stream) {
            char ch = stream.GetElem();
            if ((ch >= C0) && (ch <= C1)) {
                stream.GotoNext();
                return true;
            }
            return false;
        }
    };

    template < typename String_T >
    struct MatchString {
        static bool Accept(ParserInputStream < char > & stream) {

            char const * p = String_T::GetString();
            for (int i = 0; i != strlen(p); ++i) {
                if (stream.AtEnd()) return false;
                char ch = stream.GetElem();
                stream.GotoNext();
                if (ch != p[i]) return false;
            }

            return true;
        }
    };

    template < typename String_T > // expected to be lower-case
    struct MatchStringNoCase {
        static bool Accept(ParserInputStream < char > & stream) {
            char const * p = String_T::GetString();
            for (int i = 0; i != strlen(p); ++i) {
                if (stream.AtEnd()) return false;
                char ch = stream.GetElem();
                stream.GotoNext();
                if (ch < 96) ch += 32;
                if (ch != p[i]) return false;
            }
            return true;
        }
    };


    struct MatchWSpace : public re_or < re_or < MatchChar < ' ' >, MatchChar < '\t' > >, re_or < MatchChar < '\n' >,
       MatchChar < '\r' > > > {
    };


    typedef MatchCharRange < 'a', 'z' > MatchLowerCaseLetter;
    typedef MatchCharRange < 'A', 'Z' > MatchUpperCaseLetter;
    typedef MatchCharRange < '0', '9' > MatchNumber;

    typedef re_or < MatchLowerCaseLetter, MatchUpperCaseLetter > MatchLetter;
    typedef re_or < MatchLetter, MatchChar < '\'' > > MatchWordChar;
    typedef re_plus < MatchWordChar > MatchWord;
    typedef re_or < MatchLetter, MatchChar < '_' > > MatchIdentFirstChar;
    typedef re_or < MatchIdentFirstChar, MatchNumber > MatchIdentOtherChar;
    typedef re_and < MatchIdentFirstChar, re_star < MatchIdentOtherChar > > MatchIdent;
}

#endif // #ifndef RULES_HPP_INCLUDED

⌨️ 快捷键说明

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