mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-25 14:17:54 -05:00
Reformat code with clang format
This commit is contained in:
@ -7,7 +7,7 @@ TokenPos AbstractDirectiveStreamProxy::CreatePos(const ParserLine& line, const u
|
||||
|
||||
bool AbstractDirectiveStreamProxy::SkipWhitespace(const ParserLine& line, unsigned& position)
|
||||
{
|
||||
while(true)
|
||||
while (true)
|
||||
{
|
||||
if (position >= line.m_line.size())
|
||||
return false;
|
||||
@ -31,7 +31,7 @@ bool AbstractDirectiveStreamProxy::ExtractInteger(const ParserLine& line, unsign
|
||||
value = strtol(startPosition, &endPosition, 0);
|
||||
const auto len = endPosition - startPosition;
|
||||
|
||||
if(len > 0)
|
||||
if (len > 0)
|
||||
{
|
||||
position += len;
|
||||
return true;
|
||||
@ -49,9 +49,7 @@ bool AbstractDirectiveStreamProxy::ExtractIdentifier(const ParserLine& line, uns
|
||||
return !firstChar;
|
||||
|
||||
const auto c = line.m_line[position];
|
||||
if (isalpha(c)
|
||||
|| c == '_'
|
||||
|| !firstChar && isdigit(c))
|
||||
if (isalpha(c) || c == '_' || !firstChar && isdigit(c))
|
||||
{
|
||||
position++;
|
||||
}
|
||||
@ -108,10 +106,10 @@ bool AbstractDirectiveStreamProxy::FindDirective(const ParserLine& line, unsigne
|
||||
continue;
|
||||
|
||||
directiveEndPos = directiveStartPosition + 1;
|
||||
for(; directiveEndPos < line.m_line.size(); directiveEndPos++)
|
||||
for (; directiveEndPos < line.m_line.size(); directiveEndPos++)
|
||||
{
|
||||
const auto c2 = line.m_line[directiveEndPos];
|
||||
|
||||
|
||||
if (isspace(c2))
|
||||
break;
|
||||
}
|
||||
|
@ -1,17 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include "Parsing/ILexer.h"
|
||||
#include "Parsing/IParserLineStream.h"
|
||||
#include "Parsing/ParsingException.h"
|
||||
#include "Utils/ClassUtils.h"
|
||||
#include "Utils/StringUtils.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <deque>
|
||||
#include <sstream>
|
||||
|
||||
#include "Utils/ClassUtils.h"
|
||||
#include "Parsing/ILexer.h"
|
||||
#include "Parsing/IParserLineStream.h"
|
||||
#include "Parsing/ParsingException.h"
|
||||
#include "Utils/StringUtils.h"
|
||||
|
||||
template <typename TokenType>
|
||||
class AbstractLexer : public ILexer<TokenType>
|
||||
template<typename TokenType> class AbstractLexer : public ILexer<TokenType>
|
||||
{
|
||||
// TokenType must inherit IParserValue
|
||||
static_assert(std::is_base_of<IParserValue, TokenType>::value);
|
||||
@ -311,16 +310,12 @@ protected:
|
||||
{
|
||||
const auto& currentLine = CurrentLine();
|
||||
assert(m_current_line_offset >= 1);
|
||||
assert(isdigit(currentLine.m_line[m_current_line_offset - 1])
|
||||
|| currentLine.m_line[m_current_line_offset - 1] == '.'
|
||||
|| currentLine.m_line[m_current_line_offset - 1] == '+'
|
||||
|| currentLine.m_line[m_current_line_offset - 1] == '-');
|
||||
assert(isdigit(currentLine.m_line[m_current_line_offset - 1]) || currentLine.m_line[m_current_line_offset - 1] == '.'
|
||||
|| currentLine.m_line[m_current_line_offset - 1] == '+' || currentLine.m_line[m_current_line_offset - 1] == '-');
|
||||
hasSignPrefix = currentLine.m_line[m_current_line_offset - 1] == '+' || currentLine.m_line[m_current_line_offset - 1] == '-';
|
||||
|
||||
const auto lineLength = currentLine.m_line.size();
|
||||
if (lineLength - m_current_line_offset >= 1
|
||||
&& currentLine.m_line[m_current_line_offset - 1] == '0'
|
||||
&& currentLine.m_line[m_current_line_offset] == 'x')
|
||||
if (lineLength - m_current_line_offset >= 1 && currentLine.m_line[m_current_line_offset - 1] == '0' && currentLine.m_line[m_current_line_offset] == 'x')
|
||||
{
|
||||
isFloatingPoint = false;
|
||||
ReadHexNumber(integerValue);
|
||||
@ -341,15 +336,12 @@ protected:
|
||||
{
|
||||
const auto& currentLine = CurrentLine();
|
||||
assert(m_current_line_offset >= 1);
|
||||
assert(isdigit(currentLine.m_line[m_current_line_offset - 1])
|
||||
|| currentLine.m_line[m_current_line_offset - 1] == '+'
|
||||
|| currentLine.m_line[m_current_line_offset - 1] == '-');
|
||||
assert(isdigit(currentLine.m_line[m_current_line_offset - 1]) || currentLine.m_line[m_current_line_offset - 1] == '+'
|
||||
|| currentLine.m_line[m_current_line_offset - 1] == '-');
|
||||
hasSignPrefix = currentLine.m_line[m_current_line_offset - 1] == '+' || currentLine.m_line[m_current_line_offset - 1] == '-';
|
||||
|
||||
const auto lineLength = currentLine.m_line.size();
|
||||
if (lineLength - m_current_line_offset >= 1
|
||||
&& currentLine.m_line[m_current_line_offset - 1] == '0'
|
||||
&& currentLine.m_line[m_current_line_offset] == 'x')
|
||||
if (lineLength - m_current_line_offset >= 1 && currentLine.m_line[m_current_line_offset - 1] == '0' && currentLine.m_line[m_current_line_offset] == 'x')
|
||||
{
|
||||
ReadHexNumber(integerValue);
|
||||
}
|
||||
@ -376,9 +368,9 @@ public:
|
||||
if (static_cast<int>(m_token_cache.size()) <= amount)
|
||||
{
|
||||
const auto& lastToken = m_token_cache.back();
|
||||
while (!m_line_cache.empty()
|
||||
&& (m_line_cache.front().m_line_number != lastToken.GetPos().m_line
|
||||
|| *m_line_cache.front().m_filename != lastToken.GetPos().m_filename.get()))
|
||||
while (
|
||||
!m_line_cache.empty()
|
||||
&& (m_line_cache.front().m_line_number != lastToken.GetPos().m_line || *m_line_cache.front().m_filename != lastToken.GetPos().m_filename.get()))
|
||||
{
|
||||
m_line_cache.pop_front();
|
||||
m_line_index--;
|
||||
@ -390,8 +382,8 @@ public:
|
||||
m_token_cache.erase(m_token_cache.begin(), m_token_cache.begin() + amount);
|
||||
const auto& firstToken = m_token_cache.front();
|
||||
while (!m_line_cache.empty()
|
||||
&& (m_line_cache.front().m_line_number != firstToken.GetPos().m_line
|
||||
|| *m_line_cache.front().m_filename != firstToken.GetPos().m_filename.get()))
|
||||
&& (m_line_cache.front().m_line_number != firstToken.GetPos().m_line
|
||||
|| *m_line_cache.front().m_filename != firstToken.GetPos().m_filename.get()))
|
||||
{
|
||||
m_line_cache.pop_front();
|
||||
m_line_index--;
|
||||
@ -413,9 +405,7 @@ public:
|
||||
{
|
||||
for (const auto& line : m_line_cache)
|
||||
{
|
||||
if (line.m_filename
|
||||
&& *line.m_filename == pos.m_filename.get()
|
||||
&& line.m_line_number == pos.m_line)
|
||||
if (line.m_filename && *line.m_filename == pos.m_filename.get() && line.m_line_number == pos.m_line)
|
||||
{
|
||||
return line;
|
||||
}
|
||||
|
@ -1,15 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include "Parsing/ILexer.h"
|
||||
#include "Parsing/IParser.h"
|
||||
#include "Parsing/ParsingException.h"
|
||||
#include "Parsing/Sequence/AbstractSequence.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
#include "Parsing/IParser.h"
|
||||
#include "Parsing/ILexer.h"
|
||||
#include "Parsing/Sequence/AbstractSequence.h"
|
||||
#include "Parsing/ParsingException.h"
|
||||
|
||||
template <typename TokenType, typename ParserState>
|
||||
class AbstractParser : public IParser
|
||||
template<typename TokenType, typename ParserState> class AbstractParser : public IParser
|
||||
{
|
||||
// TokenType must inherit IParserValue
|
||||
static_assert(std::is_base_of<IParserValue, TokenType>::value);
|
||||
@ -65,11 +64,12 @@ public:
|
||||
if (!line.IsEof())
|
||||
{
|
||||
std::cerr << "Error: " << pos.m_filename.get() << " L" << pos.m_line << ':' << pos.m_column << " Could not parse expression:\n"
|
||||
<< line.m_line.substr(pos.m_column - 1) << std::endl;
|
||||
<< line.m_line.substr(pos.m_column - 1) << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "Error: " << pos.m_filename.get() << " L" << pos.m_line << ':' << pos.m_column << " Could not parse expression." << std::endl;
|
||||
std::cerr << "Error: " << pos.m_filename.get() << " L" << pos.m_line << ':' << pos.m_column << " Could not parse expression."
|
||||
<< std::endl;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ ParserLine CommentRemovingStreamProxy::NextLine()
|
||||
m_inside_multi_line_comment = false;
|
||||
}
|
||||
}
|
||||
else if(inString)
|
||||
else if (inString)
|
||||
{
|
||||
if (isEscaped)
|
||||
isEscaped = false;
|
||||
@ -45,11 +45,11 @@ ParserLine CommentRemovingStreamProxy::NextLine()
|
||||
}
|
||||
else
|
||||
{
|
||||
if(c == '"')
|
||||
if (c == '"')
|
||||
{
|
||||
inString = true;
|
||||
}
|
||||
else if(c == '/' && i + 1 < line.m_line.size())
|
||||
else if (c == '/' && i + 1 < line.m_line.size())
|
||||
{
|
||||
const auto c1 = line.m_line[i + 1];
|
||||
|
||||
@ -58,7 +58,7 @@ ParserLine CommentRemovingStreamProxy::NextLine()
|
||||
multiLineCommentStart = i;
|
||||
m_inside_multi_line_comment = true;
|
||||
}
|
||||
else if(c1 == '/')
|
||||
else if (c1 == '/')
|
||||
{
|
||||
m_next_line_is_comment = line.m_line[line.m_line.size() - 1] == '\\';
|
||||
line.m_line.erase(i);
|
||||
@ -68,7 +68,7 @@ ParserLine CommentRemovingStreamProxy::NextLine()
|
||||
}
|
||||
}
|
||||
|
||||
if(m_inside_multi_line_comment)
|
||||
if (m_inside_multi_line_comment)
|
||||
line.m_line.erase(multiLineCommentStart);
|
||||
|
||||
return line;
|
||||
|
@ -1,16 +1,16 @@
|
||||
#include "DefinesStreamProxy.h"
|
||||
|
||||
#include "ParserSingleInputStream.h"
|
||||
#include "Parsing/ParsingException.h"
|
||||
#include "Parsing/Simple/Expression/ISimpleExpression.h"
|
||||
#include "Parsing/Simple/Expression/SimpleExpressionMatchers.h"
|
||||
#include "Parsing/Simple/SimpleExpressionInterpreter.h"
|
||||
#include "Utils/ClassUtils.h"
|
||||
|
||||
#include <regex>
|
||||
#include <sstream>
|
||||
#include <utility>
|
||||
|
||||
#include "Utils/ClassUtils.h"
|
||||
#include "ParserSingleInputStream.h"
|
||||
#include "Parsing/ParsingException.h"
|
||||
#include "Parsing/Simple/SimpleExpressionInterpreter.h"
|
||||
#include "Parsing/Simple/Expression/ISimpleExpression.h"
|
||||
#include "Parsing/Simple/Expression/SimpleExpressionMatchers.h"
|
||||
|
||||
DefinesStreamProxy::DefineParameterPosition::DefineParameterPosition()
|
||||
: m_parameter_index(0u),
|
||||
m_parameter_position(0u)
|
||||
@ -23,8 +23,7 @@ DefinesStreamProxy::DefineParameterPosition::DefineParameterPosition(const unsig
|
||||
{
|
||||
}
|
||||
|
||||
DefinesStreamProxy::Define::Define()
|
||||
= default;
|
||||
DefinesStreamProxy::Define::Define() = default;
|
||||
|
||||
DefinesStreamProxy::Define::Define(std::string name, std::string value)
|
||||
: m_name(std::move(name)),
|
||||
@ -277,7 +276,8 @@ bool DefinesStreamProxy::MatchUndefDirective(const ParserLine& line, const unsig
|
||||
return true;
|
||||
}
|
||||
|
||||
std::unique_ptr<ISimpleExpression> DefinesStreamProxy::ParseExpression(std::shared_ptr<std::string> fileName, int lineNumber, std::string expressionString) const
|
||||
std::unique_ptr<ISimpleExpression>
|
||||
DefinesStreamProxy::ParseExpression(std::shared_ptr<std::string> fileName, int lineNumber, std::string expressionString) const
|
||||
{
|
||||
ParserLine pseudoLine(std::move(fileName), lineNumber, std::move(expressionString));
|
||||
ExpandDefinedExpressions(pseudoLine);
|
||||
@ -463,16 +463,13 @@ bool DefinesStreamProxy::MatchDirectives(const ParserLine& line)
|
||||
|
||||
if (m_modes.empty() || m_modes.top() == BlockMode::IN_BLOCK)
|
||||
{
|
||||
if (MatchDefineDirective(line, directiveStartPos, directiveEndPos)
|
||||
|| MatchUndefDirective(line, directiveStartPos, directiveEndPos))
|
||||
if (MatchDefineDirective(line, directiveStartPos, directiveEndPos) || MatchUndefDirective(line, directiveStartPos, directiveEndPos))
|
||||
return true;
|
||||
}
|
||||
|
||||
return MatchIfdefDirective(line, directiveStartPos, directiveEndPos)
|
||||
|| MatchIfDirective(line, directiveStartPos, directiveEndPos)
|
||||
|| MatchElIfDirective(line, directiveStartPos, directiveEndPos)
|
||||
|| MatchElseDirective(line, directiveStartPos, directiveEndPos)
|
||||
|| MatchEndifDirective(line, directiveStartPos, directiveEndPos);
|
||||
return MatchIfdefDirective(line, directiveStartPos, directiveEndPos) || MatchIfDirective(line, directiveStartPos, directiveEndPos)
|
||||
|| MatchElIfDirective(line, directiveStartPos, directiveEndPos) || MatchElseDirective(line, directiveStartPos, directiveEndPos)
|
||||
|| MatchEndifDirective(line, directiveStartPos, directiveEndPos);
|
||||
}
|
||||
|
||||
bool DefinesStreamProxy::FindDefineForWord(const ParserLine& line, const unsigned wordStart, const unsigned wordEnd, const Define*& value) const
|
||||
@ -488,7 +485,10 @@ bool DefinesStreamProxy::FindDefineForWord(const ParserLine& line, const unsigne
|
||||
return false;
|
||||
}
|
||||
|
||||
void DefinesStreamProxy::ExtractParametersFromDefineUsage(const ParserLine& line, const unsigned parameterStart, unsigned& parameterEnd, std::vector<std::string>& parameterValues)
|
||||
void DefinesStreamProxy::ExtractParametersFromDefineUsage(const ParserLine& line,
|
||||
const unsigned parameterStart,
|
||||
unsigned& parameterEnd,
|
||||
std::vector<std::string>& parameterValues)
|
||||
{
|
||||
if (line.m_line[parameterStart] != '(')
|
||||
return;
|
||||
@ -553,7 +553,7 @@ void DefinesStreamProxy::ExtractParametersFromDefineUsage(const ParserLine& line
|
||||
bool DefinesStreamProxy::MatchDefinedExpression(const ParserLine& line, unsigned& pos, std::string& definitionName)
|
||||
{
|
||||
unsigned currentPos = pos;
|
||||
|
||||
|
||||
if (!MatchNextCharacter(line, currentPos, '('))
|
||||
return false;
|
||||
|
||||
@ -609,7 +609,8 @@ void DefinesStreamProxy::ExpandDefines(ParserLine& line) const
|
||||
do
|
||||
{
|
||||
if (defineIterations > MAX_DEFINE_ITERATIONS)
|
||||
throw ParsingException(CreatePos(line, 1), "Potential define loop? Exceeded max define iterations of " + std::to_string(MAX_DEFINE_ITERATIONS) + " iterations.");
|
||||
throw ParsingException(CreatePos(line, 1),
|
||||
"Potential define loop? Exceeded max define iterations of " + std::to_string(MAX_DEFINE_ITERATIONS) + " iterations.");
|
||||
|
||||
usesDefines = false;
|
||||
|
||||
@ -684,8 +685,7 @@ void DefinesStreamProxy::ExpandDefines(ParserLine& line) const
|
||||
}
|
||||
|
||||
defineIterations++;
|
||||
}
|
||||
while (usesDefines);
|
||||
} while (usesDefines);
|
||||
}
|
||||
|
||||
void DefinesStreamProxy::AddDefine(Define define)
|
||||
|
@ -1,13 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include <stack>
|
||||
#include <sstream>
|
||||
|
||||
#include "AbstractDirectiveStreamProxy.h"
|
||||
#include "Parsing/IParserLineStream.h"
|
||||
#include "Parsing/Simple/Expression/ISimpleExpression.h"
|
||||
|
||||
#include <map>
|
||||
#include <sstream>
|
||||
#include <stack>
|
||||
|
||||
class DefinesStreamProxy final : public AbstractDirectiveStreamProxy
|
||||
{
|
||||
static constexpr const char* DEFINE_DIRECTIVE = "define";
|
||||
@ -77,7 +77,8 @@ private:
|
||||
_NODISCARD bool MatchEndifDirective(const ParserLine& line, unsigned directiveStartPosition, unsigned directiveEndPosition);
|
||||
_NODISCARD bool MatchDirectives(const ParserLine& line);
|
||||
|
||||
static void ExtractParametersFromDefineUsage(const ParserLine& line, unsigned parameterStart, unsigned& parameterEnd, std::vector<std::string>& parameterValues);
|
||||
static void
|
||||
ExtractParametersFromDefineUsage(const ParserLine& line, unsigned parameterStart, unsigned& parameterEnd, std::vector<std::string>& parameterValues);
|
||||
bool FindDefineForWord(const ParserLine& line, unsigned wordStart, unsigned wordEnd, const Define*& value) const;
|
||||
|
||||
static bool MatchDefinedExpression(const ParserLine& line, unsigned& pos, std::string& definitionName);
|
||||
|
@ -1,10 +1,10 @@
|
||||
#include "IncludingStreamProxy.h"
|
||||
|
||||
#include <sstream>
|
||||
#include <filesystem>
|
||||
|
||||
#include "Parsing/ParsingException.h"
|
||||
|
||||
#include <filesystem>
|
||||
#include <sstream>
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
IncludingStreamProxy::IncludingStreamProxy(IParserLineStream* stream)
|
||||
@ -12,7 +12,10 @@ IncludingStreamProxy::IncludingStreamProxy(IParserLineStream* stream)
|
||||
{
|
||||
}
|
||||
|
||||
bool IncludingStreamProxy::ExtractIncludeFilename(const ParserLine& line, const unsigned includeDirectivePosition, unsigned& filenameStartPosition, unsigned& filenameEndPosition)
|
||||
bool IncludingStreamProxy::ExtractIncludeFilename(const ParserLine& line,
|
||||
const unsigned includeDirectivePosition,
|
||||
unsigned& filenameStartPosition,
|
||||
unsigned& filenameEndPosition)
|
||||
{
|
||||
auto currentPos = includeDirectivePosition;
|
||||
bool isDoubleQuotes;
|
||||
@ -66,7 +69,7 @@ bool IncludingStreamProxy::MatchIncludeDirective(const ParserLine& line, const u
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
unsigned filenameStart, filenameEnd;
|
||||
|
||||
if (!ExtractIncludeFilename(line, currentPos, filenameStart, filenameEnd))
|
||||
@ -91,7 +94,7 @@ bool IncludingStreamProxy::MatchPragmaOnceDirective(const ParserLine& line, cons
|
||||
{
|
||||
auto currentPos = directiveStartPos;
|
||||
|
||||
if(directiveEndPos - directiveStartPos != std::char_traits<char>::length(PRAGMA_DIRECTIVE)
|
||||
if (directiveEndPos - directiveStartPos != std::char_traits<char>::length(PRAGMA_DIRECTIVE)
|
||||
|| !MatchString(line, currentPos, PRAGMA_DIRECTIVE, std::char_traits<char>::length(PRAGMA_DIRECTIVE)))
|
||||
{
|
||||
return false;
|
||||
@ -123,15 +126,14 @@ bool IncludingStreamProxy::MatchDirectives(const ParserLine& line)
|
||||
return false;
|
||||
|
||||
directiveStartPos++;
|
||||
return MatchIncludeDirective(line, directiveStartPos, directiveEndPos)
|
||||
|| MatchPragmaOnceDirective(line, directiveStartPos, directiveEndPos);
|
||||
return MatchIncludeDirective(line, directiveStartPos, directiveEndPos) || MatchPragmaOnceDirective(line, directiveStartPos, directiveEndPos);
|
||||
}
|
||||
|
||||
ParserLine IncludingStreamProxy::NextLine()
|
||||
{
|
||||
auto line = m_stream->NextLine();
|
||||
|
||||
while(MatchDirectives(line))
|
||||
while (MatchDirectives(line))
|
||||
line = m_stream->NextLine();
|
||||
|
||||
return line;
|
||||
|
@ -1,10 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <set>
|
||||
|
||||
#include "AbstractDirectiveStreamProxy.h"
|
||||
#include "Parsing/IParserLineStream.h"
|
||||
|
||||
#include <set>
|
||||
|
||||
class IncludingStreamProxy final : public AbstractDirectiveStreamProxy
|
||||
{
|
||||
static constexpr const char* INCLUDE_QUOTES_ERROR = "Invalid include directive. Expected \"\" or <>";
|
||||
@ -14,8 +14,9 @@ class IncludingStreamProxy final : public AbstractDirectiveStreamProxy
|
||||
|
||||
IParserLineStream* const m_stream;
|
||||
std::set<std::string> m_included_files;
|
||||
|
||||
_NODISCARD static bool ExtractIncludeFilename(const ParserLine& line, unsigned includeDirectivePosition, unsigned& filenameStartPosition, unsigned& filenameEndPosition);
|
||||
|
||||
_NODISCARD static bool
|
||||
ExtractIncludeFilename(const ParserLine& line, unsigned includeDirectivePosition, unsigned& filenameStartPosition, unsigned& filenameEndPosition);
|
||||
_NODISCARD bool MatchIncludeDirective(const ParserLine& line, unsigned directiveStartPos, unsigned directiveEndPos) const;
|
||||
_NODISCARD bool MatchPragmaOnceDirective(const ParserLine& line, unsigned directiveStartPos, unsigned directiveEndPos);
|
||||
_NODISCARD bool MatchDirectives(const ParserLine& line);
|
||||
|
@ -1,11 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <stack>
|
||||
|
||||
#include "Utils/ClassUtils.h"
|
||||
#include "AbstractDirectiveStreamProxy.h"
|
||||
#include "Parsing/IPackValueSupplier.h"
|
||||
#include "Parsing/IParserLineStream.h"
|
||||
#include "Utils/ClassUtils.h"
|
||||
|
||||
#include <stack>
|
||||
|
||||
class PackDefinitionStreamProxy final : public AbstractDirectiveStreamProxy, public IPackValueSupplier
|
||||
{
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include "ParserFilesystemStream.h"
|
||||
|
||||
#include <sstream>
|
||||
#include <filesystem>
|
||||
#include <sstream>
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
@ -20,8 +20,7 @@ ParserFilesystemStream::ParserFilesystemStream(const std::string& path)
|
||||
|
||||
bool ParserFilesystemStream::IsOpen() const
|
||||
{
|
||||
return !m_files.empty()
|
||||
&& m_files.top().m_stream.is_open();
|
||||
return !m_files.empty() && m_files.top().m_stream.is_open();
|
||||
}
|
||||
|
||||
ParserLine ParserFilesystemStream::NextLine()
|
||||
@ -32,7 +31,7 @@ ParserLine ParserFilesystemStream::NextLine()
|
||||
if (m_files.empty())
|
||||
return ParserLine();
|
||||
|
||||
while(!m_files.empty())
|
||||
while (!m_files.empty())
|
||||
{
|
||||
auto& fileInfo = m_files.top();
|
||||
|
||||
@ -61,7 +60,7 @@ ParserLine ParserFilesystemStream::NextLine()
|
||||
c = fileInfo.m_stream.get();
|
||||
}
|
||||
|
||||
if(hasLength)
|
||||
if (hasLength)
|
||||
return ParserLine(fileInfo.m_file_path, fileInfo.m_line_number, str.str());
|
||||
m_files.pop();
|
||||
}
|
||||
@ -73,7 +72,7 @@ bool ParserFilesystemStream::IncludeFile(const std::string& filename)
|
||||
{
|
||||
if (m_files.empty())
|
||||
return false;
|
||||
|
||||
|
||||
auto newFilePath = fs::path(*m_files.top().m_file_path);
|
||||
newFilePath.remove_filename().concat(filename);
|
||||
newFilePath = absolute(newFilePath);
|
||||
@ -89,12 +88,11 @@ bool ParserFilesystemStream::IncludeFile(const std::string& filename)
|
||||
|
||||
void ParserFilesystemStream::PopCurrentFile()
|
||||
{
|
||||
if(!m_files.empty())
|
||||
if (!m_files.empty())
|
||||
m_files.pop();
|
||||
}
|
||||
|
||||
bool ParserFilesystemStream::Eof() const
|
||||
{
|
||||
return m_files.empty()
|
||||
|| m_files.top().m_stream.eof();
|
||||
return m_files.empty() || m_files.top().m_stream.eof();
|
||||
}
|
||||
|
@ -1,10 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <stack>
|
||||
#include <fstream>
|
||||
|
||||
#include "Parsing/IParserLineStream.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <stack>
|
||||
|
||||
class ParserFilesystemStream final : public IParserLineStream
|
||||
{
|
||||
class FileInfo
|
||||
@ -16,6 +16,7 @@ class ParserFilesystemStream final : public IParserLineStream
|
||||
|
||||
explicit FileInfo(std::string filePath);
|
||||
};
|
||||
|
||||
std::stack<FileInfo> m_files;
|
||||
|
||||
public:
|
||||
|
@ -1,12 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <istream>
|
||||
#include <stack>
|
||||
#include <memory>
|
||||
#include <functional>
|
||||
|
||||
#include "Parsing/IParserLineStream.h"
|
||||
|
||||
#include <functional>
|
||||
#include <istream>
|
||||
#include <memory>
|
||||
#include <stack>
|
||||
|
||||
class ParserMultiInputStream final : public IParserLineStream
|
||||
{
|
||||
public:
|
||||
@ -37,4 +37,4 @@ public:
|
||||
void PopCurrentFile() override;
|
||||
_NODISCARD bool IsOpen() const override;
|
||||
_NODISCARD bool Eof() const override;
|
||||
};
|
||||
};
|
||||
|
@ -50,9 +50,7 @@ bool ParserSingleInputStream::IncludeFile(const std::string& filename)
|
||||
return false;
|
||||
}
|
||||
|
||||
void ParserSingleInputStream::PopCurrentFile()
|
||||
{
|
||||
}
|
||||
void ParserSingleInputStream::PopCurrentFile() {}
|
||||
|
||||
bool ParserSingleInputStream::IsOpen() const
|
||||
{
|
||||
|
@ -1,10 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include "Parsing/IParserLineStream.h"
|
||||
|
||||
#include <istream>
|
||||
#include <memory>
|
||||
|
||||
#include "Parsing/IParserLineStream.h"
|
||||
|
||||
class ParserSingleInputStream final : public IParserLineStream
|
||||
{
|
||||
std::istream& m_stream;
|
||||
@ -19,4 +19,4 @@ public:
|
||||
void PopCurrentFile() override;
|
||||
_NODISCARD bool IsOpen() const override;
|
||||
_NODISCARD bool Eof() const override;
|
||||
};
|
||||
};
|
||||
|
Reference in New Issue
Block a user