Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
RegExpIntegral.h
Go to the documentation of this file.
1
6#pragma once
7
12
13#include <string/LinearString.h>
14
17
18namespace regexp {
19
20namespace transform {
21
27public:
38 template < class SymbolType >
40
44 template < class SymbolType >
46
57 template < class SymbolType >
59
63 template < class SymbolType >
65
66private:
67 template < class SymbolType >
68 class Formal {
69 public:
70 static std::unique_ptr < regexp::FormalRegExpElement < SymbolType > > visit(const regexp::FormalRegExpAlternation < SymbolType > & alternation, const SymbolType& argument);
71 static std::unique_ptr < regexp::FormalRegExpElement < SymbolType > > visit(const regexp::FormalRegExpConcatenation < SymbolType > & concatenation, const SymbolType& argument);
72 static std::unique_ptr < regexp::FormalRegExpElement < SymbolType > > visit(const regexp::FormalRegExpIteration < SymbolType > & iteration, const SymbolType& argument);
73 static std::unique_ptr < regexp::FormalRegExpElement < SymbolType > > visit(const regexp::FormalRegExpSymbol < SymbolType > & symbol, const SymbolType& argument);
74 static std::unique_ptr < regexp::FormalRegExpElement < SymbolType > > visit(const regexp::FormalRegExpEpsilon < SymbolType > & epsilon, const SymbolType& argument);
75 static std::unique_ptr < regexp::FormalRegExpElement < SymbolType > > visit(const regexp::FormalRegExpEmpty < SymbolType > & empty, const SymbolType& argument);
76 };
77
78 template < class SymbolType >
79 class Unbounded {
80 public:
81 static std::unique_ptr < regexp::UnboundedRegExpElement < SymbolType > > visit(const regexp::UnboundedRegExpAlternation < SymbolType > & alternation, const SymbolType& argument);
82 static std::unique_ptr < regexp::UnboundedRegExpElement < SymbolType > > visit(const regexp::UnboundedRegExpConcatenation < SymbolType > & concatenation, const SymbolType& argument);
83 static std::unique_ptr < regexp::UnboundedRegExpElement < SymbolType > > visit(const regexp::UnboundedRegExpIteration < SymbolType > & iteration, const SymbolType& argument);
84 static std::unique_ptr < regexp::UnboundedRegExpElement < SymbolType > > visit(const regexp::UnboundedRegExpSymbol < SymbolType > & symbol, const SymbolType& argument);
85 static std::unique_ptr < regexp::UnboundedRegExpElement < SymbolType > > visit(const regexp::UnboundedRegExpEpsilon < SymbolType > & epsilon, const SymbolType& argument);
86 static std::unique_ptr < regexp::UnboundedRegExpElement < SymbolType > > visit(const regexp::UnboundedRegExpEmpty < SymbolType > & empty, const SymbolType& argument);
87 };
88};
89
90template < class SymbolType >
92 std::unique_ptr < regexp::FormalRegExpElement < SymbolType > > newRegExp ( regexp.getRegExp().getStructure().clone() );
93
94 for(const auto& symbol : string.getContent())
95 newRegExp = newRegExp->template accept < std::unique_ptr < regexp::FormalRegExpElement < SymbolType > >, RegExpIntegral::Formal < SymbolType > > ( symbol );
96
98}
99
100template < class SymbolType >
102 std::unique_ptr < regexp::UnboundedRegExpElement < SymbolType > > newRegExp ( regexp.getRegExp().getStructure().clone() );
103
104 for(const auto& symbol : string.getContent())
105 newRegExp = newRegExp->template accept < std::unique_ptr < regexp::UnboundedRegExpElement < SymbolType > >, RegExpIntegral::Unbounded < SymbolType > > ( symbol );
106
108}
109
110template < class SymbolType >
112 std::unique_ptr < regexp::FormalRegExpElement < SymbolType > > newRegExp = regexp.getRegExp().getStructure().template accept < std::unique_ptr < regexp::FormalRegExpElement < SymbolType > >, RegExpIntegral::Formal < SymbolType > > ( symbol );
113
115}
116
117template < class SymbolType >
119 std::unique_ptr < regexp::UnboundedRegExpElement < SymbolType > > newRegExp = regexp.getRegExp().getStructure().template accept < std::unique_ptr < regexp::UnboundedRegExpElement < SymbolType > >, RegExpIntegral::Unbounded < SymbolType > > ( symbol );
120
122}
123
124// ----------------------------------------------------------------------------
125
126template < class SymbolType >
127std::unique_ptr < regexp::FormalRegExpElement < SymbolType > > RegExpIntegral::Formal < SymbolType >::visit(const regexp::FormalRegExpAlternation < SymbolType > & alternation, const SymbolType& argument) {
128 std::unique_ptr < regexp::FormalRegExpElement < SymbolType > > leftIntegral = alternation.getLeftElement().template accept < std::unique_ptr < regexp::FormalRegExpElement < SymbolType > >, RegExpIntegral::Formal < SymbolType > > ( argument );
129 std::unique_ptr < regexp::FormalRegExpElement < SymbolType > > rightIntegral = alternation.getRightElement().template accept < std::unique_ptr < regexp::FormalRegExpElement < SymbolType > >, RegExpIntegral::Formal < SymbolType > > ( argument );
130
131 return std::unique_ptr < FormalRegExpElement < SymbolType > > ( new regexp::FormalRegExpAlternation < SymbolType > ( std::move ( * leftIntegral ), std::move ( * rightIntegral ) ) );
132}
133
134template < class SymbolType >
135std::unique_ptr < regexp::FormalRegExpElement < SymbolType > > RegExpIntegral::Formal < SymbolType >::visit(const regexp::FormalRegExpConcatenation < SymbolType > & concatenation, const SymbolType& argument) {
136 return std::unique_ptr < regexp::FormalRegExpElement < SymbolType > > ( new regexp::FormalRegExpConcatenation < SymbolType > ( regexp::FormalRegExpSymbol < SymbolType > ( argument ), concatenation ) );
137}
138
139template < class SymbolType >
140std::unique_ptr < regexp::FormalRegExpElement < SymbolType > > RegExpIntegral::Formal < SymbolType >::visit(const regexp::FormalRegExpIteration < SymbolType > & iteration, const SymbolType& argument) {
141 return std::unique_ptr < regexp::FormalRegExpElement < SymbolType > > ( new regexp::FormalRegExpConcatenation < SymbolType > ( regexp::FormalRegExpSymbol < SymbolType > ( argument ), iteration ) );
142}
143
144template < class SymbolType >
145std::unique_ptr < regexp::FormalRegExpElement < SymbolType > > RegExpIntegral::Formal < SymbolType >::visit(const regexp::FormalRegExpSymbol < SymbolType > & symbol, const SymbolType& argument) {
146 return std::unique_ptr < regexp::FormalRegExpElement < SymbolType > > ( new regexp::FormalRegExpConcatenation < SymbolType > ( regexp::FormalRegExpSymbol < SymbolType > ( argument ), symbol ) );
147}
148
149template < class SymbolType >
150std::unique_ptr < regexp::FormalRegExpElement < SymbolType > > RegExpIntegral::Formal < SymbolType >::visit(const regexp::FormalRegExpEpsilon < SymbolType > &, const SymbolType& argument) {
151 return std::unique_ptr < regexp::FormalRegExpElement < SymbolType > > ( new regexp::FormalRegExpSymbol < SymbolType > ( argument ) );
152}
153
154template < class SymbolType >
155std::unique_ptr < regexp::FormalRegExpElement < SymbolType > > RegExpIntegral::Formal < SymbolType >::visit(const regexp::FormalRegExpEmpty < SymbolType > &, const SymbolType&) {
156 return std::unique_ptr < regexp::FormalRegExpElement < SymbolType > > ( new regexp::FormalRegExpEmpty < SymbolType > ( ) );
157}
158
159// ----------------------------------------------------------------------------
160
161template < class SymbolType >
162std::unique_ptr < regexp::UnboundedRegExpElement < SymbolType > > RegExpIntegral::Unbounded < SymbolType >::visit(const regexp::UnboundedRegExpAlternation < SymbolType > & alternation, const SymbolType& argument) {
164
165 for(const UnboundedRegExpElement < SymbolType > & child : alternation.getElements())
166 alt->appendElement(* ( child.template accept < std::unique_ptr < regexp::UnboundedRegExpElement < SymbolType > >, RegExpIntegral::Unbounded < SymbolType > > (argument) ) );
167
168 return std::unique_ptr < UnboundedRegExpElement < SymbolType > > ( alt );
169}
170
171template < class SymbolType >
172std::unique_ptr < regexp::UnboundedRegExpElement < SymbolType > > RegExpIntegral::Unbounded < SymbolType >::visit(const regexp::UnboundedRegExpConcatenation < SymbolType > & concatenation, const SymbolType& argument) {
174
176 for ( const UnboundedRegExpElement < SymbolType > & element : concatenation.getElements() )
177 con->appendElement ( element );
178
179 return std::unique_ptr < regexp::UnboundedRegExpElement < SymbolType > > ( con );
180}
181
182template < class SymbolType >
183std::unique_ptr < regexp::UnboundedRegExpElement < SymbolType > > RegExpIntegral::Unbounded < SymbolType >::visit(const regexp::UnboundedRegExpIteration < SymbolType > & iteration, const SymbolType& argument) {
186 con->appendElement ( iteration );
187
188 return std::unique_ptr < regexp::UnboundedRegExpElement < SymbolType > > ( con );
189}
190
191template < class SymbolType >
192std::unique_ptr < regexp::UnboundedRegExpElement < SymbolType > > RegExpIntegral::Unbounded < SymbolType >::visit(const regexp::UnboundedRegExpSymbol < SymbolType > & symbol, const SymbolType& argument) {
195 con->appendElement ( symbol );
196
197 return std::unique_ptr < regexp::UnboundedRegExpElement < SymbolType > > ( con );
198}
199
200template < class SymbolType >
201std::unique_ptr < regexp::UnboundedRegExpElement < SymbolType > > RegExpIntegral::Unbounded < SymbolType >::visit(const regexp::UnboundedRegExpEpsilon < SymbolType > &, const SymbolType& argument) {
202 return std::unique_ptr < regexp::UnboundedRegExpElement < SymbolType > > ( new regexp::UnboundedRegExpSymbol < SymbolType > ( argument ) );
203}
204
205template < class SymbolType >
206std::unique_ptr < regexp::UnboundedRegExpElement < SymbolType > > RegExpIntegral::Unbounded < SymbolType >::visit(const regexp::UnboundedRegExpEmpty < SymbolType > &, const SymbolType&) {
207 return std::unique_ptr < regexp::UnboundedRegExpElement < SymbolType > > ( new regexp::UnboundedRegExpEmpty < SymbolType > ( ) );
208}
209
210} /* namespace transform */
211
212} /* namespace regexp */
213
Represents the alternation operator in the regular expression. The node must have exactly two childre...
Definition: FormalRegExpAlternation.h:44
Represents the concatenation operator in the regular expression. The node must have exactly two child...
Definition: FormalRegExpConcatenation.h:44
Represents the empty expression in the regular expression. The node can't have any children.
Definition: FormalRegExpEmpty.h:41
Represents the epsilon expression in the regular expression. The node can't have any children.
Definition: FormalRegExpEpsilon.h:41
Represents the iteration operator in the regular expression. The node has exactly one child.
Definition: FormalRegExpIteration.h:44
Represents formal regular expression structure. Regular expression is stored as a tree of FormalRegEx...
Definition: FormalRegExpStructure.h:45
Represents the symbol in the regular expression. The can't have any children.
Definition: FormalRegExpSymbol.h:42
Formal regular expression represents regular expression. It describes regular languages....
Definition: FormalRegExp.h:78
Represents the alternation operator in the regular expression. The node can have 0 to n children in l...
Definition: UnboundedRegExpAlternation.h:44
void appendElement(UnboundedRegExpElement< SymbolType > &&element)
Definition: UnboundedRegExpAlternation.h:195
Represents the concatenation operator in the regular expression. The node can have 0 to n children in...
Definition: UnboundedRegExpConcatenation.h:44
void appendElement(UnboundedRegExpElement< SymbolType > &&element)
Definition: UnboundedRegExpConcatenation.h:195
Definition: UnboundedRegExpElement.h:62
Represents the empty expression in the regular expression. The node can't have any children.
Definition: UnboundedRegExpEmpty.h:41
Represents the epsilon expression in the regular expression. The node can't have any children.
Definition: UnboundedRegExpEpsilon.h:41
Represents the iteration operator in the regular expression. The node has exactly one child.
Definition: UnboundedRegExpIteration.h:43
Represents unbounded regular expression structure. Regular expression is stored as a tree of Unbounde...
Definition: UnboundedRegExpStructure.h:47
Represents the symbol in the regular expression. The can't have any children.
Definition: UnboundedRegExpSymbol.h:42
Unbounded regular expression represents regular expression. It describes regular languages....
Definition: UnboundedRegExp.h:80
Definition: RegExpIntegral.h:26
static regexp::FormalRegExp< SymbolType > integral(const regexp::FormalRegExp< SymbolType > &regexp, const string::LinearString< SymbolType > &string)
Definition: RegExpIntegral.h:91
Linear string.
Definition: LinearString.h:57
typename T::SymbolType SymbolType
Definition: ReachableStates.h:176
ContainerType< ResType > transform(const ContainerType< InType, Ts ... > &in, Callback transform)
In container tranformation of all elements according to the tranform.
Definition: algorithm.hpp:150
constexpr auto visit(Visitor &&vis, Variants &&... vars)
Definition: variant.hpp:42
Definition: ToAutomaton.h:15