[r1]: trunk / Soul / Soul.Parsing / Primitive.hpp  Maximize  Restore  History

Download this file

116 lines (99 with data), 3.3 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*========================================================================
Copyright (c) 2011 Seppo Laakko
http://sourceforge.net/projects/soulparsing/
Distributed under the GNU General Public License, version 3 (GPLv3).
(See accompanying LICENSE.txt or http://www.gnu.org/licenses/gpl.html)
========================================================================*/
#ifndef SOUL_PARSING_PRIMITIVE_INCLUDED
#define SOUL_PARSING_PRIMITIVE_INCLUDED
#include <Soul.Parsing/Parser.hpp>
#include <Soul.Parsing/Scanner.hpp>
#include <limits.h>
#include <bitset>
namespace Soul { namespace Parsing {
class CharParser : public Parser
{
public:
CharParser(Char c_): Parser("\"" + String(1, c_) + "\""), c(c_) {}
Char GetChar() const { return c; }
virtual Match Parse(Scanner& scanner, ObjectStack& stack);
virtual void Accept(Visitor& visitor);
private:
Char c;
};
class StringParser : public Parser
{
public:
StringParser(const String& s_): Parser("\"" + s_ + "\""), s(s_) {}
const String& GetString() const { return s; }
virtual Match Parse(Scanner& scanner, ObjectStack& stack);
virtual void Accept(Visitor& visitor);
private:
String s;
};
class CharSetParser : public Parser
{
public:
CharSetParser(const String& s_): Parser("[" + s_ + "}"), s(s_), inverse(false) { InitBits(); }
CharSetParser(const String& s_, bool inverse_): Parser("[" + s_ + "}"), s(s_), inverse(inverse_) { InitBits(); }
const String& Set() const { return s; }
bool Inverse() const { return inverse; }
virtual Match Parse(Scanner& scanner, ObjectStack& stack);
virtual void Accept(Visitor& visitor);
private:
String s;
bool inverse;
std::bitset<UCHAR_MAX + 1> bits;
void InitBits();
};
class EmptyParser : public Parser
{
public:
EmptyParser(): Parser("") {}
virtual Match Parse(Scanner& scanner, ObjectStack& stack);
virtual void Accept(Visitor& visitor);
};
class SpaceParser : public Parser
{
public:
SpaceParser(): Parser("space") {}
virtual Match Parse(Scanner& scanner, ObjectStack& stack);
virtual void Accept(Visitor& visitor);
};
class LetterParser : public Parser
{
public:
LetterParser(): Parser("letter") {}
virtual Match Parse(Scanner& scanner, ObjectStack& stack);
virtual void Accept(Visitor& visitor);
};
class DigitParser : public Parser
{
public:
DigitParser(): Parser("digit") {}
virtual Match Parse(Scanner& scanner, ObjectStack& stack);
virtual void Accept(Visitor& visitor);
};
class HexDigitParser : public Parser
{
public:
HexDigitParser(): Parser("hexdigit") {}
virtual Match Parse(Scanner& scanner, ObjectStack& stack);
virtual void Accept(Visitor& visitor);
};
class PunctuationParser : public Parser
{
public:
PunctuationParser(): Parser("punctuation") {}
virtual Match Parse(Scanner& scanner, ObjectStack& stack);
virtual void Accept(Visitor& visitor);
};
class AnyCharParser : public Parser
{
public:
AnyCharParser(): Parser("anychar") {}
virtual Match Parse(Scanner& scanner, ObjectStack& stack);
virtual void Accept(Visitor& visitor);
};
} } // namespace Soul.Parsing
#endif // SOUL_PARSING_PRIMITIVE_INCLUDED

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks