|
// 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; p[i] != NULL; ++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; p[i] != NULL; ++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
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.