1
2
3
4
5
6 #ifndef SNG2HTML_SNG2HTML_REGEX_INCLUDED
7 #define SNG2HTML_SNG2HTML_REGEX_INCLUDED
8 #include <sng2html/sng2html/Symbol.hpp>
9 #include <sng2html/sng2html/Visitor.hpp>
10 #include <memory>
11
12 namespace sng2html { namespace sng2html {
13
14 class RegExpression
15 {
16 public:
17 RegExpression();
18 virtual ~RegExpression();
19 virtual void Accept(Visitor& visitor) = 0;
20 virtual bool IsCharSymbolExpr() const { return false; }
21 };
22
23 class UnaryRegExpression : public RegExpression
24 {
25 public:
26 UnaryRegExpression(RegExpression* child_);
27 RegExpression* Child() const { return child.get(); }
28 private:
29 std::unique_ptr<RegExpression> child;
30 };
31
32 class BinaryRegExpression : public RegExpression
33 {
34 public:
35 BinaryRegExpression(RegExpression* left_, RegExpression* right_);
36 RegExpression* Left() const { return left.get(); }
37 RegExpression* Right() const { return right.get(); }
38 bool IsCharSymbolExpr() const override { return left->IsCharSymbolExpr() && right->IsCharSymbolExpr(); }
39 private:
40 std::unique_ptr<RegExpression> left;
41 std::unique_ptr<RegExpression> right;
42 };
43
44 class Alt : public BinaryRegExpression
45 {
46 public:
47 Alt(RegExpression* left_, RegExpression* right_);
48 void Accept(Visitor& visitor) override;
49 };
50
51 class Cat : public BinaryRegExpression
52 {
53 public:
54 Cat(RegExpression* left_, RegExpression* right_);
55 void Accept(Visitor& visitor) override;
56 };
57
58 class Kleene : public UnaryRegExpression
59 {
60 public:
61 Kleene(RegExpression* child_);
62 void Accept(Visitor& visitor) override;
63 };
64
65 class Pos : public UnaryRegExpression
66 {
67 public:
68 Pos(RegExpression* child_);
69 void Accept(Visitor& visitor) override;
70 };
71
72 class Opt : public UnaryRegExpression
73 {
74 public:
75 Opt(RegExpression* child_);
76 void Accept(Visitor& visitor) override;
77 };
78
79 class ParenExpr : public UnaryRegExpression
80 {
81 public:
82 ParenExpr(RegExpression* child_);
83 void Accept(Visitor& visitor) override;
84 };
85
86 class SymbolExpr : public RegExpression
87 {
88 public:
89 SymbolExpr(Symbol* symbol_);
90 Symbol* GetSymbol() const { return symbol; }
91 void Accept(Visitor& visitor) override;
92 bool IsCharSymbolExpr() const override { return symbol->IsChar(); }
93 private:
94 Symbol* symbol;
95 };
96
97 class RefExpr : public RegExpression
98 {
99 public:
100 RefExpr(const std::u32string& exprId_);
101 const std::u32string& ExprId() const { return exprId; }
102 void Accept(Visitor& visitor) override;
103 private:
104 std::u32string exprId;
105 };
106
107 } }
108
109 #endif // SNG2HTML_SNG2HTML_REGEX_INCLUDED