From b9da21dbc5750f5606683a3b522ffffad225f742 Mon Sep 17 00:00:00 2001 From: Robin Jadoul Date: Thu, 26 May 2016 16:00:32 +0200 Subject: [PATCH] Implementation of driver code --- include/Lexesis/driver.h | 28 ++++++++++++++++++++++++++++ src/CMakeLists.txt | 3 ++- src/driver.cpp | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 include/Lexesis/driver.h create mode 100644 src/driver.cpp diff --git a/include/Lexesis/driver.h b/include/Lexesis/driver.h new file mode 100644 index 0000000..c248432 --- /dev/null +++ b/include/Lexesis/driver.h @@ -0,0 +1,28 @@ +#pragma once +#ifndef LEXESIS_DRIVER_H +#define LEXESIS_DRIVER_H + +#include +#include + +#include "Lexesis/backendmanager.h" + +namespace lxs { + class Driver { + public: + Driver(std::unique_ptr backends, std::istream& inputfile, std::string outputdir, std::string language, std::string lexername); + ~Driver(); + + int run(); + + private: + std::unique_ptr m_backends; + std::istream& m_inputfile; + std::string m_outputdir; + std::string m_language; + std::string m_lexername; + }; +} + +#endif //LEXESIS_DRIVER_H + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 208d3a7..09c9e26 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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 diff --git a/src/driver.cpp b/src/driver.cpp new file mode 100644 index 0000000..3165ed5 --- /dev/null +++ b/src/driver.cpp @@ -0,0 +1,37 @@ +#include "Lexesis/driver.h" +#include "Lexesis/inputparser.h" + +#include +#include + +namespace lxs { + Driver::Driver(std::unique_ptr 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 { + return std::unique_ptr(new std::ofstream(m_outputdir + "/" + filename)); + }, + m_lexername, dfa); + + return 0; + } +}