diff --git a/alib2data/src/regexp/formal/FormalRegExp.h b/alib2data/src/regexp/formal/FormalRegExp.h index 7532a0cd99d4002531feccda937fdd557b0f3097..2358959b055a5ac25c973789beb8db4d0eb6b3fb 100644 --- a/alib2data/src/regexp/formal/FormalRegExp.h +++ b/alib2data/src/regexp/formal/FormalRegExp.h @@ -104,6 +104,10 @@ public: void compose ( std::deque < sax::Token > & out ) const; virtual alib::ObjectBase * inc ( ) &&; + + virtual RegExpBase * normalize ( ) && { + return new FormalRegExp < > ( std::move ( m_regExp ).normalize ( ) ); + } }; } /* namespace regexp */ diff --git a/alib2data/src/regexp/formal/FormalRegExpAlternation.h b/alib2data/src/regexp/formal/FormalRegExpAlternation.h index ebfba605f19d3bbc991086d9b089ec27c0a5b995..1745bb8909e802f53d782f022732eda456ba5641 100644 --- a/alib2data/src/regexp/formal/FormalRegExpAlternation.h +++ b/alib2data/src/regexp/formal/FormalRegExpAlternation.h @@ -99,6 +99,10 @@ public: void operator >>( std::ostream & out ) const override; explicit operator std::string ( ) const override; + + virtual std::smart_ptr < FormalRegExpElement < DefaultSymbolType > > normalize ( ) && override { + return std::smart_ptr < FormalRegExpElement < DefaultSymbolType > > ( new FormalRegExpAlternation < DefaultSymbolType > ( std::move ( * std::move ( getLeftElement ( ) ).normalize ( ) ), std::move ( * std::move ( getRightElement ( ) ).normalize ( ) ) ) ); + } }; } /* namespace regexp */ diff --git a/alib2data/src/regexp/formal/FormalRegExpConcatenation.h b/alib2data/src/regexp/formal/FormalRegExpConcatenation.h index 9e701f36b8ec9e26b620481719bb239f832359b3..95438c2e0fee820135fe55dd81640fdd8286be9d 100644 --- a/alib2data/src/regexp/formal/FormalRegExpConcatenation.h +++ b/alib2data/src/regexp/formal/FormalRegExpConcatenation.h @@ -96,6 +96,10 @@ public: void operator >>( std::ostream & out ) const override; explicit operator std::string ( ) const override; + + virtual std::smart_ptr < FormalRegExpElement < DefaultSymbolType > > normalize ( ) && override { + return std::smart_ptr < FormalRegExpElement < DefaultSymbolType > > ( new FormalRegExpConcatenation < DefaultSymbolType > ( std::move ( * std::move ( getLeftElement ( ) ).normalize ( ) ), std::move ( * std::move ( getRightElement ( ) ).normalize ( ) ) ) ); + } }; } /* namespace regexp */ diff --git a/alib2data/src/regexp/formal/FormalRegExpElement.h b/alib2data/src/regexp/formal/FormalRegExpElement.h index ee81fc0a8e05fe6c7eb050b04c06857dae11a780..d31035908bb2a5f39df98d07b7256f05c1cfbee0 100644 --- a/alib2data/src/regexp/formal/FormalRegExpElement.h +++ b/alib2data/src/regexp/formal/FormalRegExpElement.h @@ -19,7 +19,7 @@ namespace regexp { * Abstract class representing element in the formal regular expression. Can be operator or symbol. */ template < class SymbolType > -class FormalRegExpElement : public alib::CommonBase < FormalRegExpElement < SymbolType > >, public std::BaseNode < FormalRegExpElement < SymbolType > > { +class FormalRegExpElement : public alib::CommonBaseMiddle < FormalRegExpElement < SymbolType > >, public std::BaseNode < FormalRegExpElement < SymbolType > > { public: class Visitor { public: @@ -107,6 +107,10 @@ public: * @return the minimal alphabet needed by the regexp */ std::set < SymbolType > computeMinimalAlphabet ( ) const; + + /** Traverses the regexp tree and normalizes the symbols to DefaultSymbolType + */ + virtual std::smart_ptr < FormalRegExpElement < DefaultSymbolType > > normalize ( ) && = 0; }; template < class SymbolType > diff --git a/alib2data/src/regexp/formal/FormalRegExpEmpty.h b/alib2data/src/regexp/formal/FormalRegExpEmpty.h index 0b946e8d31aa8b7f15d71aa2432b50ccec9084e5..e3ba960d0032e7901ebe284e8539b25a0f8427d3 100644 --- a/alib2data/src/regexp/formal/FormalRegExpEmpty.h +++ b/alib2data/src/regexp/formal/FormalRegExpEmpty.h @@ -70,6 +70,10 @@ public: void operator >>( std::ostream & out ) const override; explicit operator std::string ( ) const override; + + virtual std::smart_ptr < FormalRegExpElement < DefaultSymbolType > > normalize ( ) && override { + return std::smart_ptr < FormalRegExpElement < DefaultSymbolType > > ( new FormalRegExpEmpty < DefaultSymbolType > ( ) ); + } }; } /* namespace regexp */ diff --git a/alib2data/src/regexp/formal/FormalRegExpEpsilon.h b/alib2data/src/regexp/formal/FormalRegExpEpsilon.h index 2122949d6346b2daa1bb72a46ad6ef0c1c01f94c..d06a89c807df7ca3c3a962aa23a746f79b1aaae9 100644 --- a/alib2data/src/regexp/formal/FormalRegExpEpsilon.h +++ b/alib2data/src/regexp/formal/FormalRegExpEpsilon.h @@ -70,6 +70,10 @@ public: void operator >>( std::ostream & out ) const override; explicit operator std::string ( ) const override; + + virtual std::smart_ptr < FormalRegExpElement < DefaultSymbolType > > normalize ( ) && override { + return std::smart_ptr < FormalRegExpElement < DefaultSymbolType > > ( new FormalRegExpEpsilon < DefaultSymbolType > ( ) ); + } }; } /* namespace regexp */ diff --git a/alib2data/src/regexp/formal/FormalRegExpIteration.h b/alib2data/src/regexp/formal/FormalRegExpIteration.h index f911dc75e2f2e2a850a983da67f3e21ddc33ad52..6f713916ada3bbe12253130c53bde8e887fb3cc1 100644 --- a/alib2data/src/regexp/formal/FormalRegExpIteration.h +++ b/alib2data/src/regexp/formal/FormalRegExpIteration.h @@ -90,6 +90,10 @@ public: void operator >>( std::ostream & out ) const override; explicit operator std::string ( ) const override; + + virtual std::smart_ptr < FormalRegExpElement < DefaultSymbolType > > normalize ( ) && override { + return std::smart_ptr < FormalRegExpElement < DefaultSymbolType > > ( new FormalRegExpIteration < DefaultSymbolType > ( std::move ( * std::move ( getElement ( ) ).normalize ( ) ) ) ); + } }; } /* namespace regexp */ diff --git a/alib2data/src/regexp/formal/FormalRegExpStructure.h b/alib2data/src/regexp/formal/FormalRegExpStructure.h index 46e2984db70fcd2cffd7caf241edd6cfa3d33332..dad35fd0442e728404ea4230b785f2621ed9a4fb 100644 --- a/alib2data/src/regexp/formal/FormalRegExpStructure.h +++ b/alib2data/src/regexp/formal/FormalRegExpStructure.h @@ -63,6 +63,10 @@ public: friend bool operator == ( const FormalRegExpStructure < SymbolType > & first, const FormalRegExpStructure < SymbolType > & second ) { return first.getStructure().compare(second.getStructure()) == 0; } + + FormalRegExpStructure < DefaultSymbolType > normalize ( ) && { + return FormalRegExpStructure < DefaultSymbolType > ( std::move ( * std::move ( getStructure ( ) ).normalize ( ) ) ); + } }; } /* namespace regexp */ diff --git a/alib2data/src/regexp/formal/FormalRegExpSymbol.h b/alib2data/src/regexp/formal/FormalRegExpSymbol.h index 00f20d7fe6a89c06230e2678c260175e8211a026..ecaa740cae8b6717adab401ad49bfd79f130144b 100644 --- a/alib2data/src/regexp/formal/FormalRegExpSymbol.h +++ b/alib2data/src/regexp/formal/FormalRegExpSymbol.h @@ -11,6 +11,7 @@ #include <sstream> #include "FormalRegExpElement.h" +#include <object/AnyObject.h> namespace regexp { @@ -77,6 +78,10 @@ public: const SymbolType & getSymbol ( ) const; explicit operator std::string ( ) const override; + + virtual std::smart_ptr < FormalRegExpElement < DefaultSymbolType > > normalize ( ) && override { + return std::smart_ptr < FormalRegExpElement < DefaultSymbolType > > ( new FormalRegExpSymbol < DefaultSymbolType > ( DefaultSymbolType ( alib::AnyObject < SymbolType > ( std::move ( m_symbol ) ) ) ) ); + } }; } /* namespace regexp */ diff --git a/alib2data/src/regexp/unbounded/UnboundedRegExp.h b/alib2data/src/regexp/unbounded/UnboundedRegExp.h index 63668192478a27b5d2d44cd667c5f12923e9f337..c171ea25fe1dd4b6d20cb9019ed57c7a7b3556a3 100644 --- a/alib2data/src/regexp/unbounded/UnboundedRegExp.h +++ b/alib2data/src/regexp/unbounded/UnboundedRegExp.h @@ -104,6 +104,10 @@ public: void compose ( std::deque < sax::Token > & out ) const; virtual alib::ObjectBase * inc ( ) &&; + + virtual RegExpBase * normalize ( ) && { + return new UnboundedRegExp < > ( std::move ( m_regExp ).normalize ( ) ); + } }; } /* namespace regexp */ diff --git a/alib2data/src/regexp/unbounded/UnboundedRegExpAlternation.h b/alib2data/src/regexp/unbounded/UnboundedRegExpAlternation.h index d05e9d28208163845ec14c2b1536c27e0fdc5e70..8b629cd2bf9cbc1d29e9828eae29f2de9c732c4d 100644 --- a/alib2data/src/regexp/unbounded/UnboundedRegExpAlternation.h +++ b/alib2data/src/regexp/unbounded/UnboundedRegExpAlternation.h @@ -90,6 +90,15 @@ public: void operator >>( std::ostream & out ) const override; explicit operator std::string ( ) const override; + + virtual std::smart_ptr < UnboundedRegExpElement < DefaultSymbolType > > normalize ( ) && override { + UnboundedRegExpAlternation < DefaultSymbolType > * res = new UnboundedRegExpAlternation < DefaultSymbolType > ( ); + + for ( std::smart_ptr < UnboundedRegExpElement < SymbolType > > & element : this->getChildren ( ) ) + res->appendElement ( std::move ( * std::move ( * element ).normalize ( ) ) ); + + return std::smart_ptr < UnboundedRegExpElement < DefaultSymbolType > > ( res ); + } }; } /* namespace regexp */ diff --git a/alib2data/src/regexp/unbounded/UnboundedRegExpConcatenation.h b/alib2data/src/regexp/unbounded/UnboundedRegExpConcatenation.h index 794e9f9abea6bb637c4bde5e2d956140190fdb80..a1936006b8480c850926b8ae298d76a4de5d9d56 100644 --- a/alib2data/src/regexp/unbounded/UnboundedRegExpConcatenation.h +++ b/alib2data/src/regexp/unbounded/UnboundedRegExpConcatenation.h @@ -90,6 +90,15 @@ public: void operator >>( std::ostream & out ) const override; explicit operator std::string ( ) const override; + + virtual std::smart_ptr < UnboundedRegExpElement < DefaultSymbolType > > normalize ( ) && override { + UnboundedRegExpConcatenation < DefaultSymbolType > * res = new UnboundedRegExpConcatenation < DefaultSymbolType > ( ); + + for ( std::smart_ptr < UnboundedRegExpElement < SymbolType > > & element : this->getChildren ( ) ) + res->appendElement ( std::move ( * std::move ( * element ).normalize ( ) ) ); + + return std::smart_ptr < UnboundedRegExpElement < DefaultSymbolType > > ( res ); + } }; } /* namespace regexp */ diff --git a/alib2data/src/regexp/unbounded/UnboundedRegExpElement.h b/alib2data/src/regexp/unbounded/UnboundedRegExpElement.h index 6baeb21776cdf42d90ce78208715fa6414c0cb29..34a1b8de50eb1d03f4dde92e02036ff6586274a7 100644 --- a/alib2data/src/regexp/unbounded/UnboundedRegExpElement.h +++ b/alib2data/src/regexp/unbounded/UnboundedRegExpElement.h @@ -19,7 +19,7 @@ namespace regexp { * Abstract class representing element in the regular expression. Can be operator or symbol. */ template < class SymbolType > -class UnboundedRegExpElement : public alib::CommonBase < UnboundedRegExpElement < SymbolType > >, public std::BaseNode < UnboundedRegExpElement < SymbolType > > { +class UnboundedRegExpElement : public alib::CommonBaseMiddle < UnboundedRegExpElement < SymbolType > >, public std::BaseNode < UnboundedRegExpElement < SymbolType > > { public: class Visitor { public: @@ -104,6 +104,10 @@ public: * @copydoc RankedNode::computeMinimalAlphabet() */ std::set < SymbolType > computeMinimalAlphabet ( ) const; + + /** Traverses the regexp tree and normalizes the symbols to DefaultSymbolType + */ + virtual std::smart_ptr < UnboundedRegExpElement < DefaultSymbolType > > normalize ( ) && = 0; }; template < class SymbolType > diff --git a/alib2data/src/regexp/unbounded/UnboundedRegExpEmpty.h b/alib2data/src/regexp/unbounded/UnboundedRegExpEmpty.h index 79fa0e3391f2d9f3a04949dc1170e8f6d9d2044b..2f3c42e884681ac394e82bb1974233a68f223e21 100644 --- a/alib2data/src/regexp/unbounded/UnboundedRegExpEmpty.h +++ b/alib2data/src/regexp/unbounded/UnboundedRegExpEmpty.h @@ -70,6 +70,10 @@ public: void operator >>( std::ostream & out ) const override; explicit operator std::string ( ) const override; + + virtual std::smart_ptr < UnboundedRegExpElement < DefaultSymbolType > > normalize ( ) && override { + return std::smart_ptr < UnboundedRegExpElement < DefaultSymbolType > > ( new UnboundedRegExpEmpty < DefaultSymbolType > ( ) ); + } }; } /* namespace regexp */ diff --git a/alib2data/src/regexp/unbounded/UnboundedRegExpEpsilon.h b/alib2data/src/regexp/unbounded/UnboundedRegExpEpsilon.h index 6d254b9301eac46adfc293beec6300f2d377951e..c5460bfc47ab5d040f12d3bf8a27b4b6bf66554d 100644 --- a/alib2data/src/regexp/unbounded/UnboundedRegExpEpsilon.h +++ b/alib2data/src/regexp/unbounded/UnboundedRegExpEpsilon.h @@ -70,6 +70,10 @@ public: void operator >>( std::ostream & out ) const override; explicit operator std::string ( ) const override; + + virtual std::smart_ptr < UnboundedRegExpElement < DefaultSymbolType > > normalize ( ) && override { + return std::smart_ptr < UnboundedRegExpElement < DefaultSymbolType > > ( new UnboundedRegExpEpsilon < DefaultSymbolType > ( ) ); + } }; } /* namespace regexp */ diff --git a/alib2data/src/regexp/unbounded/UnboundedRegExpIteration.h b/alib2data/src/regexp/unbounded/UnboundedRegExpIteration.h index dfd6831e467ab28f92ea992849b1d67ca9e950d2..6a0cd632c8273b1dd05f81f834b56890671d474f 100644 --- a/alib2data/src/regexp/unbounded/UnboundedRegExpIteration.h +++ b/alib2data/src/regexp/unbounded/UnboundedRegExpIteration.h @@ -90,6 +90,10 @@ public: void operator >>( std::ostream & out ) const override; explicit operator std::string ( ) const override; + + virtual std::smart_ptr < UnboundedRegExpElement < DefaultSymbolType > > normalize ( ) && override { + return std::smart_ptr < UnboundedRegExpElement < DefaultSymbolType > > ( new UnboundedRegExpIteration < DefaultSymbolType > ( std::move ( * std::move ( getElement ( ) ).normalize ( ) ) ) ); + } }; } /* namespace regexp */ diff --git a/alib2data/src/regexp/unbounded/UnboundedRegExpStructure.h b/alib2data/src/regexp/unbounded/UnboundedRegExpStructure.h index ba2111a77b1d792f1a2c3fdb7d6230d44652bb00..5c480c193dbf13dbee0f0664b409d6ab5d2828b6 100644 --- a/alib2data/src/regexp/unbounded/UnboundedRegExpStructure.h +++ b/alib2data/src/regexp/unbounded/UnboundedRegExpStructure.h @@ -63,6 +63,10 @@ public: friend bool operator == ( const UnboundedRegExpStructure & first, const UnboundedRegExpStructure & second ) { return first.getStructure().compare(second.getStructure()) == 0; } + + UnboundedRegExpStructure < DefaultSymbolType > normalize ( ) && { + return UnboundedRegExpStructure < DefaultSymbolType > ( std::move ( * std::move ( getStructure ( ) ).normalize ( ) ) ); + } }; } /* namespace regexp */ diff --git a/alib2data/src/regexp/unbounded/UnboundedRegExpSymbol.h b/alib2data/src/regexp/unbounded/UnboundedRegExpSymbol.h index c1c0a57dfdecc2ca258d88dda84ae0eb08679b05..142dd497d6605b7955d82b85e58fcdf9f16abbf5 100644 --- a/alib2data/src/regexp/unbounded/UnboundedRegExpSymbol.h +++ b/alib2data/src/regexp/unbounded/UnboundedRegExpSymbol.h @@ -11,6 +11,7 @@ #include <sstream> #include "UnboundedRegExpElement.h" +#include <object/AnyObject.h> namespace regexp { @@ -77,6 +78,10 @@ public: const SymbolType & getSymbol ( ) const; explicit operator std::string ( ) const override; + + virtual std::smart_ptr < UnboundedRegExpElement < DefaultSymbolType > > normalize ( ) && override { + return std::smart_ptr < UnboundedRegExpElement < DefaultSymbolType > > ( new UnboundedRegExpSymbol < DefaultSymbolType > ( DefaultSymbolType ( alib::AnyObject < SymbolType > ( std::move ( m_symbol ) ) ) ) ); + } }; } /* namespace regexp */