diff --git a/alib2data/src/regexp/RegExpFromStringParser.cpp b/alib2data/src/regexp/RegExpFromStringParser.cpp index 6ca6c60f535d0a3d3ac6b70bdfc0399aedd0fbb8..ddf3bab87b1ebe1480da7886559a9e9786a50385 100644 --- a/alib2data/src/regexp/RegExpFromStringParser.cpp +++ b/alib2data/src/regexp/RegExpFromStringParser.cpp @@ -19,7 +19,7 @@ RegExp RegExpFromStringParser::parse(const std::set<FEATURES>& features) { delete element; if(features.count(FEATURES::UNBOUNDED)) return RegExp{regexp}; -// if(features.count(FEATURES::FORMAL)) return RegExp{FormalRegExp{regexp}}; TODO + if(features.count(FEATURES::FORMAL)) return RegExp{FormalRegExp{regexp}}; throw exception::AlibException(); } diff --git a/alib2data/src/regexp/RegExpFromStringParser.h b/alib2data/src/regexp/RegExpFromStringParser.h index 96c488031d3360963b9e1c5674bf6e8fbca6a8fe..341ef44b30a0d9c5e963f2bb74494cb31fb39430 100644 --- a/alib2data/src/regexp/RegExpFromStringParser.h +++ b/alib2data/src/regexp/RegExpFromStringParser.h @@ -10,6 +10,7 @@ #include "RegExp.h" #include "unbounded/UnboundedRegExpElements.h" +#include "formal/FormalRegExpElements.h" #include "RegExpFromStringLexer.h" #include "../alphabet/SymbolFromStringParser.h" diff --git a/alib2data/src/regexp/formal/FormalRegExp.cpp b/alib2data/src/regexp/formal/FormalRegExp.cpp index 351f9005c206a62eccc3398e009c0e7aa1b35a65..9b171d128ffabfe1023d93fc818f6c47cb9086eb 100644 --- a/alib2data/src/regexp/formal/FormalRegExp.cpp +++ b/alib2data/src/regexp/formal/FormalRegExp.cpp @@ -23,6 +23,13 @@ FormalRegExp::FormalRegExp() { this->regExp = new FormalRegExpEmpty(); } +FormalRegExp::FormalRegExp(const UnboundedRegExp& other) : alphabet(other.getAlphabet()) { + this->regExp = NULL; + FormalRegExpElement* element = other.getRegExp().cloneAsFormal(); + setRegExp(std::move(*element)); + delete element; +} + FormalRegExp::FormalRegExp(const std::set<alphabet::Symbol>& alphabet, const FormalRegExpElement& regExp) : alphabet(alphabet) { this->regExp = NULL; setRegExp(regExp); diff --git a/alib2data/src/regexp/formal/FormalRegExp.h b/alib2data/src/regexp/formal/FormalRegExp.h index 639d8e07b00e4f4b4ff3df246f75c3cf455f0aa1..bba5ca7e4fae07262dc277598bc8736985a30bc0 100644 --- a/alib2data/src/regexp/formal/FormalRegExp.h +++ b/alib2data/src/regexp/formal/FormalRegExp.h @@ -42,6 +42,7 @@ protected: public: FormalRegExp(); + explicit FormalRegExp(const UnboundedRegExp& other); FormalRegExp(const std::set<alphabet::Symbol>& alphabet, const FormalRegExpElement& regExp); FormalRegExp(std::set<alphabet::Symbol>&& alphabet, FormalRegExpElement&& regExp); explicit FormalRegExp(const FormalRegExpElement& regExp); diff --git a/alib2data/src/regexp/formal/FormalRegExpAlternation.cpp b/alib2data/src/regexp/formal/FormalRegExpAlternation.cpp index bc772ca3887cd33fda9daf4aac8501cd1f229809..9ef0dd825366ba66dc23a7c2a6a3318d7195745f 100644 --- a/alib2data/src/regexp/formal/FormalRegExpAlternation.cpp +++ b/alib2data/src/regexp/formal/FormalRegExpAlternation.cpp @@ -7,6 +7,7 @@ #include "FormalRegExpAlternation.h" #include "../../exception/AlibException.h" +#include "../unbounded/UnboundedRegExpAlternation.h" namespace regexp { @@ -112,6 +113,20 @@ FormalRegExpElement* FormalRegExpAlternation::plunder() && { return new FormalRegExpAlternation(std::move(*this)); } +UnboundedRegExpElement* FormalRegExpAlternation::cloneAsUnbounded() const { + UnboundedRegExpAlternation* res = new UnboundedRegExpAlternation(); + + UnboundedRegExpElement* leftTmp = left->cloneAsUnbounded(); + res->appendElement(std::move(*leftTmp)); + delete leftTmp; + + UnboundedRegExpElement* rightTmp = right->cloneAsUnbounded(); + res->appendElement(std::move(*rightTmp)); + delete rightTmp; + + return res; +} + bool FormalRegExpAlternation::operator<(const FormalRegExpElement& other) const { return other > *this; } diff --git a/alib2data/src/regexp/formal/FormalRegExpAlternation.h b/alib2data/src/regexp/formal/FormalRegExpAlternation.h index 4f317b8de717922fcbfbc6d1e4bb1d58e77da0e2..200a00f5712676b1da097db59f087ded9348eaf0 100644 --- a/alib2data/src/regexp/formal/FormalRegExpAlternation.h +++ b/alib2data/src/regexp/formal/FormalRegExpAlternation.h @@ -29,6 +29,11 @@ protected: */ virtual FormalRegExpElement* plunder() &&; + /** + * @copydoc FormalRegExpElement::clone() const + */ + virtual UnboundedRegExpElement* cloneAsUnbounded() const; + FormalRegExpElement* left; FormalRegExpElement* right; diff --git a/alib2data/src/regexp/formal/FormalRegExpConcatenation.cpp b/alib2data/src/regexp/formal/FormalRegExpConcatenation.cpp index 9cd3cc01ea9f92b116cdc4ceca5280538e2fa959..dab550bb6a20dac134b98273658cc382bbcf25ab 100644 --- a/alib2data/src/regexp/formal/FormalRegExpConcatenation.cpp +++ b/alib2data/src/regexp/formal/FormalRegExpConcatenation.cpp @@ -7,6 +7,7 @@ #include "FormalRegExpConcatenation.h" #include "../../exception/AlibException.h" +#include "../unbounded/UnboundedRegExpConcatenation.h" namespace regexp { @@ -108,6 +109,20 @@ FormalRegExpElement* FormalRegExpConcatenation::clone() const { return new FormalRegExpConcatenation(*this); } +UnboundedRegExpElement* FormalRegExpConcatenation::cloneAsUnbounded() const { + UnboundedRegExpConcatenation* res = new UnboundedRegExpConcatenation(); + + UnboundedRegExpElement* leftTmp = left->cloneAsUnbounded(); + res->appendElement(std::move(*leftTmp)); + delete leftTmp; + + UnboundedRegExpElement* rightTmp = right->cloneAsUnbounded(); + res->appendElement(std::move(*rightTmp)); + delete rightTmp; + + return res; +} + FormalRegExpElement* FormalRegExpConcatenation::plunder() && { return new FormalRegExpConcatenation(std::move(*this)); } diff --git a/alib2data/src/regexp/formal/FormalRegExpConcatenation.h b/alib2data/src/regexp/formal/FormalRegExpConcatenation.h index c47a20a8c8a56752cad31ef8376c749d7778d285..c5cf985af0af750a9546e911bc4df45ec8fbdaaf 100644 --- a/alib2data/src/regexp/formal/FormalRegExpConcatenation.h +++ b/alib2data/src/regexp/formal/FormalRegExpConcatenation.h @@ -26,6 +26,11 @@ protected: virtual FormalRegExpElement* plunder() &&; + /** + * @copydoc FormalRegExpElement::clone() const + */ + virtual UnboundedRegExpElement* cloneAsUnbounded() const; + FormalRegExpElement* left; FormalRegExpElement* right; diff --git a/alib2data/src/regexp/formal/FormalRegExpElement.h b/alib2data/src/regexp/formal/FormalRegExpElement.h index ee6fb0dea1a333c1cc7f1c58bc92283b64fde487..a5d6240fffd90c173837ecdd2226009108b1fdfb 100644 --- a/alib2data/src/regexp/formal/FormalRegExpElement.h +++ b/alib2data/src/regexp/formal/FormalRegExpElement.h @@ -24,6 +24,8 @@ class FormalRegExpSymbol; class FormalRegExpEmpty; class FormalRegExpEpsilon; +class UnboundedRegExpElement; + /** * Abstract class representing element in the regular expression. Can be operator or symbol. */ @@ -68,6 +70,12 @@ public: virtual FormalRegExpElement* plunder() && = 0; + /** + * Creates copy of the element. + * @return copy of the element + */ + virtual UnboundedRegExpElement* cloneAsUnbounded() const = 0; + virtual ~FormalRegExpElement() noexcept; // RegExpEmpty < RegExpEpsilon < RegExpSymbol < RegExpIteration < RegExpAlternation < RegExpConcatenation diff --git a/alib2data/src/regexp/formal/FormalRegExpEmpty.cpp b/alib2data/src/regexp/formal/FormalRegExpEmpty.cpp index f9ffa8e78ebba4d198343d42df8f6cf55702f99e..17f69d97b82ad1023e31a6bfb5534a7ebe2ebcad 100644 --- a/alib2data/src/regexp/formal/FormalRegExpEmpty.cpp +++ b/alib2data/src/regexp/formal/FormalRegExpEmpty.cpp @@ -6,6 +6,7 @@ */ #include "FormalRegExpEmpty.h" +#include "../unbounded/UnboundedRegExpEmpty.h" namespace regexp { @@ -39,6 +40,10 @@ FormalRegExpElement* FormalRegExpEmpty::plunder() && { return new FormalRegExpEmpty(std::move(*this)); } +UnboundedRegExpElement* FormalRegExpEmpty::cloneAsUnbounded() const { + return new UnboundedRegExpEmpty(); +} + bool FormalRegExpEmpty::operator<(const FormalRegExpElement& other) const { return other > *this; } diff --git a/alib2data/src/regexp/formal/FormalRegExpEmpty.h b/alib2data/src/regexp/formal/FormalRegExpEmpty.h index a34a9823e1c1f59f6d8216af06e5279a6b34f8f7..2416ac97b99ba3b01561657b2b2c42389893d238 100644 --- a/alib2data/src/regexp/formal/FormalRegExpEmpty.h +++ b/alib2data/src/regexp/formal/FormalRegExpEmpty.h @@ -24,6 +24,11 @@ protected: virtual FormalRegExpElement* plunder() &&; + /** + * @copydoc FormalRegExpElement::clone() const + */ + virtual UnboundedRegExpElement* cloneAsUnbounded() const; + /** * @copydoc FormalRegExpElement::testSymbol() const */ diff --git a/alib2data/src/regexp/formal/FormalRegExpEpsilon.cpp b/alib2data/src/regexp/formal/FormalRegExpEpsilon.cpp index dcbabffcb37249d56db61233a80dcf64a8087e86..b434618e3a1e913c9121468d7130a36a55ffe5bb 100644 --- a/alib2data/src/regexp/formal/FormalRegExpEpsilon.cpp +++ b/alib2data/src/regexp/formal/FormalRegExpEpsilon.cpp @@ -6,6 +6,7 @@ */ #include "FormalRegExpEpsilon.h" +#include "../unbounded/UnboundedRegExpEpsilon.h" namespace regexp { @@ -39,6 +40,10 @@ FormalRegExpElement* FormalRegExpEpsilon::plunder() && { return new FormalRegExpEpsilon(std::move(*this)); } +UnboundedRegExpElement* FormalRegExpEpsilon::cloneAsUnbounded() const { + return new UnboundedRegExpEpsilon(); +} + bool FormalRegExpEpsilon::operator<(const FormalRegExpElement& other) const { return other > *this; } diff --git a/alib2data/src/regexp/formal/FormalRegExpEpsilon.h b/alib2data/src/regexp/formal/FormalRegExpEpsilon.h index 44b6721496cb2227b30cf3a0f38e2a1390301f3c..9c510aaf5878ca2ee8840b228be407be6e2f7545 100644 --- a/alib2data/src/regexp/formal/FormalRegExpEpsilon.h +++ b/alib2data/src/regexp/formal/FormalRegExpEpsilon.h @@ -24,6 +24,11 @@ protected: virtual FormalRegExpElement* plunder() &&; + /** + * @copydoc FormalRegExpElement::clone() const + */ + virtual UnboundedRegExpElement* cloneAsUnbounded() const; + /** * @copydoc FormalRegExpElement::testSymbol() const */ diff --git a/alib2data/src/regexp/formal/FormalRegExpIteration.cpp b/alib2data/src/regexp/formal/FormalRegExpIteration.cpp index 6198410e3d3639f1e17cc0444c3440209d779981..6f851535e68efa4b76b557ea763b0c2d3ab6ff8a 100644 --- a/alib2data/src/regexp/formal/FormalRegExpIteration.cpp +++ b/alib2data/src/regexp/formal/FormalRegExpIteration.cpp @@ -8,6 +8,8 @@ #include "FormalRegExpIteration.h" #include "../../exception/AlibException.h" +#include "../unbounded/UnboundedRegExpIteration.h" + namespace regexp { FormalRegExpIteration::FormalRegExpIteration(FormalRegExpElement&& element) : element( NULL ) { @@ -83,6 +85,13 @@ FormalRegExpElement* FormalRegExpIteration::plunder() && { return new FormalRegExpIteration(std::move(*this)); } +UnboundedRegExpElement* FormalRegExpIteration::cloneAsUnbounded() const { + UnboundedRegExpElement* tmp = this->element->cloneAsUnbounded(); + UnboundedRegExpElement* res = new UnboundedRegExpIteration(std::move(*tmp)); + delete tmp; + return res; +} + bool FormalRegExpIteration::operator<(const FormalRegExpElement& other) const { return other > *this; } diff --git a/alib2data/src/regexp/formal/FormalRegExpIteration.h b/alib2data/src/regexp/formal/FormalRegExpIteration.h index db404a7ee1a2eba6d3b5101a403993c7b734ae84..1d3a4110f25a63658dfa675e5ded2d97399a9769 100644 --- a/alib2data/src/regexp/formal/FormalRegExpIteration.h +++ b/alib2data/src/regexp/formal/FormalRegExpIteration.h @@ -28,6 +28,11 @@ protected: virtual FormalRegExpElement* plunder() &&; + /** + * @copydoc FormalRegExpElement::clone() const + */ + virtual UnboundedRegExpElement* cloneAsUnbounded() const; + /** * @copydoc FormalRegExpElement::testSymbol() const */ diff --git a/alib2data/src/regexp/formal/FormalRegExpSymbol.cpp b/alib2data/src/regexp/formal/FormalRegExpSymbol.cpp index 7885ca4e733196fb50aaedff5e563a1b063e529d..3f3ee366665f5ee6effc8aab75e06ee99fbf2b21 100644 --- a/alib2data/src/regexp/formal/FormalRegExpSymbol.cpp +++ b/alib2data/src/regexp/formal/FormalRegExpSymbol.cpp @@ -6,6 +6,7 @@ */ #include "FormalRegExpSymbol.h" +#include "../unbounded/UnboundedRegExpSymbol.h" namespace regexp { @@ -52,6 +53,10 @@ FormalRegExpElement* FormalRegExpSymbol::plunder() && { return new FormalRegExpSymbol(std::move(*this)); } +UnboundedRegExpElement* FormalRegExpSymbol::cloneAsUnbounded() const { + return new UnboundedRegExpSymbol(this->symbol); +} + bool FormalRegExpSymbol::operator==(const alphabet::Symbol& other) const { return this->symbol == other; } diff --git a/alib2data/src/regexp/formal/FormalRegExpSymbol.h b/alib2data/src/regexp/formal/FormalRegExpSymbol.h index 3edb3aed80c5f062dbce9e978d8a9d5e8da51a94..f7c4615e991893a5dd5bc3fe422ee801fd7e7f86 100644 --- a/alib2data/src/regexp/formal/FormalRegExpSymbol.h +++ b/alib2data/src/regexp/formal/FormalRegExpSymbol.h @@ -28,6 +28,11 @@ protected: virtual FormalRegExpElement* plunder() &&; + /** + * @copydoc FormalRegExpElement::clone() const + */ + virtual UnboundedRegExpElement* cloneAsUnbounded() const; + /** * @copydoc FormalRegExpElement::testSymbol() const */ diff --git a/alib2data/src/regexp/unbounded/UnboundedRegExp.cpp b/alib2data/src/regexp/unbounded/UnboundedRegExp.cpp index 3d9f2a010223f39e922dd5a1920448fb15d8d4d9..77ba7a25d18f4d7f959e7257ff83d181013de90b 100644 --- a/alib2data/src/regexp/unbounded/UnboundedRegExp.cpp +++ b/alib2data/src/regexp/unbounded/UnboundedRegExp.cpp @@ -23,6 +23,13 @@ UnboundedRegExp::UnboundedRegExp() { this->regExp = new UnboundedRegExpEmpty(); } +UnboundedRegExp::UnboundedRegExp(const FormalRegExp& other) : alphabet(other.getAlphabet()) { + this->regExp = NULL; + UnboundedRegExpElement* element = other.getRegExp().cloneAsUnbounded(); + setRegExp(std::move(*element)); + delete element; +} + UnboundedRegExp::UnboundedRegExp(const std::set<alphabet::Symbol>& alphabet, const UnboundedRegExpElement& regExp) : alphabet(alphabet) { this->regExp = NULL; setRegExp(regExp); diff --git a/alib2data/src/regexp/unbounded/UnboundedRegExp.h b/alib2data/src/regexp/unbounded/UnboundedRegExp.h index 2812e23334679efa8076c0526e83913ce8774515..ef282ae9f281f19a40fba8dfc6d99041848489f1 100644 --- a/alib2data/src/regexp/unbounded/UnboundedRegExp.h +++ b/alib2data/src/regexp/unbounded/UnboundedRegExp.h @@ -42,6 +42,7 @@ protected: public: UnboundedRegExp(); + explicit UnboundedRegExp(const FormalRegExp& other); UnboundedRegExp(const std::set<alphabet::Symbol>& alphabet, const UnboundedRegExpElement& regExp); UnboundedRegExp(std::set<alphabet::Symbol>&& alphabet, UnboundedRegExpElement&& regExp); explicit UnboundedRegExp(const UnboundedRegExpElement& regExp); diff --git a/alib2data/src/regexp/unbounded/UnboundedRegExpAlternation.cpp b/alib2data/src/regexp/unbounded/UnboundedRegExpAlternation.cpp index 1d3cfd9eafd2081f5cf5196ca30f9cbdda49e032..dad8b817cc0848141243920b5c2f7e473f766879 100644 --- a/alib2data/src/regexp/unbounded/UnboundedRegExpAlternation.cpp +++ b/alib2data/src/regexp/unbounded/UnboundedRegExpAlternation.cpp @@ -7,6 +7,8 @@ #include "UnboundedRegExpAlternation.h" #include "../../exception/AlibException.h" +#include "../formal/FormalRegExpAlternation.h" +#include "../formal/FormalRegExpEmpty.h" namespace regexp { @@ -81,6 +83,30 @@ UnboundedRegExpElement* UnboundedRegExpAlternation::plunder() && { return new UnboundedRegExpAlternation(std::move(*this)); } +FormalRegExpElement* UnboundedRegExpAlternation::cloneAsFormal() const { + if(elements.size() == 0) return new FormalRegExpEmpty(); + if(elements.size() == 1) return elements[0]->cloneAsFormal(); + + int size = elements.size(); + FormalRegExpElement* rightTmp = elements[--size]->cloneAsFormal(); + FormalRegExpElement* leftTmp = elements[--size]->cloneAsFormal(); + + FormalRegExpAlternation* res = new FormalRegExpAlternation(std::move(*leftTmp), std::move(*rightTmp)); + delete rightTmp; + delete leftTmp; + + while(size) { + FormalRegExpElement* tmp = res; + FormalRegExpElement* newLeft = elements[--size]->cloneAsFormal(); + + res = new FormalRegExpAlternation(std::move(*newLeft), std::move(*tmp)); + delete tmp; + delete newLeft; + } + + return res; +} + bool UnboundedRegExpAlternation::operator<(const UnboundedRegExpElement& other) const { return other > *this; } diff --git a/alib2data/src/regexp/unbounded/UnboundedRegExpAlternation.h b/alib2data/src/regexp/unbounded/UnboundedRegExpAlternation.h index 1e51660957e0c58cb6768cb9ae7dbf6b2602c60b..e6a2fb21a386075ab0bd9d6e22eb8a18c61ec52d 100644 --- a/alib2data/src/regexp/unbounded/UnboundedRegExpAlternation.h +++ b/alib2data/src/regexp/unbounded/UnboundedRegExpAlternation.h @@ -24,6 +24,11 @@ protected: */ virtual UnboundedRegExpElement* clone() const; + /** + * @copydoc UnboundedRegExpElement::cloneAsFormal() const + */ + virtual FormalRegExpElement* cloneAsFormal() const; + /** * @copydoc UnboundedRegExpElement::plunder() const */ diff --git a/alib2data/src/regexp/unbounded/UnboundedRegExpConcatenation.cpp b/alib2data/src/regexp/unbounded/UnboundedRegExpConcatenation.cpp index bcf2c137425c42b4734ddb738f27662e06fcae16..bcbe39ad3f835ae6e6d6ee019c37228ca02d4d38 100644 --- a/alib2data/src/regexp/unbounded/UnboundedRegExpConcatenation.cpp +++ b/alib2data/src/regexp/unbounded/UnboundedRegExpConcatenation.cpp @@ -7,6 +7,8 @@ #include "UnboundedRegExpConcatenation.h" #include "../../exception/AlibException.h" +#include "../formal/FormalRegExpConcatenation.h" +#include "../formal/FormalRegExpEpsilon.h" namespace regexp { @@ -80,6 +82,30 @@ UnboundedRegExpElement* UnboundedRegExpConcatenation::plunder() && { return new UnboundedRegExpConcatenation(std::move(*this)); } +FormalRegExpElement* UnboundedRegExpConcatenation::cloneAsFormal() const { + if(elements.size() == 0) return new FormalRegExpEpsilon(); + if(elements.size() == 1) return elements[0]->cloneAsFormal(); + + int size = elements.size(); + FormalRegExpElement* rightTmp = elements[--size]->cloneAsFormal(); + FormalRegExpElement* leftTmp = elements[--size]->cloneAsFormal(); + + FormalRegExpConcatenation* res = new FormalRegExpConcatenation(std::move(*leftTmp), std::move(*rightTmp)); + delete rightTmp; + delete leftTmp; + + while(size) { + FormalRegExpElement* tmp = res; + FormalRegExpElement* newLeft = elements[--size]->cloneAsFormal(); + + res = new FormalRegExpConcatenation(std::move(*newLeft), std::move(*tmp)); + delete tmp; + delete newLeft; + } + + return res; +} + bool UnboundedRegExpConcatenation::operator<(const UnboundedRegExpElement& other) const { return other > *this; } diff --git a/alib2data/src/regexp/unbounded/UnboundedRegExpConcatenation.h b/alib2data/src/regexp/unbounded/UnboundedRegExpConcatenation.h index bf318442565b27afb5243c0034e9fa260f364f97..aee2fe4d21aa3f5c6df8c4abb9a8ff1d4a764d7b 100644 --- a/alib2data/src/regexp/unbounded/UnboundedRegExpConcatenation.h +++ b/alib2data/src/regexp/unbounded/UnboundedRegExpConcatenation.h @@ -23,7 +23,12 @@ protected: * @copydoc UnboundedRegExpElement::clone() const */ virtual UnboundedRegExpElement* clone() const; - + + /** + * @copydoc UnboundedRegExpElement::cloneAsFormal() const + */ + virtual FormalRegExpElement* cloneAsFormal() const; + virtual UnboundedRegExpElement* plunder() &&; std::vector<UnboundedRegExpElement*> elements; diff --git a/alib2data/src/regexp/unbounded/UnboundedRegExpElement.h b/alib2data/src/regexp/unbounded/UnboundedRegExpElement.h index 00ee179a21a94527ab1bf1b73b14db1adae7c0c7..160f3ca5ccb53f33b2e44d1515466a8d0d53dc51 100644 --- a/alib2data/src/regexp/unbounded/UnboundedRegExpElement.h +++ b/alib2data/src/regexp/unbounded/UnboundedRegExpElement.h @@ -24,12 +24,14 @@ class UnboundedRegExpSymbol; class UnboundedRegExpEmpty; class UnboundedRegExpEpsilon; +class FormalRegExpElement; + /** * Abstract class representing element in the regular expression. Can be operator or symbol. */ class UnboundedRegExpElement : public std::elementBase<UnboundedRegExpAlternation, UnboundedRegExpConcatenation, UnboundedRegExpIteration, UnboundedRegExpSymbol, UnboundedRegExpEmpty, UnboundedRegExpEpsilon> { protected: - /* + /** * Parent regexp contanining this instance of RegExpElement */ const UnboundedRegExp * parentRegExp; @@ -68,6 +70,12 @@ public: virtual UnboundedRegExpElement* plunder() && = 0; + /** + * Creates copy of the element. + * @return copy of the element + */ + virtual FormalRegExpElement* cloneAsFormal() const = 0; + virtual ~UnboundedRegExpElement() noexcept; // RegExpEmpty < RegExpEpsilon < RegExpSymbol < RegExpIteration < RegExpAlternation < RegExpConcatenation diff --git a/alib2data/src/regexp/unbounded/UnboundedRegExpEmpty.cpp b/alib2data/src/regexp/unbounded/UnboundedRegExpEmpty.cpp index 23bbd113008e5efd1e81069355dba12b9a54db9b..d5d2c73f6fbb0b2b4b5156fc4017e32ed973d5b3 100644 --- a/alib2data/src/regexp/unbounded/UnboundedRegExpEmpty.cpp +++ b/alib2data/src/regexp/unbounded/UnboundedRegExpEmpty.cpp @@ -6,6 +6,7 @@ */ #include "UnboundedRegExpEmpty.h" +#include "../formal/FormalRegExpEmpty.h" namespace regexp { @@ -39,6 +40,10 @@ UnboundedRegExpElement* UnboundedRegExpEmpty::plunder() && { return new UnboundedRegExpEmpty(std::move(*this)); } +FormalRegExpElement* UnboundedRegExpEmpty::cloneAsFormal() const { + return new FormalRegExpEmpty(); +} + bool UnboundedRegExpEmpty::operator<(const UnboundedRegExpElement& other) const { return other > *this; } diff --git a/alib2data/src/regexp/unbounded/UnboundedRegExpEmpty.h b/alib2data/src/regexp/unbounded/UnboundedRegExpEmpty.h index 598d4a56efac6e71c96c7b55560642f0f5ea4375..e5466db10d8124c04a857374b172f499ac2482f3 100644 --- a/alib2data/src/regexp/unbounded/UnboundedRegExpEmpty.h +++ b/alib2data/src/regexp/unbounded/UnboundedRegExpEmpty.h @@ -24,6 +24,11 @@ protected: virtual UnboundedRegExpElement* plunder() &&; + /** + * @copydoc UnboundedRegExpElement::cloneAsFormal() const + */ + virtual FormalRegExpElement* cloneAsFormal() const; + /** * @copydoc UnboundedRegExpElement::testSymbol() const */ diff --git a/alib2data/src/regexp/unbounded/UnboundedRegExpEpsilon.cpp b/alib2data/src/regexp/unbounded/UnboundedRegExpEpsilon.cpp index 10544081928510e34f654f8abec088112d993be9..706b4c455a76ca35a62c64f7f33a2276f65b2ecc 100644 --- a/alib2data/src/regexp/unbounded/UnboundedRegExpEpsilon.cpp +++ b/alib2data/src/regexp/unbounded/UnboundedRegExpEpsilon.cpp @@ -6,6 +6,7 @@ */ #include "UnboundedRegExpEpsilon.h" +#include "../formal/FormalRegExpEpsilon.h" namespace regexp { @@ -30,7 +31,7 @@ UnboundedRegExpEpsilon& UnboundedRegExpEpsilon::operator =(UnboundedRegExpEpsilo //this is actually different than default implementation return *this; } - + UnboundedRegExpElement* UnboundedRegExpEpsilon::clone() const { return new UnboundedRegExpEpsilon(*this); } @@ -39,6 +40,10 @@ UnboundedRegExpElement* UnboundedRegExpEpsilon::plunder() && { return new UnboundedRegExpEpsilon(std::move(*this)); } +FormalRegExpElement* UnboundedRegExpEpsilon::cloneAsFormal() const { + return new FormalRegExpEpsilon(); +} + bool UnboundedRegExpEpsilon::operator<(const UnboundedRegExpElement& other) const { return other > *this; } diff --git a/alib2data/src/regexp/unbounded/UnboundedRegExpEpsilon.h b/alib2data/src/regexp/unbounded/UnboundedRegExpEpsilon.h index d69f3f6701bc302df16a65ec42c1651d910e45a0..61f6f5ef77a2fbc34d334f70507c72e14549a0aa 100644 --- a/alib2data/src/regexp/unbounded/UnboundedRegExpEpsilon.h +++ b/alib2data/src/regexp/unbounded/UnboundedRegExpEpsilon.h @@ -24,6 +24,11 @@ protected: virtual UnboundedRegExpElement* plunder() &&; + /** + * @copydoc UnboundedRegExpElement::cloneAsFormal() const + */ + virtual FormalRegExpElement* cloneAsFormal() const; + /** * @copydoc UnboundedRegExpElement::testSymbol() const */ diff --git a/alib2data/src/regexp/unbounded/UnboundedRegExpIteration.cpp b/alib2data/src/regexp/unbounded/UnboundedRegExpIteration.cpp index 9e2322a0cf6b205a5344391c8b1bcf83f79c5735..7788d970ed60370fdf8789dd906914edf4fd354b 100644 --- a/alib2data/src/regexp/unbounded/UnboundedRegExpIteration.cpp +++ b/alib2data/src/regexp/unbounded/UnboundedRegExpIteration.cpp @@ -8,6 +8,8 @@ #include "UnboundedRegExpIteration.h" #include "../../exception/AlibException.h" +#include "../formal/FormalRegExpIteration.h" + namespace regexp { UnboundedRegExpIteration::UnboundedRegExpIteration(UnboundedRegExpElement&& element) : element( NULL ) { @@ -83,6 +85,13 @@ UnboundedRegExpElement* UnboundedRegExpIteration::plunder() && { return new UnboundedRegExpIteration(std::move(*this)); } +FormalRegExpElement* UnboundedRegExpIteration::cloneAsFormal() const { + FormalRegExpElement* tmp = this->element->cloneAsFormal(); + FormalRegExpElement* res = new FormalRegExpIteration(std::move(*tmp)); + delete tmp; + return res; +} + bool UnboundedRegExpIteration::operator<(const UnboundedRegExpElement& other) const { return other > *this; } diff --git a/alib2data/src/regexp/unbounded/UnboundedRegExpIteration.h b/alib2data/src/regexp/unbounded/UnboundedRegExpIteration.h index 7a8fe4e3ace30aab2ce5383474346c3c880abaa9..b16ddbbc222f35f713c09dccb966d806be19e23c 100644 --- a/alib2data/src/regexp/unbounded/UnboundedRegExpIteration.h +++ b/alib2data/src/regexp/unbounded/UnboundedRegExpIteration.h @@ -28,6 +28,11 @@ protected: virtual UnboundedRegExpElement* plunder() &&; + /** + * @copydoc UnboundedRegExpElement::cloneAsFormal() const + */ + virtual FormalRegExpElement* cloneAsFormal() const; + /** * @copydoc UnboundedRegExpElement::testSymbol() const */ diff --git a/alib2data/src/regexp/unbounded/UnboundedRegExpSymbol.cpp b/alib2data/src/regexp/unbounded/UnboundedRegExpSymbol.cpp index 268abb7585d6b299126249b29dcfea29d1642b63..312bc642db3bf9d53848653a3ed9d2e303046adb 100644 --- a/alib2data/src/regexp/unbounded/UnboundedRegExpSymbol.cpp +++ b/alib2data/src/regexp/unbounded/UnboundedRegExpSymbol.cpp @@ -6,6 +6,7 @@ */ #include "UnboundedRegExpSymbol.h" +#include "../formal/FormalRegExpSymbol.h" namespace regexp { @@ -52,6 +53,10 @@ UnboundedRegExpElement* UnboundedRegExpSymbol::plunder() && { return new UnboundedRegExpSymbol(std::move(*this)); } +FormalRegExpElement* UnboundedRegExpSymbol::cloneAsFormal() const { + return new FormalRegExpSymbol(this->symbol); +} + bool UnboundedRegExpSymbol::operator==(const alphabet::Symbol& other) const { return this->symbol == other; } diff --git a/alib2data/src/regexp/unbounded/UnboundedRegExpSymbol.h b/alib2data/src/regexp/unbounded/UnboundedRegExpSymbol.h index f282d312c6df358c4a8eb810c74dea03afa635b9..fd30fd2447b381ded96532c8766bb7eb6de54b09 100644 --- a/alib2data/src/regexp/unbounded/UnboundedRegExpSymbol.h +++ b/alib2data/src/regexp/unbounded/UnboundedRegExpSymbol.h @@ -28,6 +28,11 @@ protected: virtual UnboundedRegExpElement* plunder() &&; + /** + * @copydoc UnboundedRegExpElement::cloneAsFormal() const + */ + virtual FormalRegExpElement* cloneAsFormal() const; + /** * @copydoc UnboundedRegExpElement::testSymbol() const */