Skip to content
Snippets Groups Projects
Commit 9a73915f authored by Jan Trávníček's avatar Jan Trávníček
Browse files

base class for all xml parsers

parent 1a6af884
No related branches found
No related tags found
No related merge requests found
/*
* 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 */
/*
* 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_ */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment