Add Simple Parsing implementations for basic parsers

This commit is contained in:
Jan
2021-03-09 11:04:04 +01:00
parent 8d9080066f
commit 88ff98f334
14 changed files with 503 additions and 0 deletions

View File

@ -0,0 +1,65 @@
#include "ParserInputStream.h"
#include <sstream>
ParserInputStream::ParserInputStream(std::istream& stream, std::string fileName)
: m_stream(stream),
m_file_name(std::move(fileName)),
m_line_number(1)
{
}
ParserLine ParserInputStream::NextLine()
{
std::ostringstream str;
auto hasLength = false;
auto c = m_stream.get();
while (c != EOF)
{
switch (c)
{
case '\r':
c = m_stream.get();
if (c == '\n')
return ParserLine(m_file_name, m_line_number++, str.str());
str << '\r';
hasLength = true;
continue;
case '\n':
return ParserLine(m_file_name, m_line_number++, str.str());
default:
str << static_cast<char>(c);
hasLength = true;
break;
}
c = m_stream.get();
}
if (hasLength)
return ParserLine(m_file_name, m_line_number, str.str());
return ParserLine();
}
bool ParserInputStream::IncludeFile(const std::string& filename)
{
return false;
}
void ParserInputStream::PopCurrentFile()
{
}
bool ParserInputStream::IsOpen() const
{
return !m_stream.eof();
}
bool ParserInputStream::Eof() const
{
return !m_stream.eof();
}

View File

@ -0,0 +1,21 @@
#pragma once
#include <istream>
#include "Parsing/IParserLineStream.h"
class ParserInputStream final : public IParserLineStream
{
std::istream& m_stream;
std::string m_file_name;
int m_line_number;
public:
ParserInputStream(std::istream& stream, std::string fileName);
ParserLine NextLine() override;
bool IncludeFile(const std::string& filename) override;
void PopCurrentFile() override;
_NODISCARD bool IsOpen() const override;
_NODISCARD bool Eof() const override;
};