Skip until first non empty line for templater

This commit is contained in:
Jan 2022-09-05 23:51:09 +02:00
parent e8baf65134
commit f574204e61
4 changed files with 66 additions and 1 deletions

View File

@ -1,11 +1,14 @@
#pragma options TEST(asdf, bla) #pragma options TEST(asdf, bla)
#pragma switch TEST_SWITCH #pragma switch TEST_SWITCH
#ifdef TEST_SWITCH #ifdef TEST_SWITCH
#define SVAL "1" #define SVAL "1"
#else #else
#define SVAL "0" #define SVAL "0"
#endif #endif
#pragma filename "lemao_" + TEST + SVAL + ".txt" #pragma filename "lemao_" + TEST + SVAL + ".txt"
HAHA TEST HAHA TEST
#ifdef TEST_SWITCH #ifdef TEST_SWITCH
kekw kekw

View File

@ -0,0 +1,40 @@
#include "SkipUntilFirstNonEmptyProxy.h"
SkipUntilFirstNonEmptyProxy::SkipUntilFirstNonEmptyProxy(IParserLineStream* stream)
: m_stream(stream),
m_had_non_empty(false)
{
}
ParserLine SkipUntilFirstNonEmptyProxy::NextLine()
{
auto line = m_stream->NextLine();
if (!m_had_non_empty)
{
while (line.m_line.empty() && !m_stream->Eof())
line = m_stream->NextLine();
m_had_non_empty = true;
}
return line;
}
bool SkipUntilFirstNonEmptyProxy::IncludeFile(const std::string& filename)
{
return m_stream->IncludeFile(filename);
}
void SkipUntilFirstNonEmptyProxy::PopCurrentFile()
{
m_stream->PopCurrentFile();
}
bool SkipUntilFirstNonEmptyProxy::IsOpen() const
{
return m_stream->IsOpen();
}
bool SkipUntilFirstNonEmptyProxy::Eof() const
{
return m_stream->Eof();
}

View File

@ -0,0 +1,19 @@
#pragma once
#include "Parsing/IParserLineStream.h"
class SkipUntilFirstNonEmptyProxy final : public IParserLineStream
{
public:
explicit SkipUntilFirstNonEmptyProxy(IParserLineStream* stream);
ParserLine NextLine() override;
bool IncludeFile(const std::string& filename) override;
void PopCurrentFile() override;
_NODISCARD bool IsOpen() const override;
_NODISCARD bool Eof() const override;
private:
IParserLineStream* const m_stream;
bool m_had_non_empty;
};

View File

@ -12,6 +12,7 @@
#include "Parsing/ParsingException.h" #include "Parsing/ParsingException.h"
#include "Parsing/Impl/DefinesStreamProxy.h" #include "Parsing/Impl/DefinesStreamProxy.h"
#include "Parsing/Impl/ParserSingleInputStream.h" #include "Parsing/Impl/ParserSingleInputStream.h"
#include "Parsing/Impl/SkipUntilFirstNonEmptyProxy.h"
using namespace templating; using namespace templating;
namespace fs = std::filesystem; namespace fs = std::filesystem;
@ -33,15 +34,17 @@ namespace templating
m_templating_proxy = std::make_unique<TemplatingStreamProxy>(m_base_stream.get(), templaterControl); m_templating_proxy = std::make_unique<TemplatingStreamProxy>(m_base_stream.get(), templaterControl);
m_defines_proxy = std::make_unique<DefinesStreamProxy>(m_templating_proxy.get()); m_defines_proxy = std::make_unique<DefinesStreamProxy>(m_templating_proxy.get());
m_directive_escape_proxy = std::make_unique<DirectiveEscapeStreamProxy>(m_defines_proxy.get()); m_directive_escape_proxy = std::make_unique<DirectiveEscapeStreamProxy>(m_defines_proxy.get());
m_skip_until_first_non_empty_proxy = std::make_unique<SkipUntilFirstNonEmptyProxy>(m_directive_escape_proxy.get());
m_templating_proxy->SetDefinesProxy(m_defines_proxy.get()); m_templating_proxy->SetDefinesProxy(m_defines_proxy.get());
m_stream = m_directive_escape_proxy.get(); m_stream = m_skip_until_first_non_empty_proxy.get();
} }
std::unique_ptr<IParserLineStream> m_base_stream; std::unique_ptr<IParserLineStream> m_base_stream;
std::unique_ptr<TemplatingStreamProxy> m_templating_proxy; std::unique_ptr<TemplatingStreamProxy> m_templating_proxy;
std::unique_ptr<DefinesStreamProxy> m_defines_proxy; std::unique_ptr<DefinesStreamProxy> m_defines_proxy;
std::unique_ptr<DirectiveEscapeStreamProxy> m_directive_escape_proxy; std::unique_ptr<DirectiveEscapeStreamProxy> m_directive_escape_proxy;
std::unique_ptr<SkipUntilFirstNonEmptyProxy> m_skip_until_first_non_empty_proxy;
IParserLineStream* m_stream; IParserLineStream* m_stream;
}; };