Implementation of driver code
This commit is contained in:
parent
73ddf7fc11
commit
b9da21dbc5
|
@ -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
|
||||||
|
|
|
@ -10,11 +10,12 @@ add_executable(Lexesis
|
||||||
automata.cpp
|
automata.cpp
|
||||||
backend.cpp
|
backend.cpp
|
||||||
backendmanager.cpp
|
backendmanager.cpp
|
||||||
|
driver.cpp
|
||||||
re.cpp
|
re.cpp
|
||||||
inputparser.cpp
|
inputparser.cpp
|
||||||
template.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
|
install(TARGETS Lexesis
|
||||||
RUNTIME DESTINATION bin
|
RUNTIME DESTINATION bin
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue