Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
UnboundedRegExpElement.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 >
31class UnboundedRegExpElement;
32
33} /* namespace regexp */
34
35#include <alib/set>
36#include <ext/tree_base>
37#include <core/visitor.hpp>
38
39#include "../formal/FormalRegExpElement.h"
40
41namespace regexp {
42
43template < class SymbolType >
44class UnboundedRegExpAlternation;
45template < class SymbolType >
46class UnboundedRegExpConcatenation;
47template < class SymbolType >
48class UnboundedRegExpIteration;
49template < class SymbolType >
50class UnboundedRegExpSymbol;
51template < class SymbolType >
52class UnboundedRegExpEmpty;
53template < class SymbolType >
54class UnboundedRegExpEpsilon;
55
61template < class SymbolType >
62class UnboundedRegExpElement : public ext::BaseNode < UnboundedRegExpElement < SymbolType > > {
63protected:
67 class Visitor {
68 public:
69 virtual ~Visitor ( ) noexcept = default;
70 virtual void visit ( const UnboundedRegExpAlternation < SymbolType > & ) = 0;
71 virtual void visit ( const UnboundedRegExpConcatenation < SymbolType > & ) = 0;
72 virtual void visit ( const UnboundedRegExpIteration < SymbolType > & ) = 0;
73 virtual void visit ( const UnboundedRegExpSymbol < SymbolType > & ) = 0;
74 virtual void visit ( const UnboundedRegExpEmpty < SymbolType > & ) = 0;
75 virtual void visit ( const UnboundedRegExpEpsilon < SymbolType > & ) = 0;
76 };
77
82 public:
83 virtual ~RvalueVisitor ( ) noexcept = default;
84 virtual void visit ( UnboundedRegExpAlternation < SymbolType > && ) = 0;
85 virtual void visit ( UnboundedRegExpConcatenation < SymbolType > && ) = 0;
86 virtual void visit ( UnboundedRegExpIteration < SymbolType > && ) = 0;
87 virtual void visit ( UnboundedRegExpSymbol < SymbolType > && ) = 0;
88 virtual void visit ( UnboundedRegExpEmpty < SymbolType > && ) = 0;
89 virtual void visit ( UnboundedRegExpEpsilon < SymbolType > && ) = 0;
90 };
91
99 template < class ReturnType, class Visitorr, class ... Params >
100 class VisitorContext : public core::VisitorContextAux < ReturnType, Visitorr, Params ... >, public UnboundedRegExpElement::Visitor {
101 public:
105 using core::VisitorContextAux < ReturnType, Visitorr, Params ... >::VisitorContextAux;
106
110 void visit ( const UnboundedRegExpAlternation < SymbolType > & inherit ) override {
111 this->call ( inherit, std::make_index_sequence < sizeof ... ( Params ) > { } );
112 }
113
117 void visit ( const UnboundedRegExpConcatenation < SymbolType > & inherit ) override {
118 this->call ( inherit, std::make_index_sequence < sizeof ... ( Params ) > { } );
119 }
120
124 void visit ( const UnboundedRegExpIteration < SymbolType > & inherit ) override {
125 this->call ( inherit, std::make_index_sequence < sizeof ... ( Params ) > { } );
126 }
127
131 void visit ( const UnboundedRegExpSymbol < SymbolType > & inherit ) override {
132 this->call ( inherit, std::make_index_sequence < sizeof ... ( Params ) > { } );
133 }
134
138 void visit ( const UnboundedRegExpEmpty < SymbolType > & inherit ) override {
139 this->call ( inherit, std::make_index_sequence < sizeof ... ( Params ) > { } );
140 }
141
145 void visit ( const UnboundedRegExpEpsilon < SymbolType > & inherit ) override {
146 this->call ( inherit, std::make_index_sequence < sizeof ... ( Params ) > { } );
147 }
148 };
149
157 template < class ReturnType, class Visitorr, class ... Params >
158 class RvalueVisitorContext : public core::VisitorContextAux < ReturnType, Visitorr, Params ... >, public UnboundedRegExpElement::RvalueVisitor {
159 public:
163 using core::VisitorContextAux < ReturnType, Visitorr, Params ... >::VisitorContextAux;
164
169 this->call ( std::move ( inherit ), std::make_index_sequence < sizeof ... ( Params ) > { } );
170 }
171
176 this->call ( std::move ( inherit ), std::make_index_sequence < sizeof ... ( Params ) > { } );
177 }
178
182 void visit ( UnboundedRegExpIteration < SymbolType > && inherit ) override {
183 this->call ( std::move ( inherit ), std::make_index_sequence < sizeof ... ( Params ) > { } );
184 }
185
189 void visit ( UnboundedRegExpSymbol < SymbolType > && inherit ) override {
190 this->call ( std::move ( inherit ), std::make_index_sequence < sizeof ... ( Params ) > { } );
191 }
192
196 void visit ( UnboundedRegExpEmpty < SymbolType > && inherit ) override {
197 this->call ( std::move ( inherit ), std::make_index_sequence < sizeof ... ( Params ) > { } );
198 }
199
203 void visit ( UnboundedRegExpEpsilon < SymbolType > && inherit ) override {
204 this->call ( std::move ( inherit ), std::make_index_sequence < sizeof ... ( Params ) > { } );
205 }
206 };
207
213 virtual void accept ( UnboundedRegExpElement::Visitor & visitor ) const & = 0;
214
220 virtual void accept ( UnboundedRegExpElement::RvalueVisitor & visitor ) && = 0;
221
222public:
224
225 virtual UnboundedRegExpElement < SymbolType > * clone ( ) && = 0;
226
238 template < class ReturnType, class Visitorr, class ... Params >
239 ReturnType accept ( Params && ... params ) const & {
240 VisitorContext < ReturnType, Visitorr, Params ... > context ( std::forward < Params > ( params ) ... );
241 accept ( context );
242 return context.getResult ( );
243 }
244
256 template < class ReturnType, class Visitorr, class ... Params >
257 ReturnType accept ( Params && ... params ) && {
258 RvalueVisitorContext < ReturnType, Visitorr, Params ... > context ( std::forward < Params > ( params ) ... );
259 std::move ( * this ).accept ( context );
260 return context.getResult ( );
261 }
262
269
276 virtual bool testSymbol ( const SymbolType & symbol ) const = 0;
277
284
291 virtual bool checkAlphabet ( const ext::set < SymbolType > & alphabet ) const = 0;
292
299
306
316 instance >> os;
317 return os;
318 }
319
325 virtual void operator >>( ext::ostream & ) const = 0;
326
336 virtual std::strong_ordering operator <=> ( const UnboundedRegExpElement < SymbolType > & other ) const = 0;
337
347 virtual bool operator == ( const UnboundedRegExpElement < SymbolType > & other ) const = 0;
348};
349
350template < class SymbolType >
353
355 return res;
356}
357
358} /* namespace regexp */
359
361
Class implementing an actual visitor interface to the visitor.
Definition: visitor.hpp:22
Base class for hierarchy of tree node types. The tree node types can be used to construct tree struct...
Definition: tree_base.hpp:20
Definition: ostream.h:14
Definition: set.hpp:44
Managed pointer simulating value like behavior.
Definition: memory.hpp:233
Represents the alternation operator in the regular expression. The node can have 0 to n children in l...
Definition: UnboundedRegExpAlternation.h:44
Represents the concatenation operator in the regular expression. The node can have 0 to n children in...
Definition: UnboundedRegExpConcatenation.h:44
Definition: UnboundedRegExpElement.h:158
void visit(UnboundedRegExpEmpty< SymbolType > &&inherit) override
Definition: UnboundedRegExpElement.h:196
void visit(UnboundedRegExpEpsilon< SymbolType > &&inherit) override
Definition: UnboundedRegExpElement.h:203
void visit(UnboundedRegExpConcatenation< SymbolType > &&inherit) override
Definition: UnboundedRegExpElement.h:175
void visit(UnboundedRegExpIteration< SymbolType > &&inherit) override
Definition: UnboundedRegExpElement.h:182
void visit(UnboundedRegExpAlternation< SymbolType > &&inherit) override
Definition: UnboundedRegExpElement.h:168
void visit(UnboundedRegExpSymbol< SymbolType > &&inherit) override
Definition: UnboundedRegExpElement.h:189
Definition: UnboundedRegExpElement.h:81
virtual ~RvalueVisitor() noexcept=default
Definition: UnboundedRegExpElement.h:100
void visit(const UnboundedRegExpSymbol< SymbolType > &inherit) override
Definition: UnboundedRegExpElement.h:131
void visit(const UnboundedRegExpEmpty< SymbolType > &inherit) override
Definition: UnboundedRegExpElement.h:138
void visit(const UnboundedRegExpAlternation< SymbolType > &inherit) override
Definition: UnboundedRegExpElement.h:110
void visit(const UnboundedRegExpIteration< SymbolType > &inherit) override
Definition: UnboundedRegExpElement.h:124
void visit(const UnboundedRegExpConcatenation< SymbolType > &inherit) override
Definition: UnboundedRegExpElement.h:117
void visit(const UnboundedRegExpEpsilon< SymbolType > &inherit) override
Definition: UnboundedRegExpElement.h:145
Definition: UnboundedRegExpElement.h:67
virtual void visit(const UnboundedRegExpAlternation< SymbolType > &)=0
virtual ~Visitor() noexcept=default
Definition: UnboundedRegExpElement.h:62
friend ext::ostream & operator<<(ext::ostream &os, const UnboundedRegExpElement< SymbolType > &instance)
Definition: UnboundedRegExpElement.h:315
virtual void operator>>(ext::ostream &) const =0
virtual ext::smart_ptr< UnboundedRegExpElement< DefaultSymbolType > > normalize() &&=0
Traverses the regexp tree and normalizes the symbols to DefaultSymbolType.
ext::set< SymbolType > computeMinimalAlphabet() const
Definition: UnboundedRegExpElement.h:351
ReturnType accept(Params &&... params) &&
Definition: UnboundedRegExpElement.h:257
virtual UnboundedRegExpElement< SymbolType > * clone() const &=0
virtual void computeMinimalAlphabet(ext::set< SymbolType > &alphabet) const =0
virtual bool testSymbol(const SymbolType &symbol) const =0
virtual void accept(UnboundedRegExpElement::Visitor &visitor) const &=0
Accept method of the visitor pattern. This is where the actual type of this object is evaluated.
virtual bool operator==(const UnboundedRegExpElement< SymbolType > &other) const =0
Comparison helper method evaluating allowing possibly deeper comparison of this with other class of t...
virtual bool checkAlphabet(const ext::set< SymbolType > &alphabet) const =0
virtual std::strong_ordering operator<=>(const UnboundedRegExpElement< SymbolType > &other) const =0
Three way comparison helper method evaluating allowing possibly deeper comparison of this with other ...
virtual ext::smart_ptr< FormalRegExpElement< SymbolType > > asFormal() const =0
virtual void accept(UnboundedRegExpElement::RvalueVisitor &visitor) &&=0
Accept method of the visitor pattern. This is where the actual type of this object is evaluated.
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 the symbol in the regular expression. The can't have any children.
Definition: UnboundedRegExpSymbol.h:42
Definition: BarSymbol.cpp:12
ext::set< ext::pair< StateType, StateType > > call(const ext::set< ext::pair< StateType, StateType > > &S, const InputSymbolType &input, const N &nondeterministic)
Definition: RHDPDACommon.h:94
typename T::SymbolType SymbolType
Definition: ReachableStates.h:176
return res
Definition: MinimizeByPartitioning.h:145
Definition: normalize.hpp:10
Definition: ToAutomaton.h:15