diff --git a/alib2algo/src/trim/automaton/TrimFSM.cpp b/alib2algo/src/trim/automaton/TrimFSM.cpp index 980f8fb3fb0648b61e828c8e58f2604efe57336b..b0d426827df9c512df8729b4a5522788fe803e01 100644 --- a/alib2algo/src/trim/automaton/TrimFSM.cpp +++ b/alib2algo/src/trim/automaton/TrimFSM.cpp @@ -43,7 +43,7 @@ T TrimFSM::removeUselessStates( const T & fsm ) { for( const auto & t : fsm.getTransitions( ) ) for( const auto & to : t.second ) - if( /* TODO test this Qu.count(t.first.first) ) && */ Qu.count(to) ) + if( /* this part is not needed Qu.count(t.first.first) ) && */ Qu.count(to) ) M.addTransition( t.first.first, t.first.second, to ); for( const auto & q : fsm.getInitialStates( ) ) @@ -80,7 +80,7 @@ automaton::DFA TrimFSM::removeUselessStates( const automaton::DFA & fsm ) { M.addInputSymbol( a ); for( const auto & t : fsm.getTransitions( ) ) - if( /* TODO test this Qu.count( t.first.first ) && */ Qu.count( t.second ) ) + if( /* this part is not needed Qu.count( t.first.first ) && */ Qu.count( t.second ) ) M.addTransition( t.first.first, t.first.second, t.second ); for( const auto & q : fsm.getFinalStates( ) ) diff --git a/alib2data/src/Api.cpp b/alib2data/src/Api.cpp index bc951570b7828a0ff35eda2c5217c05395f9515d..3d959053520525bc018a947dc238aa1f4c9e1bd5 100644 --- a/alib2data/src/Api.cpp +++ b/alib2data/src/Api.cpp @@ -33,6 +33,14 @@ const primitive::PrimitiveToXMLComposer ToXMLComposers::primitiveComposer; const ToXMLComposers ToXMLComposers::toXMLComposers; +Void api<Void>::parse(std::list<sax::Token>& input) { + return FromXMLParsers::objectParser.parseVoid(input); +} + +std::list<sax::Token> api<Void>::compose(const Void& data) { + return ToXMLComposers::objectComposer.compose(data); +} + container::Container api<container::Container>::parse(std::list<sax::Token>& input) { return FromXMLParsers::containerParser.parseContainer(input); } @@ -520,6 +528,10 @@ std::list<sax::Token> api<primitive::Character>::compose(const primitive::Charac } +void ToXMLComposers::Visit(void* data, const Void& voidObject) const { + *((std::list<sax::Token>*) data) = std::move(api<Void>::compose(voidObject)); +} + void ToXMLComposers::Visit(void* data, const container::ObjectsSet& container) const { *((std::list<sax::Token>*) data) = std::move(api<container::ObjectsSet>::compose(container)); } diff --git a/alib2data/src/Api.hpp b/alib2data/src/Api.hpp index 9fa47bb61f1b3bd31a0e317e2617b88b5dd766cd..e8dd119aad04a124893ef0c5ea35765d5717a0cf 100644 --- a/alib2data/src/Api.hpp +++ b/alib2data/src/Api.hpp @@ -38,6 +38,12 @@ struct api { static std::list<sax::Token> compose(const T& data); }; +template<> +struct api<Void> { + static Void parse(std::list<sax::Token>& input); + static std::list<sax::Token> compose(const Void& data); +}; + template<typename T> struct api<std::set<T>> { static std::set<T> parse(std::list<sax::Token>& input); @@ -458,6 +464,8 @@ public: }; class ToXMLComposers : public VisitableObjectBase::const_visitor_type { + void Visit(void*, const Void& voidObject) const; + void Visit(void*, const exception::AlibException& symbol) const; void Visit(void*, const alphabet::LabeledSymbol& symbol) const; diff --git a/alib2data/src/object/ObjectBase.h b/alib2data/src/object/ObjectBase.h index 3f8e1e127ce2de96ad462055bcc0491ed8b5e070..9063b6d5c2b69d5cdf8e107b0903602f775075dc 100644 --- a/alib2data/src/object/ObjectBase.h +++ b/alib2data/src/object/ObjectBase.h @@ -11,6 +11,12 @@ #include "../std/visitor.hpp" #include "../common/base.hpp" +namespace alib { + +class Void; + +} + namespace exception { class AlibException; @@ -109,6 +115,7 @@ class Character; namespace alib { typedef std::acceptor_base< + Void, exception::AlibException, automaton::UnknownAutomaton, automaton::DFA, automaton::NFA, automaton::EpsilonNFA, automaton::CompactNFA, automaton::ExtendedNFA, automaton::DPDA, automaton::SinglePopDPDA, automaton::InputDrivenNPDA, automaton::VisiblyPushdownNPDA, automaton::RealTimeHeightDeterministicNPDA, automaton::NPDA, automaton::SinglePopNPDA, automaton::OneTapeDTM, grammar::UnknownGrammar, grammar::LeftLG, grammar::LeftRG, grammar::RightLG, grammar::RightRG, grammar::LG, grammar::CFG, grammar::EpsilonFreeCFG, grammar::CNF, grammar::GNF, grammar::CSG, grammar::NonContractingGrammar, grammar::ContextPreservingUnrestrictedGrammar, grammar::UnrestrictedGrammar, @@ -123,6 +130,7 @@ typedef std::acceptor_base< class ObjectBase : public alib::base< ObjectBase, + Void, exception::AlibException, automaton::UnknownAutomaton, automaton::DFA, automaton::NFA, automaton::EpsilonNFA, automaton::CompactNFA, automaton::ExtendedNFA, automaton::DPDA, automaton::SinglePopDPDA, automaton::InputDrivenNPDA, automaton::VisiblyPushdownNPDA, automaton::RealTimeHeightDeterministicNPDA, automaton::NPDA, automaton::SinglePopNPDA, automaton::OneTapeDTM, grammar::UnknownGrammar, grammar::LeftLG, grammar::LeftRG, grammar::RightLG, grammar::RightRG, grammar::LG, grammar::CFG, grammar::EpsilonFreeCFG, grammar::CNF, grammar::GNF, grammar::CSG, grammar::NonContractingGrammar, grammar::ContextPreservingUnrestrictedGrammar, grammar::UnrestrictedGrammar, diff --git a/alib2data/src/object/ObjectFromXMLParser.cpp b/alib2data/src/object/ObjectFromXMLParser.cpp index 45b138cb6c0b8c7c247f49cca33dc9a75b1ba9db..ce15e1d98ccb6c4c8a0126586a62fd061e5f0337 100644 --- a/alib2data/src/object/ObjectFromXMLParser.cpp +++ b/alib2data/src/object/ObjectFromXMLParser.cpp @@ -51,13 +51,23 @@ Object ObjectFromXMLParser::parseObject(std::list<sax::Token>& input) const { primitive::Primitive primitive = alib::api<primitive::Primitive>::parse(input); Object res(std::move(primitive.getData())); return res; + } else if(isToken(input, sax::Token::TokenType::START_ELEMENT, "Void")) { + Object res(std::move(parseVoid(input))); + return res; } else { throw exception::AlibException("Unknown element in xml"); } } +Void ObjectFromXMLParser::parseVoid(std::list<sax::Token>& input) const { + popToken(input, sax::Token::TokenType::START_ELEMENT, "Void"); + popToken(input, sax::Token::TokenType::END_ELEMENT, "Void"); + + return {}; +} + bool ObjectFromXMLParser::first(std::list<sax::Token>& input) { - return alib::FromXMLParsers::symbolParser.first(input) || alib::FromXMLParsers::exceptionParser.first(input) || alib::FromXMLParsers::labelParser.first(input) || alib::FromXMLParsers::regexpParser.first(input) || alib::FromXMLParsers::stringParser.first(input) || alib::FromXMLParsers::automatonParser.first(input) || alib::FromXMLParsers::grammarParser.first(input) || alib::FromXMLParsers::containerParser.first(input); + return alib::FromXMLParsers::symbolParser.first(input) || alib::FromXMLParsers::exceptionParser.first(input) || alib::FromXMLParsers::labelParser.first(input) || alib::FromXMLParsers::regexpParser.first(input) || alib::FromXMLParsers::stringParser.first(input) || alib::FromXMLParsers::automatonParser.first(input) || alib::FromXMLParsers::grammarParser.first(input) || alib::FromXMLParsers::containerParser.first(input) || isToken(input, sax::Token::TokenType::START_ELEMENT, "Void"); } } /* namespace alib */ diff --git a/alib2data/src/object/ObjectFromXMLParser.h b/alib2data/src/object/ObjectFromXMLParser.h index 6946756c2a2ce71f28cce712b55266604cb15c23..f2b0637bcea6f6ccee02e03023198f97cc2d22d1 100644 --- a/alib2data/src/object/ObjectFromXMLParser.h +++ b/alib2data/src/object/ObjectFromXMLParser.h @@ -28,10 +28,11 @@ namespace alib { */ class ObjectFromXMLParser : public sax::FromXMLParserHelper { Object parseObject(std::list<sax::Token>& input) const; + Void parseVoid(std::list<sax::Token>& input) const; template<typename T> friend class alib::api; public: - static bool first(std::list<sax::Token>& input); + bool first(std::list<sax::Token>& input); }; } /* namespace alib */ diff --git a/alib2data/src/object/ObjectToXMLComposer.cpp b/alib2data/src/object/ObjectToXMLComposer.cpp index 97bedbf9af2f0b9370160908324301b78d70191c..0fc9252f2d3971e42aa7b35ac3c2fff38ddbeccb 100644 --- a/alib2data/src/object/ObjectToXMLComposer.cpp +++ b/alib2data/src/object/ObjectToXMLComposer.cpp @@ -17,6 +17,13 @@ std::list<sax::Token> ObjectToXMLComposer::compose(const Object& object) const { return out; } +std::list<sax::Token> ObjectToXMLComposer::compose(const Void&) const { + std::list<sax::Token> out; + out.push_back(sax::Token("Void", sax::Token::TokenType::START_ELEMENT)); + out.push_back(sax::Token("Void", sax::Token::TokenType::END_ELEMENT)); + return out; +} + std::list<sax::Token> ObjectToXMLComposer::compose(const ObjectBase& object) const { std::list<sax::Token> out; object.Accept((void*) &out, alib::ToXMLComposers::toXMLComposers); diff --git a/alib2data/src/object/ObjectToXMLComposer.h b/alib2data/src/object/ObjectToXMLComposer.h index 23c69b5380c874daa92b19c9fcb2799f52246b77..ac298206ca597ac0d48cd8b3d65760c37c87ad97 100644 --- a/alib2data/src/object/ObjectToXMLComposer.h +++ b/alib2data/src/object/ObjectToXMLComposer.h @@ -10,6 +10,7 @@ #include <list> #include "Object.h" +#include "Void.h" #include "../sax/Token.h" #include "../label/Label.h" @@ -40,6 +41,13 @@ class ObjectToXMLComposer { */ std::list<sax::Token> compose(const Object& object) const; + /** + * Prints XML representation of String to the output stream. + * @param string String to print + * @param out output stream to which print the String + */ + std::list<sax::Token> compose(const Void& voidObject) const; + template<typename T> friend class alib::api; };