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

acat2 include exception passing feature

parent 4142d876
No related branches found
No related tags found
No related merge requests found
......@@ -10,29 +10,18 @@
#include <unistd.h>
#include <exception>
#include "exception/AlibException.h"
#include "FromXMLParsers.h"
#include "factory/AutomatonFactory.h"
#include "factory/RegExpFactory.h"
#include "factory/StringFactory.h"
#include "factory/ExceptionFactory.h"
#include "sax/SaxParseInterface.h"
#include "FromXMLParsers.h"
#include "sax/ParserException.h"
 
 
#define VERSION "0.0.1"
#define USAGE "Usage: catPDA [-c] [input]";
 
void getAutomaton(std::list<sax::Token>& tokens) {
automaton::Automaton automaton = alib::FromXMLParsers::automatonParser.parseValue(tokens);
std::cout << automaton;
}
void getRegExp(std::list<sax::Token>& tokens) {
regexp::RegExp regexp = alib::FromXMLParsers::regexpParser.parseValue(tokens);
std::cout << regexp;
}
void getString(std::list<sax::Token>& tokens) {
string::String string = alib::FromXMLParsers::stringParser.parseValue(tokens);
std::cout << string;
}
int main(int argc, char** argv) {
if(argc == 2 && std::string(argv[1])=="-v" ) {
std::cout << argv[0] << " version " << VERSION << "\n";
......@@ -51,21 +40,35 @@ int main(int argc, char** argv) {
i=getopt(argc, argv, "t:");
}
 
std::list<sax::Token> tokens;
if(optind == argc) {
std::string input(std::istreambuf_iterator<char>(std::cin), std::istreambuf_iterator<char>());
sax::SaxParseInterface::parseMemory(input, tokens);
} else {
sax::SaxParseInterface::parseFile(argv[optind],tokens);
}
try {
std::list<sax::Token> tokens;
if(optind == argc) {
std::string input(std::istreambuf_iterator<char>(std::cin), std::istreambuf_iterator<char>());
sax::SaxParseInterface::parseMemory(input, tokens);
} else {
sax::SaxParseInterface::parseFile(argv[optind],tokens);
}
 
if (alib::FromXMLParsers::automatonParser.first(tokens)) {
getAutomaton(tokens);
} else if (alib::FromXMLParsers::regexpParser.first(tokens)) {
getRegExp(tokens);
} else if (alib::FromXMLParsers::stringParser.first(tokens)) {
getString(tokens);
} else {
throw exception::AlibException( "Expected root tag automaton, grammar, regexp or string. Read: " + tokens.front().getData());
if (alib::FromXMLParsers::automatonParser.first(tokens)) {
automaton::Automaton automaton = automaton::AutomatonFactory::fromTokens(tokens);
automaton::AutomatonFactory::toStdout(automaton);
} else if (alib::FromXMLParsers::regexpParser.first(tokens)) {
regexp::RegExp regexp = regexp::RegExpFactory::fromTokens(tokens);
regexp::RegExpFactory::toStdout(regexp);
} else if (alib::FromXMLParsers::stringParser.first(tokens)) {
string::String string = string::StringFactory::fromTokens(tokens);
string::StringFactory::StringFactory::toStdout(string);
} else if (alib::FromXMLParsers::exceptionParser.first(tokens)) {
exception::AlibException exception = exception::ExceptionFactory::fromTokens(tokens);
exception::ExceptionFactory::toStdout(exception);
} else {
throw exception::AlibException( "Expected root tag automaton, grammar, regexp, string or exception. Read: " + tokens.front().getData());
}
} catch(const exception::AlibException& exception) {
exception::ExceptionFactory::toStdout(exception);
return 1;
} catch(...) {
return 127;
}
return 0;
}
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