1
2
3
4
5
6 #ifndef SNG2HTML_SNG2HTML_SYMBOL_INCLUDED
7 #define SNG2HTML_SNG2HTML_SYMBOL_INCLUDED
8 #include <sng2html/sng2html/Visitor.hpp>
9 #include <string>
10 #include <vector>
11
12 namespace sng2html { namespace sng2html {
13
14 class Symbol
15 {
16 public:
17 Symbol();
18 virtual ~Symbol();
19 virtual void Accept(Visitor& visitor) = 0;
20 virtual bool IsClass() const { return false; }
21 virtual bool IsChar() const { return false; }
22 virtual bool IsAny() const { return false; }
23 virtual bool IsRange() const { return false; }
24 const std::string& Name() const { return name; }
25 private:
26 std::string name;
27 };
28
29 class Char : public Symbol
30 {
31 public:
32 Char(char32_t chr_);
33 bool IsChar() const override { return true; }
34 void Accept(Visitor& visitor) override;
35 char32_t Chr() const { return chr; }
36 private:
37 char32_t chr;
38 };
39
40 class Any : public Symbol
41 {
42 public:
43 Any();
44 void Accept(Visitor& visitor) override;
45 bool IsAny() const override { return true; }
46 };
47
48 class Range : public Symbol
49 {
50 public:
51 Range(char32_t start_, char32_t end_);
52 void Accept(Visitor& visitor) override;
53 bool IsRange() const override { return true; }
54 bool IsEmpty() const { return start > end; }
55 char32_t Start() const { return start; }
56 char32_t End() const { return end; }
57 private:
58 char32_t start;
59 char32_t end;
60 };
61
62 inline bool operator==(const Range& left, const Range& right)
63 {
64 return left.Start() == right.Start() && left.End() == right.End();
65 }
66
67 inline bool operator<(const Range& left, const Range& right)
68 {
69 if (left.Start() < right.Start()) return true;
70 if (left.Start() > right.Start()) return false;
71 return left.End() < right.End();
72 }
73
74 class Class : public Symbol
75 {
76 public:
77 Class(int index_);
78 void Accept(Visitor& visitor) override;
79 bool IsClass() const override { return true; }
80 bool Inverse() const { return inverse; }
81 void SetInverse() { inverse = true; }
82 const std::std::vector<Symbol*>&Symbols() const{returnsymbols;}
83 void AddSymbol(Symbol* symbol);
84 int Index() const { return index; }
85 bool IsEmpty() const { return symbols.empty(); }
86 private:
87 int index;
88 bool inverse;
89 std::vector<Symbol*> symbols;
90 };
91
92 } }
93
94 #endif // SNG2HTML_SNG2HTML_SYMBOL_INCLUDED