Diff of /trunk/Soul/Soul.Parsing/Primitive.hpp [000000] .. [r1]  Maximize  Restore

Switch to side-by-side view

--- a
+++ b/trunk/Soul/Soul.Parsing/Primitive.hpp
@@ -0,0 +1,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