From f5612801a77231d1cc7a4649279abbbbdbf1746f Mon Sep 17 00:00:00 2001 From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz> Date: Sat, 28 Jun 2014 09:43:09 +0200 Subject: [PATCH] Features of symbols --- alib2/src/alphabet/SymbolFeatures.h | 8 ++++---- alib2/src/alphabet/SymbolFromStringParser.cpp | 8 ++++++++ alib2/src/alphabet/SymbolFromStringParser.h | 2 ++ alib2/src/alphabet/SymbolFromXMLParser.cpp | 8 ++++++++ alib2/src/alphabet/SymbolFromXMLParser.h | 3 +++ 5 files changed, 25 insertions(+), 4 deletions(-) diff --git a/alib2/src/alphabet/SymbolFeatures.h b/alib2/src/alphabet/SymbolFeatures.h index a7743c9b36..f1d1db6871 100644 --- a/alib2/src/alphabet/SymbolFeatures.h +++ b/alib2/src/alphabet/SymbolFeatures.h @@ -1,12 +1,12 @@ /* - * LabelFeatures.h + * SymbolFeatures.h * * Created on: Jun 19, 2014 * Author: Jan Travnicek */ -#ifndef LABEL_FEATURES_H_ -#define LABEL_FEATURES_H_ +#ifndef SYMBOL_FEATURES_H_ +#define SYMBOL_FEATURES_H_ namespace alphabet { @@ -19,4 +19,4 @@ enum class FEATURES { } /* namespace label */ -#endif /* LABEL_FEATURES_H_ */ +#endif /* SYMBOL_FEATURES_H_ */ diff --git a/alib2/src/alphabet/SymbolFromStringParser.cpp b/alib2/src/alphabet/SymbolFromStringParser.cpp index 28f0f16ae2..6ef1a26384 100644 --- a/alib2/src/alphabet/SymbolFromStringParser.cpp +++ b/alib2/src/alphabet/SymbolFromStringParser.cpp @@ -12,15 +12,23 @@ SymbolFromStringParser::SymbolFromStringParser(std::stringstream& input) : m_Sym } Symbol SymbolFromStringParser::parse() { + return parse(std::set<FEATURES>({FEATURES::LABELED, FEATURES::BLANK, FEATURES::BOTTOM, FEATURES::END})); +} + +Symbol SymbolFromStringParser::parse(const std::set<FEATURES>& features) { SymbolFromStringLexer::Token token = m_SymbolLexer.token(); switch(token.type) { case SymbolFromStringLexer::TokenType::BLANK: + if(!features.count(FEATURES::BLANK)) throw alib::AlibException(); return Symbol(BlankSymbol()); case SymbolFromStringLexer::TokenType::BOTTOM: + if(!features.count(FEATURES::BOTTOM)) throw alib::AlibException(); return Symbol(BottomOfTheStackSymbol()); case SymbolFromStringLexer::TokenType::END: + if(!features.count(FEATURES::END)) throw alib::AlibException(); return Symbol(EndSymbol()); case SymbolFromStringLexer::TokenType::ERROR: + if(!features.count(FEATURES::LABELED)) throw alib::AlibException(); return Symbol(LabeledSymbol(m_LabelParser.parse())); case SymbolFromStringLexer::TokenType::TEOF: throw alib::AlibException(); diff --git a/alib2/src/alphabet/SymbolFromStringParser.h b/alib2/src/alphabet/SymbolFromStringParser.h index 6115aef72d..cd3d46cd6b 100644 --- a/alib2/src/alphabet/SymbolFromStringParser.h +++ b/alib2/src/alphabet/SymbolFromStringParser.h @@ -13,6 +13,7 @@ #include "SymbolFromStringLexer.h" #include "../label/LabelFromStringParser.h" +#include "SymbolFeatures.h" namespace string { @@ -35,6 +36,7 @@ class SymbolFromStringParser { label::LabelFromStringParser m_LabelParser; Symbol* parsePointer(); Symbol parse(); + Symbol parse(const std::set<FEATURES>& features); public: SymbolFromStringParser(std::stringstream&); Symbol parseValue(); diff --git a/alib2/src/alphabet/SymbolFromXMLParser.cpp b/alib2/src/alphabet/SymbolFromXMLParser.cpp index 6ef74c5c3d..bd4226ffba 100644 --- a/alib2/src/alphabet/SymbolFromXMLParser.cpp +++ b/alib2/src/alphabet/SymbolFromXMLParser.cpp @@ -19,13 +19,21 @@ namespace alphabet { Symbol SymbolFromXMLParser::parse(std::list<sax::Token>& input) const { + return parse(input, std::set<FEATURES>({FEATURES::LABELED, FEATURES::BLANK, FEATURES::BOTTOM, FEATURES::END})); +} + +Symbol SymbolFromXMLParser::parse(std::list<sax::Token>& input, const std::set<FEATURES>& features) const { if(isToken(input, sax::Token::TokenType::START_ELEMENT, "LabeledSymbol")) { + if(!features.count(FEATURES::LABELED)) throw alib::AlibException(); return parseLabeledSymbol(input); } else if(isToken(input, sax::Token::TokenType::START_ELEMENT, "BlankSymbol")) { + if(!features.count(FEATURES::BLANK)) throw alib::AlibException(); return parseBlankSymbol(input); } else if(isToken(input, sax::Token::TokenType::START_ELEMENT, "BottomOfTheStackSymbol")) { + if(!features.count(FEATURES::BOTTOM)) throw alib::AlibException(); return parseBlankSymbol(input); } else if(isToken(input, sax::Token::TokenType::START_ELEMENT, "EndSymbol")) { + if(!features.count(FEATURES::END)) throw alib::AlibException(); return parseEndSymbol(input); } else { throw sax::ParserException(sax::Token("LabeledSymbol, BlankSymbol, BottomOfTheStackSymbol, EndSymbol", sax::Token::TokenType::START_ELEMENT), input.front()); diff --git a/alib2/src/alphabet/SymbolFromXMLParser.h b/alib2/src/alphabet/SymbolFromXMLParser.h index 243a105f74..be0b411348 100644 --- a/alib2/src/alphabet/SymbolFromXMLParser.h +++ b/alib2/src/alphabet/SymbolFromXMLParser.h @@ -10,7 +10,9 @@ #include "../sax/FromXMLParser.h" #include <vector> +#include <set> #include "Symbol.h" +#include "SymbolFeatures.h" #include "../sax/Token.h" #include "../label/Label.h" @@ -39,6 +41,7 @@ namespace alphabet { */ class SymbolFromXMLParser : public sax::FromXMLParser { Symbol parse(std::list<sax::Token>& input) const; + Symbol parse(std::list<sax::Token>& input, const std::set<FEATURES>& features) const; Symbol parseLabeledSymbol(std::list<sax::Token>& input) const; Symbol parseBlankSymbol(std::list<sax::Token>& input) const; -- GitLab