#include "CommandsFileReader.h" #include #include #include "Impl/CommandsLexer.h" #include "Impl/CommandsParser.h" #include "Parsing/Impl/CommentRemovingStreamProxy.h" #include "Parsing/Impl/DefinesStreamProxy.h" #include "Parsing/Impl/IncludingStreamProxy.h" #include "Parsing/Impl/ParserFilesystemStream.h" CommandsFileReader::CommandsFileReader(const ZoneCodeGeneratorArguments* args, std::string filename) : m_args(args), m_filename(std::move(filename)), m_stream(nullptr) { } bool CommandsFileReader::OpenBaseStream() { auto stream = std::make_unique(m_filename); if (!stream->IsOpen()) { std::cout << "Could not open commands file" << std::endl; return false; } m_stream = stream.get(); m_open_streams.emplace_back(std::move(stream)); return true; } void CommandsFileReader::SetupStreamProxies() { auto commentProxy = std::make_unique(m_stream); auto includeProxy = std::make_unique(commentProxy.get()); auto definesProxy = std::make_unique(includeProxy.get()); definesProxy->AddDefine(ZONE_CODE_GENERATOR_DEFINE_NAME, ZONE_CODE_GENERATOR_DEFINE_VALUE); m_stream = definesProxy.get(); m_open_streams.emplace_back(std::move(commentProxy)); m_open_streams.emplace_back(std::move(includeProxy)); m_open_streams.emplace_back(std::move(definesProxy)); } bool CommandsFileReader::ReadCommandsFile(IDataRepository* repository) { std::cout << "Reading commands file: " << m_filename << std::endl; if (!OpenBaseStream()) return false; SetupStreamProxies(); const auto lexer = std::make_unique(m_stream); const auto parser = std::make_unique(lexer.get(), repository); const auto start = std::chrono::steady_clock::now(); const auto result = parser->Parse(); const auto end = std::chrono::steady_clock::now(); std::cout << "Processing commands took " << std::chrono::duration_cast(end - start).count() << "ms" << std::endl; return result; }