Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
FormalRegExp.h
Go to the documentation of this file.
1
6/*
7 * This file is part of Algorithms library toolkit.
8 * Copyright (C) 2017 Jan Travnicek (jan.travnicek@fit.cvut.cz)
9
10 * Algorithms library toolkit is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
14
15 * Algorithms library toolkit is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19
20 * You should have received a copy of the GNU General Public License
21 * along with Algorithms library toolkit. If not, see <http://www.gnu.org/licenses/>.
22 */
23
24#pragma once
25
27
28namespace regexp {
29
30template < class SymbolType = DefaultSymbolType >
31class FormalRegExp;
32
33} /* namespace regexp */
34
35#include <ext/iostream>
36#include <ext/algorithm>
37
38#include <alib/string>
39#include <alib/set>
40
41#include <core/components.hpp>
43
45
46#include <core/normalize.hpp>
48
49#include "../unbounded/UnboundedRegExp.h"
50
51namespace regexp {
52
53class GeneralAlphabet;
54
77template < class SymbolType >
78class FormalRegExp final : public core::Components < FormalRegExp < SymbolType >, ext::set < SymbolType >, component::Set, GeneralAlphabet > {
83
84public:
89
93 explicit FormalRegExp ( );
94
102
109
113 explicit FormalRegExp ( const UnboundedRegExp < SymbolType > & other );
114
121 return this->template accessComponent < GeneralAlphabet > ( ).get ( );
122 }
123
130 return std::move ( this->template accessComponent < GeneralAlphabet > ( ).get ( ) );
131 }
132
139
146
152 void setRegExp ( FormalRegExpStructure < SymbolType > param );
153
161 auto operator <=> ( const FormalRegExp & other ) const {
162 return std::tie ( m_regExp.getStructure ( ), getAlphabet ( ) ) <=> std::tie ( other.m_regExp.getStructure ( ), other.getAlphabet ( ) );
163 }
164
172 bool operator == ( const FormalRegExp & other ) const {
173 return std::tie ( m_regExp.getStructure ( ), getAlphabet ( ) ) == std::tie ( other.m_regExp.getStructure ( ), other.getAlphabet ( ) );
174 }
175
184 friend ext::ostream & operator << ( ext::ostream & out, const FormalRegExp & instance ) {
185 return out << "(FormalRegExp " << instance.getRegExp ( ).getStructure ( ) << ")";
186 }
187};
188
189template < class SymbolType >
190FormalRegExp < SymbolType >::FormalRegExp ( ext::set < SymbolType > alphabet, FormalRegExpStructure < SymbolType > regExp ) : core::Components < FormalRegExp, ext::set < SymbolType >, component::Set, GeneralAlphabet > ( std::move ( alphabet ) ), m_regExp ( std::move ( regExp ) ) {
191 if ( !this->m_regExp.getStructure ( ).checkAlphabet ( getAlphabet ( ) ) )
192 throw exception::CommonException ( "Input symbols not in the alphabet." );
193}
194
195template < class SymbolType >
197}
198
199template < class SymbolType >
200FormalRegExp < SymbolType >::FormalRegExp ( FormalRegExpStructure < SymbolType > regExp ) : FormalRegExp ( regExp.getStructure ( ).computeMinimalAlphabet ( ), regExp ) {
201}
202
203template < class SymbolType >
205}
206
207template < class SymbolType >
209 return m_regExp;
210}
211
212template < class SymbolType >
214 return std::move ( m_regExp );
215}
216
217template < class SymbolType >
219 if ( !param.getStructure ( ).checkAlphabet ( getAlphabet ( ) ) )
220 throw exception::CommonException ( "Input symbols not in the alphabet." );
221
222 this->m_regExp = std::move ( param );
223}
224
225} /* namespace regexp */
226
227namespace core {
228
234template < class SymbolType >
235class SetConstraint< regexp::FormalRegExp < SymbolType >, SymbolType, regexp::GeneralAlphabet > {
236public:
245 static bool used ( const regexp::FormalRegExp < SymbolType > & regexp, const SymbolType & symbol ) {
246 return regexp.getRegExp ( ).getStructure ( ).testSymbol ( symbol );
247 }
248
258 return true;
259 }
260
267 static void valid ( const regexp::FormalRegExp < SymbolType > &, const SymbolType & ) {
268 }
269};
270
276template < class SymbolType >
277struct normalize < regexp::FormalRegExp < SymbolType > > {
280
281 return regexp::FormalRegExp < > ( alphabet, std::move ( value ).getRegExp ( ).normalize ( ) );
282 }
283};
284
285} /* namespace core */
286
287extern template class regexp::FormalRegExp < >;
288
static ext::set< DefaultSymbolType > normalizeAlphabet(ext::set< SymbolType > &&symbols)
Definition: SymbolNormalize.h:50
Definition: components.hpp:181
static bool used(const regexp::FormalRegExp< SymbolType > &regexp, const SymbolType &symbol)
Definition: FormalRegExp.h:245
static bool available(const regexp::FormalRegExp< SymbolType > &, const SymbolType &)
Definition: FormalRegExp.h:257
static void valid(const regexp::FormalRegExp< SymbolType > &, const SymbolType &)
Definition: FormalRegExp.h:267
Definition: setComponents.hpp:26
Basic exception from which all other exceptions are derived.
Definition: CommonException.h:21
Definition: ostream.h:14
Definition: set.hpp:44
Represents formal regular expression structure. Regular expression is stored as a tree of FormalRegEx...
Definition: FormalRegExpStructure.h:45
Formal regular expression represents regular expression. It describes regular languages....
Definition: FormalRegExp.h:78
void setRegExp(FormalRegExpStructure< SymbolType > param)
Definition: FormalRegExp.h:218
ext::set< SymbolType > && getAlphabet() &&
Definition: FormalRegExp.h:129
FormalRegExp()
Creates a new instance of the expression. The default constructor creates expression describing empty...
Definition: FormalRegExp.h:196
SymbolType symbol_type
Definition: FormalRegExp.h:88
bool operator==(const FormalRegExp &other) const
Definition: FormalRegExp.h:172
const ext::set< SymbolType > & getAlphabet() const &
Definition: FormalRegExp.h:120
friend ext::ostream & operator<<(ext::ostream &out, const FormalRegExp &instance)
Definition: FormalRegExp.h:184
const FormalRegExpStructure< SymbolType > & getRegExp() const &
Definition: FormalRegExp.h:208
Unbounded regular expression represents regular expression. It describes regular languages....
Definition: UnboundedRegExp.h:80
Definition: BarSymbol.cpp:12
typename T::SymbolType SymbolType
Definition: ReachableStates.h:176
Definition: normalize.hpp:10
constexpr tuple< Elements &... > tie(Elements &... args) noexcept
Helper of extended tuple of references construction. The tuple is constructed to reffer to values in ...
Definition: tuple.hpp:218
Definition: ToAutomaton.h:15
auto & get(ext::ptr_array< Type, N > &tpl)
Specialisation of get function for pointer arrays.
Definition: ptr_array.hpp:693
static regexp::FormalRegExp< > eval(regexp::FormalRegExp< SymbolType > &&value)
Definition: FormalRegExp.h:278
Definition: normalize.hpp:13