diff --git a/alib2/src/sax/FromXMLParser.cpp b/alib2/src/sax/FromXMLParser.cpp new file mode 100644 index 0000000000000000000000000000000000000000..782b395a94a84dcb15680ddbeed76f2e32fd0c26 --- /dev/null +++ b/alib2/src/sax/FromXMLParser.cpp @@ -0,0 +1,39 @@ +/* + * FromXMLParser.cpp + * + * Created on: Oct 12, 2013 + * Author: Jan Travnicek + */ + +#include "FromXMLParser.h" +#include "ParserException.h" + +namespace sax { + +bool FromXMLParser::isToken(std::list<Token>& input, Token::TokenType type, std::string data) { + return input.front().getType() == type && input.front().getData() == data; +} + +bool FromXMLParser::isTokenType(std::list<Token>& input, Token::TokenType type) { + return input.front().getType() == type; +} + +void FromXMLParser::popToken(std::list<Token>& input, Token::TokenType type, std::string data) { + if (isToken(input, type, data)) { + input.pop_front(); + } else { + throw ParserException(Token(data, type), input.front()); + } +} + +std::string FromXMLParser::popTokenType(std::list<Token>& input, Token::TokenType type) { + if(isTokenType(input, type)) { + std::string result = input.front().getData(); + input.pop_front(); + return std::move(result); + } else { + throw ParserException(Token("?", type), input.front()); + } +} + +} /* namespace sax */ diff --git a/alib2/src/sax/FromXMLParser.h b/alib2/src/sax/FromXMLParser.h new file mode 100644 index 0000000000000000000000000000000000000000..d6d55b0b4db577af570926f630eaedb9dd21fd02 --- /dev/null +++ b/alib2/src/sax/FromXMLParser.h @@ -0,0 +1,31 @@ +/* + * FromXMLParser.h + * + * Created on: Oct 12, 2013 + * Author: Jan Travnicek + */ + +#ifndef FROM_XML_PARSER_H_ +#define FROM_XML_PARSER_H_ + +#include <list> +#include "Token.h" + +namespace sax { + +/** + * Parser used to get UnknownAutomaton from XML parsed into list of Tokens. + */ +class FromXMLParser { +protected: + bool isToken(std::list<Token> &input, Token::TokenType type, std::string data); + bool isTokenType(std::list<Token>& input, Token::TokenType type); + void popToken(std::list<Token> &input, Token::TokenType type, std::string data); + std::string popTokenType(std::list<Token>& input, Token::TokenType type); + +}; + +} /* namespace sax */ + +#endif /* FROM_XML_PARSER_H_ */ +