Implementation of driver code

This commit is contained in:
Robin Jadoul 2016-05-26 16:00:32 +02:00
parent 73ddf7fc11
commit b9da21dbc5
3 changed files with 67 additions and 1 deletions

28
include/Lexesis/driver.h Normal file
View File

@ -0,0 +1,28 @@
#pragma once
#ifndef LEXESIS_DRIVER_H
#define LEXESIS_DRIVER_H
#include <memory>
#include <string>
#include "Lexesis/backendmanager.h"
namespace lxs {
class Driver {
public:
Driver(std::unique_ptr<BackendManager> backends, std::istream& inputfile, std::string outputdir, std::string language, std::string lexername);
~Driver();
int run();
private:
std::unique_ptr<BackendManager> m_backends;
std::istream& m_inputfile;
std::string m_outputdir;
std::string m_language;
std::string m_lexername;
};
}
#endif //LEXESIS_DRIVER_H

View File

@ -10,11 +10,12 @@ add_executable(Lexesis
automata.cpp
backend.cpp
backendmanager.cpp
driver.cpp
re.cpp
inputparser.cpp
template.cpp
)
target_link_libraries(Lexesis Lexesis-backends mstch::mstch docopt)
target_link_libraries(Lexesis Lexesis-backends mstch::mstch cpp-optparse)
install(TARGETS Lexesis
RUNTIME DESTINATION bin

37
src/driver.cpp Normal file
View File

@ -0,0 +1,37 @@
#include "Lexesis/driver.h"
#include "Lexesis/inputparser.h"
#include <iostream>
#include <fstream>
namespace lxs {
Driver::Driver(std::unique_ptr<BackendManager> backends, std::istream& inputfile, std::string outputdir, std::string language, std::string lexername) :
m_backends(std::move(backends)),
m_inputfile(inputfile),
m_outputdir(outputdir),
m_language(language),
m_lexername(lexername)
{
//TODO clean lexername
}
Driver::~Driver()
{}
int Driver::run() {
Backend* back = m_backends->findBackendForLang(m_language);
if (!back) {
std::cerr << "Could not find a valid backend for language " << m_language << std::endl;
return 1;
}
DFA dfa = InputParser::parseInput(m_inputfile);
back->generateLexer([this](std::string filename) -> std::unique_ptr<std::ostream> {
return std::unique_ptr<std::ostream>(new std::ofstream(m_outputdir + "/" + filename));
},
m_lexername, dfa);
return 0;
}
}