1 using System;
2 using System.Collections;
3
4 namespace soulcm.scm2html
5 {
6 public abstract class RegExpression
7 {
8 public RegExpression()
9 {
10 }
11 public virtual ~RegExpression()
12 {
13 }
14 public abstract void Accept(Visitor& visitor);
15 public virtual bool IsCharSymbolExpr() const
16 {
17 return false;
18 }
19 }
20
21 public abstract class UnaryRegExpression : RegExpression
22 {
23 public UnaryRegExpression(RegExpression* child_) :
24 child(child_)
25 {
26 }
27 public RegExpression* Child() const
28 {
29 return child.Get();
30 }
31 private UniquePtr<RegExpression> child;
32 }
33
34 public abstract class BinaryRegExpression : RegExpression
35 {
36 public BinaryRegExpression(RegExpression* left_, RegExpression* right_) :
37 left(left_), right(right_)
38 {
39 }
40 public RegExpression* Left() const
41 {
42 return left.Get();
43 }
44 public RegExpression* Right() const
45 {
46 return right.Get();
47 }
48 public override bool IsCharSymbolExpr() const
49 {
50 return left->IsCharSymbolExpr() && right->IsCharSymbolExpr();
51 }
52 private UniquePtr<RegExpression> left;
53 private UniquePtr<RegExpression> right;
54 }
55
56 public class Alt : BinaryRegExpression
57 {
58 public Alt(RegExpression* left_, RegExpression* right_) :
59 base(left_, right_)
60 {
61 }
62 public override void Accept(Visitor& visitor)
63 {
64 visitor.Visit(*this);
65 }
66 }
67
68 public class Cat : BinaryRegExpression
69 {
70 public Cat(RegExpression* left_, RegExpression* right_) :
71 base(left_, right_)
72 {
73 }
74 public override void Accept(Visitor& visitor)
75 {
76 visitor.Visit(*this);
77 }
78 }
79
80 public class Kleene : UnaryRegExpression
81 {
82 public Kleene(RegExpression* child_) :
83 base(child_)
84 {
85 }
86 public override void Accept(Visitor& visitor)
87 {
88 visitor.Visit(*this);
89 }
90 }
91
92 public class Pos : UnaryRegExpression
93 {
94 public Pos(RegExpression* child_) :
95 base(child_)
96 {
97 }
98 public override void Accept(Visitor& visitor)
99 {
100 visitor.Visit(*this);
101 }
102 }
103
104 public class Opt : UnaryRegExpression
105 {
106 public Opt(RegExpression* child_) :
107 base(child_)
108 {
109 }
110 public override void Accept(Visitor& visitor)
111 {
112 visitor.Visit(*this);
113 }
114 }
115
116 public class ParenExpr : UnaryRegExpression
117 {
118 public ParenExpr(RegExpression* child_) :
119 base(child_)
120 {
121 }
122 public override void Accept(Visitor& visitor)
123 {
124 visitor.Visit(*this);
125 }
126 }
127
128 public class SymbolExpr : RegExpression
129 {
130 public SymbolExpr(Symbol* symbol_) :
131 symbol(symbol_)
132 {
133 }
134 public Symbol* GetSymbol() const
135 {
136 return symbol;
137 }
138 public override bool IsCharSymbolExpr() const
139 {
140 return symbol->IsChar();
141 }
142 public override void Accept(Visitor& visitor)
143 {
144 visitor.Visit(*this);
145 }
146 private Symbol* symbol;
147 }
148
149 public class RefExpr : RegExpression
150 {
151 public RefExpr(const ustring& exprId_) :
152 exprId(exprId_)
153 {
154 }
155 public const ustring& ExprId() const
156 {
157 return exprId;
158 }
159 public override void Accept(Visitor& visitor)
160 {
161 visitor.Visit(*this);
162 }
163 private ustring exprId;
164 }
165 }