diff --git a/alib2/src/string/StringFeatures.h b/alib2/src/string/StringFeatures.h new file mode 100644 index 0000000000000000000000000000000000000000..b3aba2adde7ece40032fff11e15b7ad2a7a589d2 --- /dev/null +++ b/alib2/src/string/StringFeatures.h @@ -0,0 +1,21 @@ +/* + * StringFeatures.h + * + * Created on: Jun 19, 2014 + * Author: Jan Travnicek + */ + +#ifndef STRING_FEATURES_H_ +#define STRING_FEATURES_H_ + +namespace string { + +enum class FEATURES { + LINEAR, + CYCLIC, + EPSILON +}; + +} /* namespace string */ + +#endif /* STRING_FEATURES_H_ */ diff --git a/alib2/src/string/StringFromStringParser.cpp b/alib2/src/string/StringFromStringParser.cpp index 84c127dffd206241d3f872eda41cf76494d1ba2c..d57e0e8d365423238e185d1f5c4394654bb3596c 100644 --- a/alib2/src/string/StringFromStringParser.cpp +++ b/alib2/src/string/StringFromStringParser.cpp @@ -14,10 +14,16 @@ StringFromStringParser::StringFromStringParser(std::stringstream& input) : m_Str } String StringFromStringParser::parse() { + return parse(std::set<FEATURES>({FEATURES::LINEAR, FEATURES::CYCLIC, FEATURES::EPSILON})); +} + +String StringFromStringParser::parse(const std::set<FEATURES>& features) { StringFromStringLexer::Token token = m_StringLexer.token(); if(token.type == StringFromStringLexer::TokenType::EPSILON) { + if(!features.count(FEATURES::EPSILON)) throw alib::AlibException(); return String(Epsilon()); } else if(token.type == StringFromStringLexer::TokenType::LESS) { + if(!features.count(FEATURES::CYCLIC)) throw alib::AlibException(); std::vector<alphabet::Symbol> data = parseContent(); if(token.type == StringFromStringLexer::TokenType::GREATER) { return String(CyclicString(data)); @@ -25,6 +31,7 @@ String StringFromStringParser::parse() { throw alib::AlibException(); } } else if(token.type == StringFromStringLexer::TokenType::QUOTE) { + if(!features.count(FEATURES::LINEAR)) throw alib::AlibException(); std::vector<alphabet::Symbol> data = parseContent(); if(token.type == StringFromStringLexer::TokenType::QUOTE) { return String(LinearString(data)); diff --git a/alib2/src/string/StringFromStringParser.h b/alib2/src/string/StringFromStringParser.h index 04935b2121ed8f8874018b93aa3228c8d85e08df..9f1fc4e1c329f2960b653a69d0e1ffa197d649a7 100644 --- a/alib2/src/string/StringFromStringParser.h +++ b/alib2/src/string/StringFromStringParser.h @@ -9,6 +9,7 @@ #define STRING_FROM_STRING_PARSER_H_ #include "String.h" +#include "StringFeatures.h" #include <vector> #include "../alphabet/Symbol.h" @@ -24,6 +25,7 @@ class StringFromStringParser { alphabet::SymbolFromStringParser m_SymbolParser; String parse(); + String parse(const std::set<FEATURES>& features); String* parsePointer(); public: StringFromStringParser(std::stringstream&); diff --git a/alib2/src/string/StringFromXMLParser.cpp b/alib2/src/string/StringFromXMLParser.cpp index 3da9e1b5661a3b1fe09235f8db94e720f2cba928..325f71b9fca45f268c7ea195453d21baa7e65780 100644 --- a/alib2/src/string/StringFromXMLParser.cpp +++ b/alib2/src/string/StringFromXMLParser.cpp @@ -16,28 +16,35 @@ namespace string { String StringFromXMLParser::parse(std::list<sax::Token>& input) const { + return parse(input, std::set<FEATURES>({FEATURES::LINEAR, FEATURES::CYCLIC, FEATURES::EPSILON})); +} + +String StringFromXMLParser::parse(std::list<sax::Token>& input, const std::set<FEATURES>& features) const { popToken(input, sax::Token::TokenType::START_ELEMENT, "string"); String string; parseAlphabet(input, string); - parseContent(input, string); + parseContent(input, string, features); popToken(input, sax::Token::TokenType::END_ELEMENT, "string"); return string; } -void StringFromXMLParser::parseContent(std::list<sax::Token>& input, String& string) const { +void StringFromXMLParser::parseContent(std::list<sax::Token>& input, String& string, const std::set<FEATURES>& features) const { if(isToken(input, sax::Token::TokenType::START_ELEMENT, "Epsilon")) { + if(!features.count(FEATURES::EPSILON)) throw alib::AlibException(); popToken(input, sax::Token::TokenType::START_ELEMENT, "Epsilon"); popToken(input, sax::Token::TokenType::END_ELEMENT, "Epsilon"); string.setString(Epsilon()); } else if(isToken(input, sax::Token::TokenType::START_ELEMENT, "LinearString")) { + if(!features.count(FEATURES::LINEAR)) throw alib::AlibException(); popToken(input, sax::Token::TokenType::START_ELEMENT, "LinearString"); std::vector<alphabet::Symbol> data = parseContentData(input); popToken(input, sax::Token::TokenType::END_ELEMENT, "LinearString"); string.setString(LinearString(data)); } else if(isToken(input, sax::Token::TokenType::START_ELEMENT, "CyclicString")) { + if(!features.count(FEATURES::CYCLIC)) throw alib::AlibException(); popToken(input, sax::Token::TokenType::START_ELEMENT, "CyclicString"); std::vector<alphabet::Symbol> data = parseContentData(input); popToken(input, sax::Token::TokenType::END_ELEMENT, "CyclicString"); diff --git a/alib2/src/string/StringFromXMLParser.h b/alib2/src/string/StringFromXMLParser.h index 66301d28638312962505468cb7110cc942907bdb..9ed0008fa4500e6de2bc5f637649650779cbd801 100644 --- a/alib2/src/string/StringFromXMLParser.h +++ b/alib2/src/string/StringFromXMLParser.h @@ -10,7 +10,9 @@ #include "../sax/FromXMLParser.h" #include <vector> +#include <set> #include "String.h" +#include "StringFeatures.h" #include "../sax/Token.h" #include "../alphabet/Symbol.h" @@ -20,11 +22,12 @@ namespace string { * Parser used to get String from XML parsed into list of tokens. */ class StringFromXMLParser : public sax::FromXMLParser { - void parseContent(std::list<sax::Token>& input, String& string) const; + void parseContent(std::list<sax::Token>& input, String& string, const std::set<FEATURES>& features) const; std::vector<alphabet::Symbol> parseContentData(std::list<sax::Token>& input) const; void parseAlphabet(std::list<sax::Token> &input, String& string) const; String parse(std::list<sax::Token>& input) const; + String parse(std::list<sax::Token>& input, const std::set<FEATURES>& features) const; String* parsePointer(std::list<sax::Token>& input) const; public: /**