Reformat code with clang format

This commit is contained in:
Clang Format
2023-11-19 15:28:38 +01:00
committed by Jan
parent 22e17272fd
commit 6b4f5d94a8
1099 changed files with 16763 additions and 18076 deletions

View File

@ -3,8 +3,7 @@
#include "IParserLineStream.h"
#include "Parsing/IParserValue.h"
template<typename TokenType>
class ILexer
template<typename TokenType> class ILexer
{
// TokenType must inherit IParserValue
static_assert(std::is_base_of<IParserValue, TokenType>::value);

View File

@ -11,4 +11,4 @@ public:
IPackValueSupplier& operator=(IPackValueSupplier&& other) noexcept = default;
virtual int GetCurrentPack() const = 0;
};
};

View File

@ -1,10 +1,10 @@
#pragma once
#include <string>
#include "Utils/ClassUtils.h"
#include <functional>
#include <memory>
#include "Utils/ClassUtils.h"
#include <string>
class ParserLine
{

View File

@ -1,7 +1,7 @@
#pragma once
#include "Utils/ClassUtils.h"
#include "TokenPos.h"
#include "Utils/ClassUtils.h"
class IParserValue
{

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;

View File

@ -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)

View File

@ -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);

View File

@ -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;

View File

@ -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);

View File

@ -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
{

View File

@ -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();
}

View File

@ -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:

View File

@ -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;
};
};

View File

@ -50,9 +50,7 @@ bool ParserSingleInputStream::IncludeFile(const std::string& filename)
return false;
}
void ParserSingleInputStream::PopCurrentFile()
{
}
void ParserSingleInputStream::PopCurrentFile() {}
bool ParserSingleInputStream::IsOpen() const
{

View File

@ -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;
};
};

View File

@ -1,13 +1,12 @@
#pragma once
#include "Parsing/ILexer.h"
#include "Parsing/IParserValue.h"
#include "Parsing/Matcher/MatcherResult.h"
#include <functional>
#include "Parsing/IParserValue.h"
#include "Parsing/ILexer.h"
#include "Parsing/Matcher/MatcherResult.h"
template <typename TokenType>
class AbstractMatcher
template<typename TokenType> class AbstractMatcher
{
// TokenType must inherit IParserValue
static_assert(std::is_base_of<IParserValue, TokenType>::value);
@ -83,7 +82,7 @@ public:
result.m_matched_tokens.clear();
result.m_matched_tokens.emplace_back(result.m_fabricated_tokens.size() - 1, true);
}
else if(result.m_matched_tokens.empty())
else if (result.m_matched_tokens.empty())
{
for (auto i = 0u; i < result.m_consumed_token_count; i++)
result.m_matched_tokens.emplace_back(tokenOffset + i, false);

View File

@ -1,20 +1,19 @@
#pragma once
#include "AbstractMatcher.h"
#include "MatcherAnd.h"
#include "MatcherFalse.h"
#include "MatcherLabel.h"
#include "MatcherLoop.h"
#include "MatcherOptional.h"
#include "MatcherOr.h"
#include "MatcherTrue.h"
#include "Parsing/IParserValue.h"
#include "Utils/ClassUtils.h"
#include <memory>
#include "Utils/ClassUtils.h"
#include "AbstractMatcher.h"
#include "MatcherAnd.h"
#include "MatcherLabel.h"
#include "MatcherLoop.h"
#include "MatcherFalse.h"
#include "MatcherTrue.h"
#include "MatcherOptional.h"
#include "MatcherOr.h"
#include "Parsing/IParserValue.h"
template <typename TokenType>
class MatcherFactoryWrapper
template<typename TokenType> class MatcherFactoryWrapper
{
// TokenType must inherit IParserValue
static_assert(std::is_base_of<IParserValue, TokenType>::value);
@ -71,8 +70,7 @@ public:
}
};
template <typename TokenType>
class AbstractMatcherFactory
template<typename TokenType> class AbstractMatcherFactory
{
// TokenType must inherit IParserValue
static_assert(std::is_base_of<IParserValue, TokenType>::value);

View File

@ -1,13 +1,12 @@
#pragma once
#include "AbstractMatcher.h"
#include "Parsing/IParserValue.h"
#include <iterator>
#include <memory>
#include "Parsing/IParserValue.h"
#include "AbstractMatcher.h"
template <typename TokenType>
class MatcherAnd final : public AbstractMatcher<TokenType>
template<typename TokenType> class MatcherAnd final : public AbstractMatcher<TokenType>
{
// TokenType must inherit IParserValue
static_assert(std::is_base_of<IParserValue, TokenType>::value);
@ -25,10 +24,10 @@ protected:
if (!result.m_matches)
return MatcherResult<TokenType>::NoMatch();
matchResult.Absorb(std::move(result));
}
return matchResult;
}

View File

@ -1,12 +1,11 @@
#pragma once
#include "AbstractMatcher.h"
#include "Parsing/IParserValue.h"
#include <memory>
#include "Parsing/IParserValue.h"
#include "AbstractMatcher.h"
template <typename TokenType>
class MatcherFalse final : public AbstractMatcher<TokenType>
template<typename TokenType> class MatcherFalse final : public AbstractMatcher<TokenType>
{
// TokenType must inherit IParserValue
static_assert(std::is_base_of<IParserValue, TokenType>::value);
@ -18,6 +17,5 @@ protected:
}
public:
MatcherFalse()
= default;
MatcherFalse() = default;
};

View File

@ -1,13 +1,12 @@
#pragma once
#include "AbstractMatcher.h"
#include "Parsing/IParserValue.h"
#include "Utils/ClassUtils.h"
#include <cassert>
#include "Utils/ClassUtils.h"
#include "Parsing/IParserValue.h"
#include "AbstractMatcher.h"
template <typename TokenType>
class IMatcherForLabelSupplier
template<typename TokenType> class IMatcherForLabelSupplier
{
// TokenType must inherit IParserValue
static_assert(std::is_base_of<IParserValue, TokenType>::value);
@ -23,8 +22,7 @@ public:
_NODISCARD virtual AbstractMatcher<TokenType>* GetMatcherForLabel(int label) const = 0;
};
template <typename TokenType>
class MatcherLabel final : public AbstractMatcher<TokenType>
template<typename TokenType> class MatcherLabel final : public AbstractMatcher<TokenType>
{
// TokenType must inherit IParserValue
static_assert(std::is_base_of<IParserValue, TokenType>::value);

View File

@ -1,12 +1,11 @@
#pragma once
#include "AbstractMatcher.h"
#include "Parsing/IParserValue.h"
#include <memory>
#include "Parsing/IParserValue.h"
#include "AbstractMatcher.h"
template <typename TokenType>
class MatcherLoop final : public AbstractMatcher<TokenType>
template<typename TokenType> class MatcherLoop final : public AbstractMatcher<TokenType>
{
// TokenType must inherit IParserValue
static_assert(std::is_base_of<IParserValue, TokenType>::value);
@ -19,11 +18,11 @@ protected:
auto matchResult = MatcherResult<TokenType>::Match(0);
auto loopedAtLeastOnce = false;
while(true)
while (true)
{
auto result = m_matcher->Match(lexer, tokenOffset + matchResult.m_consumed_token_count);
if(!result.m_matches)
if (!result.m_matches)
{
if (loopedAtLeastOnce)
return matchResult;

View File

@ -1,12 +1,11 @@
#pragma once
#include "AbstractMatcher.h"
#include "Parsing/IParserValue.h"
#include <memory>
#include "Parsing/IParserValue.h"
#include "AbstractMatcher.h"
template <typename TokenType>
class MatcherOptional final : public AbstractMatcher<TokenType>
template<typename TokenType> class MatcherOptional final : public AbstractMatcher<TokenType>
{
// TokenType must inherit IParserValue
static_assert(std::is_base_of<IParserValue, TokenType>::value);

View File

@ -1,13 +1,12 @@
#pragma once
#include "AbstractMatcher.h"
#include "Parsing/IParserValue.h"
#include <iterator>
#include <memory>
#include "Parsing/IParserValue.h"
#include "AbstractMatcher.h"
template <typename TokenType>
class MatcherOr final : public AbstractMatcher<TokenType>
template<typename TokenType> class MatcherOr final : public AbstractMatcher<TokenType>
{
// TokenType must inherit IParserValue
static_assert(std::is_base_of<IParserValue, TokenType>::value);

View File

@ -1,14 +1,13 @@
#pragma once
#include "Parsing/IParserValue.h"
#include "Utils/ClassUtils.h"
#include <iterator>
#include <limits>
#include <vector>
#include "Utils/ClassUtils.h"
#include "Parsing/IParserValue.h"
template <typename TokenType>
class MatcherResult
template<typename TokenType> class MatcherResult
{
// TokenType must inherit IParserValue
static_assert(std::is_base_of<IParserValue, TokenType>::value);

View File

@ -1,12 +1,11 @@
#pragma once
#include "AbstractMatcher.h"
#include "Parsing/IParserValue.h"
#include <memory>
#include "Parsing/IParserValue.h"
#include "AbstractMatcher.h"
template <typename TokenType>
class MatcherTrue final : public AbstractMatcher<TokenType>
template<typename TokenType> class MatcherTrue final : public AbstractMatcher<TokenType>
{
// TokenType must inherit IParserValue
static_assert(std::is_base_of<IParserValue, TokenType>::value);
@ -18,6 +17,5 @@ protected:
}
public:
MatcherTrue()
= default;
MatcherTrue() = default;
};

View File

@ -1,11 +1,11 @@
#pragma once
#include <exception>
#include <string>
#include "TokenPos.h"
#include "Utils/ClassUtils.h"
#include <exception>
#include <string>
class ParsingException final : std::exception
{
TokenPos m_pos;

View File

@ -3,14 +3,14 @@
#include <memory>
#include <vector>
template <typename ParserType>
class AbstractScopeSequenceHolder
template<typename ParserType> class AbstractScopeSequenceHolder
{
std::vector<std::unique_ptr<typename ParserType::sequence_t>>& m_all_sequences;
std::vector<typename ParserType::sequence_t*>& m_scope_sequences;
protected:
AbstractScopeSequenceHolder(std::vector<std::unique_ptr<typename ParserType::sequence_t>>& allSequences, std::vector<typename ParserType::sequence_t*>& scopeSequences)
AbstractScopeSequenceHolder(std::vector<std::unique_ptr<typename ParserType::sequence_t>>& allSequences,
std::vector<typename ParserType::sequence_t*>& scopeSequences)
: m_all_sequences(allSequences),
m_scope_sequences(scopeSequences)
{

View File

@ -1,16 +1,15 @@
#pragma once
#include <unordered_map>
#include <cassert>
#include "SequenceResult.h"
#include "Utils/ClassUtils.h"
#include "Parsing/Matcher/AbstractMatcher.h"
#include "Parsing/Matcher/MatcherAnd.h"
#include "Parsing/Matcher/MatcherLabel.h"
#include "SequenceResult.h"
#include "Utils/ClassUtils.h"
template<typename TokenType, typename ParserState>
class AbstractSequence : protected IMatcherForLabelSupplier<TokenType>
#include <cassert>
#include <unordered_map>
template<typename TokenType, typename ParserState> class AbstractSequence : protected IMatcherForLabelSupplier<TokenType>
{
// TokenType must inherit IParserValue
static_assert(std::is_base_of<IParserValue, TokenType>::value);
@ -19,7 +18,6 @@ public:
typedef AbstractMatcher<TokenType> matcher_t;
private:
std::unique_ptr<matcher_t> m_entry;
std::unordered_map<int, std::unique_ptr<matcher_t>> m_matchers;
@ -80,7 +78,7 @@ public:
return false;
auto result = m_entry->Match(lexer, 0);
if (result.m_matches)
{
SequenceResult<TokenType> sequenceResult(lexer, result);

View File

@ -1,14 +1,13 @@
#pragma once
#include <unordered_map>
#include "Utils/ClassUtils.h"
#include "Parsing/Matcher/AbstractMatcher.h"
#include "Parsing/Matcher/MatcherResult.h"
#include "Parsing/ParsingException.h"
#include "Utils/ClassUtils.h"
template <typename TokenType>
class SequenceResult
#include <unordered_map>
template<typename TokenType> class SequenceResult
{
class Capture
{
@ -57,7 +56,7 @@ public:
if (m_tag_offset < m_tags.size())
{
const auto result = m_tags[m_tag_offset];
if (result == tag)
m_tag_offset++;
@ -92,7 +91,7 @@ public:
if (foundEntry == m_captures.end())
throw ParsingException(TokenPos(), "Tried to access next capture even though no captures exists!");
if(foundEntry->second.m_offset >= foundEntry->second.m_tokens.size())
if (foundEntry->second.m_offset >= foundEntry->second.m_tokens.size())
throw ParsingException(TokenPos(), "Tried to access next capture even though none exists!");
return foundEntry->second.m_tokens[foundEntry->second.m_offset++];

View File

@ -1,14 +1,16 @@
#pragma once
#include <string>
#include "Utils/ClassUtils.h"
#include <string>
class SimpleExpressionValue;
class ISimpleExpressionScopeValues
{
protected:
ISimpleExpressionScopeValues() = default;
public:
virtual ~ISimpleExpressionScopeValues() = default;
ISimpleExpressionScopeValues(const ISimpleExpressionScopeValues& other) = default;
@ -23,6 +25,7 @@ class ISimpleExpression
{
protected:
ISimpleExpression() = default;
public:
virtual ~ISimpleExpression() = default;
ISimpleExpression(const ISimpleExpression& other) = default;
@ -37,4 +40,4 @@ public:
};
// Include SimpleExpressionValue after definition to avoid "base class not defined"
#include "SimpleExpressionValue.h"
#include "SimpleExpressionValue.h"

View File

@ -3,7 +3,9 @@
#include <cassert>
#include <cmath>
SimpleExpressionBinaryOperationType::SimpleExpressionBinaryOperationType(const SimpleBinaryOperationId id, std::string syntax, const SimpleOperationPrecedence precedence,
SimpleExpressionBinaryOperationType::SimpleExpressionBinaryOperationType(const SimpleBinaryOperationId id,
std::string syntax,
const SimpleOperationPrecedence precedence,
evaluation_function_t evaluationFunction)
: m_id(id),
m_syntax(std::move(syntax)),
@ -47,8 +49,7 @@ const SimpleExpressionBinaryOperationType SimpleExpressionBinaryOperationType::O
}
return SimpleExpressionValue(0);
}
);
});
const SimpleExpressionBinaryOperationType SimpleExpressionBinaryOperationType::OPERATION_SUBTRACT(
SimpleBinaryOperationId::SUBTRACT,
@ -72,8 +73,7 @@ const SimpleExpressionBinaryOperationType SimpleExpressionBinaryOperationType::O
}
return SimpleExpressionValue(0);
}
);
});
const SimpleExpressionBinaryOperationType SimpleExpressionBinaryOperationType::OPERATION_MULTIPLY(
SimpleBinaryOperationId::MULTIPLY,
@ -97,8 +97,7 @@ const SimpleExpressionBinaryOperationType SimpleExpressionBinaryOperationType::O
}
return SimpleExpressionValue(0);
}
);
});
const SimpleExpressionBinaryOperationType SimpleExpressionBinaryOperationType::OPERATION_DIVIDE(
SimpleBinaryOperationId::DIVIDE,
@ -122,8 +121,7 @@ const SimpleExpressionBinaryOperationType SimpleExpressionBinaryOperationType::O
}
return SimpleExpressionValue(0);
}
);
});
const SimpleExpressionBinaryOperationType SimpleExpressionBinaryOperationType::OPERATION_REMAINDER(
SimpleBinaryOperationId::REMAINDER,
@ -135,8 +133,7 @@ const SimpleExpressionBinaryOperationType SimpleExpressionBinaryOperationType::O
return SimpleExpressionValue(operand1.m_int_value % operand2.m_int_value);
return SimpleExpressionValue(0);
}
);
});
const SimpleExpressionBinaryOperationType SimpleExpressionBinaryOperationType::OPERATION_BITWISE_AND(
SimpleBinaryOperationId::BITWISE_AND,
@ -148,8 +145,7 @@ const SimpleExpressionBinaryOperationType SimpleExpressionBinaryOperationType::O
return SimpleExpressionValue(operand1.m_int_value & operand2.m_int_value);
return SimpleExpressionValue(0);
}
);
});
const SimpleExpressionBinaryOperationType SimpleExpressionBinaryOperationType::OPERATION_BITWISE_OR(
SimpleBinaryOperationId::BITWISE_OR,
@ -161,8 +157,7 @@ const SimpleExpressionBinaryOperationType SimpleExpressionBinaryOperationType::O
return SimpleExpressionValue(operand1.m_int_value | operand2.m_int_value);
return SimpleExpressionValue(0);
}
);
});
const SimpleExpressionBinaryOperationType SimpleExpressionBinaryOperationType::OPERATION_SHIFT_LEFT(
SimpleBinaryOperationId::SHIFT_LEFT,
@ -174,8 +169,7 @@ const SimpleExpressionBinaryOperationType SimpleExpressionBinaryOperationType::O
return SimpleExpressionValue(operand1.m_int_value << operand2.m_int_value);
return SimpleExpressionValue(0);
}
);
});
const SimpleExpressionBinaryOperationType SimpleExpressionBinaryOperationType::OPERATION_SHIFT_RIGHT(
SimpleBinaryOperationId::SHIFT_RIGHT,
@ -187,8 +181,7 @@ const SimpleExpressionBinaryOperationType SimpleExpressionBinaryOperationType::O
return SimpleExpressionValue(operand1.m_int_value >> operand2.m_int_value);
return SimpleExpressionValue(0);
}
);
});
const SimpleExpressionBinaryOperationType SimpleExpressionBinaryOperationType::OPERATION_GREATER_THAN(
SimpleBinaryOperationId::GREATER_THAN,
@ -215,8 +208,7 @@ const SimpleExpressionBinaryOperationType SimpleExpressionBinaryOperationType::O
}
return SimpleExpressionValue(0);
}
);
});
const SimpleExpressionBinaryOperationType SimpleExpressionBinaryOperationType::OPERATION_GREATER_EQUAL_THAN(
SimpleBinaryOperationId::GREATER_EQUAL_THAN,
@ -243,8 +235,7 @@ const SimpleExpressionBinaryOperationType SimpleExpressionBinaryOperationType::O
}
return SimpleExpressionValue(0);
}
);
});
const SimpleExpressionBinaryOperationType SimpleExpressionBinaryOperationType::OPERATION_LESS_THAN(
SimpleBinaryOperationId::LESS_THAN,
@ -271,8 +262,7 @@ const SimpleExpressionBinaryOperationType SimpleExpressionBinaryOperationType::O
}
return SimpleExpressionValue(0);
}
);
});
const SimpleExpressionBinaryOperationType SimpleExpressionBinaryOperationType::OPERATION_LESS_EQUAL_THAN(
SimpleBinaryOperationId::LESS_EQUAL_THAN,
@ -299,8 +289,7 @@ const SimpleExpressionBinaryOperationType SimpleExpressionBinaryOperationType::O
}
return SimpleExpressionValue(0);
}
);
});
const SimpleExpressionBinaryOperationType SimpleExpressionBinaryOperationType::OPERATION_EQUALS(
SimpleBinaryOperationId::EQUALS,
@ -337,8 +326,7 @@ const SimpleExpressionBinaryOperationType SimpleExpressionBinaryOperationType::O
}
return SimpleExpressionValue(0);
}
);
});
const SimpleExpressionBinaryOperationType SimpleExpressionBinaryOperationType::OPERATION_NOT_EQUAL(
SimpleBinaryOperationId::NOT_EQUAL,
@ -375,35 +363,31 @@ const SimpleExpressionBinaryOperationType SimpleExpressionBinaryOperationType::O
}
return SimpleExpressionValue(0);
}
);
});
const SimpleExpressionBinaryOperationType SimpleExpressionBinaryOperationType::OPERATION_AND(
SimpleBinaryOperationId::AND,
"&&",
SimpleOperationPrecedence::LOGICAL_AND,
[](const SimpleExpressionValue& operand1, const SimpleExpressionValue& operand2) -> SimpleExpressionValue
{
if (operand1.IsTruthy())
return operand2;
return operand1;
}
);
const SimpleExpressionBinaryOperationType SimpleExpressionBinaryOperationType::OPERATION_AND(SimpleBinaryOperationId::AND,
"&&",
SimpleOperationPrecedence::LOGICAL_AND,
[](const SimpleExpressionValue& operand1,
const SimpleExpressionValue& operand2) -> SimpleExpressionValue
{
if (operand1.IsTruthy())
return operand2;
return operand1;
});
const SimpleExpressionBinaryOperationType SimpleExpressionBinaryOperationType::OPERATION_OR(
SimpleBinaryOperationId::OR,
"||",
SimpleOperationPrecedence::LOGICAL_OR,
[](const SimpleExpressionValue& operand1, const SimpleExpressionValue& operand2) -> SimpleExpressionValue
{
if (operand1.IsTruthy())
return operand1;
return operand2;
}
);
const SimpleExpressionBinaryOperationType SimpleExpressionBinaryOperationType::OPERATION_OR(SimpleBinaryOperationId::OR,
"||",
SimpleOperationPrecedence::LOGICAL_OR,
[](const SimpleExpressionValue& operand1,
const SimpleExpressionValue& operand2) -> SimpleExpressionValue
{
if (operand1.IsTruthy())
return operand1;
return operand2;
});
const SimpleExpressionBinaryOperationType* const SimpleExpressionBinaryOperationType::ALL_OPERATION_TYPES[static_cast<int>(SimpleBinaryOperationId::COUNT)]
{
const SimpleExpressionBinaryOperationType* const SimpleExpressionBinaryOperationType::ALL_OPERATION_TYPES[static_cast<int>(SimpleBinaryOperationId::COUNT)]{
&OPERATION_ADD,
&OPERATION_SUBTRACT,
&OPERATION_MULTIPLY,
@ -420,10 +404,10 @@ const SimpleExpressionBinaryOperationType* const SimpleExpressionBinaryOperation
&OPERATION_EQUALS,
&OPERATION_NOT_EQUAL,
&OPERATION_AND,
&OPERATION_OR
};
&OPERATION_OR};
SimpleExpressionBinaryOperation::SimpleExpressionBinaryOperation(const SimpleExpressionBinaryOperationType* operationType, std::unique_ptr<ISimpleExpression> operand1,
SimpleExpressionBinaryOperation::SimpleExpressionBinaryOperation(const SimpleExpressionBinaryOperationType* operationType,
std::unique_ptr<ISimpleExpression> operand1,
std::unique_ptr<ISimpleExpression> operand2)
: m_operation_type(operationType),
m_operand1(std::move(operand1)),
@ -447,10 +431,8 @@ bool SimpleExpressionBinaryOperation::Equals(const ISimpleExpression* other) con
{
const auto* otherBinaryOperation = dynamic_cast<const SimpleExpressionBinaryOperation*>(other);
return otherBinaryOperation
&& m_operation_type->m_id == otherBinaryOperation->m_operation_type->m_id
&& m_operand1->Equals(otherBinaryOperation->m_operand1.get())
&& m_operand2->Equals(otherBinaryOperation->m_operand2.get());
return otherBinaryOperation && m_operation_type->m_id == otherBinaryOperation->m_operation_type->m_id
&& m_operand1->Equals(otherBinaryOperation->m_operand1.get()) && m_operand2->Equals(otherBinaryOperation->m_operand2.get());
}
bool SimpleExpressionBinaryOperation::IsStatic() const

View File

@ -1,12 +1,12 @@
#pragma once
#include <string>
#include <memory>
#include <functional>
#include "ISimpleExpression.h"
#include "SimpleExpressionValue.h"
#include <functional>
#include <memory>
#include <string>
// https://en.cppreference.com/w/cpp/language/operator_precedence
enum class SimpleOperationPrecedence
{
@ -55,7 +55,10 @@ public:
evaluation_function_t m_evaluation_function;
private:
SimpleExpressionBinaryOperationType(SimpleBinaryOperationId id, std::string syntax, SimpleOperationPrecedence precedence, evaluation_function_t evaluationFunction);
SimpleExpressionBinaryOperationType(SimpleBinaryOperationId id,
std::string syntax,
SimpleOperationPrecedence precedence,
evaluation_function_t evaluationFunction);
public:
static const SimpleExpressionBinaryOperationType OPERATION_ADD;
@ -87,8 +90,8 @@ public:
std::unique_ptr<ISimpleExpression> m_operand2;
SimpleExpressionBinaryOperation(const SimpleExpressionBinaryOperationType* operationType,
std::unique_ptr<ISimpleExpression> operand1,
std::unique_ptr<ISimpleExpression> operand2);
std::unique_ptr<ISimpleExpression> operand1,
std::unique_ptr<ISimpleExpression> operand2);
_NODISCARD bool Operand1NeedsParenthesis() const;
_NODISCARD bool Operand2NeedsParenthesis() const;

View File

@ -1,9 +1,9 @@
#include "SimpleExpressionConditionalOperator.h"
SimpleExpressionConditionalOperator::SimpleExpressionConditionalOperator()
= default;
SimpleExpressionConditionalOperator::SimpleExpressionConditionalOperator() = default;
SimpleExpressionConditionalOperator::SimpleExpressionConditionalOperator(std::unique_ptr<ISimpleExpression> condition, std::unique_ptr<ISimpleExpression> trueExpression,
SimpleExpressionConditionalOperator::SimpleExpressionConditionalOperator(std::unique_ptr<ISimpleExpression> condition,
std::unique_ptr<ISimpleExpression> trueExpression,
std::unique_ptr<ISimpleExpression> falseExpression)
: m_condition(std::move(condition)),
m_true_value(std::move(trueExpression)),
@ -15,10 +15,8 @@ bool SimpleExpressionConditionalOperator::Equals(const ISimpleExpression* other)
{
const auto* otherConditionalOperator = dynamic_cast<const SimpleExpressionConditionalOperator*>(other);
return otherConditionalOperator
&& m_condition->Equals(otherConditionalOperator->m_condition.get())
&& m_true_value->Equals(otherConditionalOperator->m_true_value.get())
&& m_false_value->Equals(otherConditionalOperator->m_false_value.get());
return otherConditionalOperator && m_condition->Equals(otherConditionalOperator->m_condition.get())
&& m_true_value->Equals(otherConditionalOperator->m_true_value.get()) && m_false_value->Equals(otherConditionalOperator->m_false_value.get());
}
bool SimpleExpressionConditionalOperator::IsStatic() const
@ -33,7 +31,6 @@ SimpleExpressionValue SimpleExpressionConditionalOperator::EvaluateStatic() cons
SimpleExpressionValue SimpleExpressionConditionalOperator::EvaluateNonStatic(const ISimpleExpressionScopeValues* scopeValues) const
{
return m_condition->EvaluateNonStatic(scopeValues).IsTruthy()
? m_true_value->EvaluateNonStatic(scopeValues)
: m_false_value->EvaluateNonStatic(scopeValues);
return m_condition->EvaluateNonStatic(scopeValues).IsTruthy() ? m_true_value->EvaluateNonStatic(scopeValues)
: m_false_value->EvaluateNonStatic(scopeValues);
}

View File

@ -14,5 +14,7 @@ public:
_NODISCARD SimpleExpressionValue EvaluateNonStatic(const ISimpleExpressionScopeValues* scopeValues) const override;
SimpleExpressionConditionalOperator();
SimpleExpressionConditionalOperator(std::unique_ptr<ISimpleExpression> condition, std::unique_ptr<ISimpleExpression> trueExpression, std::unique_ptr<ISimpleExpression> falseExpression);
SimpleExpressionConditionalOperator(std::unique_ptr<ISimpleExpression> condition,
std::unique_ptr<ISimpleExpression> trueExpression,
std::unique_ptr<ISimpleExpression> falseExpression);
};

View File

@ -1,13 +1,13 @@
#include "SimpleExpressionMatchers.h"
#include "Parsing/Simple/Expression/SimpleExpressionBinaryOperation.h"
#include "Parsing/Simple/Expression/SimpleExpressionUnaryOperation.h"
#include "Parsing/Simple/Matcher/SimpleMatcherFactory.h"
#include "SimpleExpressionConditionalOperator.h"
#include <algorithm>
#include <list>
#include "SimpleExpressionConditionalOperator.h"
#include "Parsing/Simple/Matcher/SimpleMatcherFactory.h"
#include "Parsing/Simple/Expression/SimpleExpressionBinaryOperation.h"
#include "Parsing/Simple/Expression/SimpleExpressionUnaryOperation.h"
static constexpr int TAG_EXPRESSION = SimpleExpressionMatchers::TAG_OFFSET_EXPRESSION + 1;
static constexpr int TAG_OPERAND = SimpleExpressionMatchers::TAG_OFFSET_EXPRESSION + 2;
static constexpr int TAG_UNARY_OPERATION = SimpleExpressionMatchers::TAG_OFFSET_EXPRESSION + 3;
@ -29,7 +29,10 @@ SimpleExpressionMatchers::SimpleExpressionMatchers()
{
}
SimpleExpressionMatchers::SimpleExpressionMatchers(const bool enableStringOperands, const bool enableIdentifierOperands, const bool enableFloatingPointOperands, const bool enableIntOperands,
SimpleExpressionMatchers::SimpleExpressionMatchers(const bool enableStringOperands,
const bool enableIdentifierOperands,
const bool enableFloatingPointOperands,
const bool enableIntOperands,
const bool enableConditionalOperator)
: m_enable_string_operands(enableStringOperands),
m_enable_identifier_operands(enableIdentifierOperands),
@ -39,8 +42,7 @@ SimpleExpressionMatchers::SimpleExpressionMatchers(const bool enableStringOperan
{
}
SimpleExpressionMatchers::~SimpleExpressionMatchers()
= default;
SimpleExpressionMatchers::~SimpleExpressionMatchers() = default;
void SimpleExpressionMatchers::ApplyTokensToLexerConfig(SimpleLexer::Config& lexerConfig)
{
@ -63,14 +65,16 @@ void SimpleExpressionMatchers::ApplyTokensToLexerConfig(SimpleLexer::Config& lex
std::vector<const SimpleExpressionUnaryOperationType*> SimpleExpressionMatchers::EnabledUnaryOperations() const
{
return std::vector(&SimpleExpressionUnaryOperationType::ALL_OPERATION_TYPES[0],
&SimpleExpressionUnaryOperationType::ALL_OPERATION_TYPES[std::extent_v<decltype(SimpleExpressionUnaryOperationType::ALL_OPERATION_TYPES)>]);
return std::vector(
&SimpleExpressionUnaryOperationType::ALL_OPERATION_TYPES[0],
&SimpleExpressionUnaryOperationType::ALL_OPERATION_TYPES[std::extent_v<decltype(SimpleExpressionUnaryOperationType::ALL_OPERATION_TYPES)>]);
}
std::vector<const SimpleExpressionBinaryOperationType*> SimpleExpressionMatchers::EnabledBinaryOperations() const
{
return std::vector(&SimpleExpressionBinaryOperationType::ALL_OPERATION_TYPES[0],
&SimpleExpressionBinaryOperationType::ALL_OPERATION_TYPES[std::extent_v<decltype(SimpleExpressionBinaryOperationType::ALL_OPERATION_TYPES)>]);
return std::vector(
&SimpleExpressionBinaryOperationType::ALL_OPERATION_TYPES[0],
&SimpleExpressionBinaryOperationType::ALL_OPERATION_TYPES[std::extent_v<decltype(SimpleExpressionBinaryOperationType::ALL_OPERATION_TYPES)>]);
}
std::unique_ptr<ISimpleExpression> SimpleExpressionMatchers::ProcessExpressionInParenthesis(SequenceResult<SimpleParserValue>& result) const
@ -83,7 +87,8 @@ std::unique_ptr<ISimpleExpression> SimpleExpressionMatchers::ProcessExpressionIn
return processedEvaluation;
}
std::unique_ptr<ISimpleExpression> SimpleExpressionMatchers::ProcessConditionalOperation(std::unique_ptr<ISimpleExpression> condition, SequenceResult<SimpleParserValue>& result) const
std::unique_ptr<ISimpleExpression> SimpleExpressionMatchers::ProcessConditionalOperation(std::unique_ptr<ISimpleExpression> condition,
SequenceResult<SimpleParserValue>& result) const
{
auto trueExpression = ProcessExpression(result);
@ -194,19 +199,21 @@ std::unique_ptr<ISimpleExpression> SimpleExpressionMatchers::ProcessExpression(S
throw ParsingException(TokenPos(), "Expected EvaluationTag @ Evaluation");
}
operators.sort([](const std::pair<unsigned, const SimpleExpressionBinaryOperationType*>& p1, const std::pair<unsigned, const SimpleExpressionBinaryOperationType*>& p2)
{
if (p1.second->m_precedence != p2.second->m_precedence)
return p1.second->m_precedence > p2.second->m_precedence;
operators.sort(
[](const std::pair<unsigned, const SimpleExpressionBinaryOperationType*>& p1, const std::pair<unsigned, const SimpleExpressionBinaryOperationType*>& p2)
{
if (p1.second->m_precedence != p2.second->m_precedence)
return p1.second->m_precedence > p2.second->m_precedence;
return p1.first > p2.first;
});
return p1.first > p2.first;
});
while (!operators.empty())
{
const auto [operatorIndex, operatorType] = operators.back(); // This must not be a reference
auto operation = std::make_unique<SimpleExpressionBinaryOperation>(operatorType, std::move(operands[operatorIndex]), std::move(operands[operatorIndex + 1]));
auto operation =
std::make_unique<SimpleExpressionBinaryOperation>(operatorType, std::move(operands[operatorIndex]), std::move(operands[operatorIndex + 1]));
operands.erase(operands.begin() + static_cast<int>(operatorIndex));
operands[operatorIndex] = std::move(operation);
@ -256,48 +263,51 @@ std::unique_ptr<SimpleExpressionMatchers::matcher_t> SimpleExpressionMatchers::P
{
if (enabledBinaryOperation->m_syntax.size() > 1)
{
binaryOperationsMatchers.emplace_back(
create.MultiChar(MULTI_TOKEN_OFFSET_BINARY + static_cast<int>(enabledBinaryOperation->m_id))
.Transform([enabledBinaryOperation](const SimpleMatcherFactory::token_list_t& values)
{
return SimpleParserValue::Integer(values[0].get().GetPos(), static_cast<int>(enabledBinaryOperation->m_id));
}));
binaryOperationsMatchers.emplace_back(create.MultiChar(MULTI_TOKEN_OFFSET_BINARY + static_cast<int>(enabledBinaryOperation->m_id))
.Transform(
[enabledBinaryOperation](const SimpleMatcherFactory::token_list_t& values)
{
return SimpleParserValue::Integer(values[0].get().GetPos(),
static_cast<int>(enabledBinaryOperation->m_id));
}));
}
else if (!enabledBinaryOperation->m_syntax.empty())
{
binaryOperationsMatchers.emplace_back(
create.Char(enabledBinaryOperation->m_syntax[0])
.Transform([enabledBinaryOperation](const SimpleMatcherFactory::token_list_t& values)
{
return SimpleParserValue::Integer(values[0].get().GetPos(), static_cast<int>(enabledBinaryOperation->m_id));
}));
binaryOperationsMatchers.emplace_back(create.Char(enabledBinaryOperation->m_syntax[0])
.Transform(
[enabledBinaryOperation](const SimpleMatcherFactory::token_list_t& values)
{
return SimpleParserValue::Integer(values[0].get().GetPos(),
static_cast<int>(enabledBinaryOperation->m_id));
}));
}
}
const auto hasAddOperation = std::any_of(enabledBinaryOperations.begin(), enabledBinaryOperations.end(), [](const SimpleExpressionBinaryOperationType* type)
{
return type == &SimpleExpressionBinaryOperationType::OPERATION_ADD;
});
const auto hasSubtractOperation = std::any_of(enabledBinaryOperations.begin(), enabledBinaryOperations.end(), [](const SimpleExpressionBinaryOperationType* type)
{
return type == &SimpleExpressionBinaryOperationType::OPERATION_SUBTRACT;
});
const auto hasAddOperation = std::any_of(enabledBinaryOperations.begin(),
enabledBinaryOperations.end(),
[](const SimpleExpressionBinaryOperationType* type)
{
return type == &SimpleExpressionBinaryOperationType::OPERATION_ADD;
});
const auto hasSubtractOperation = std::any_of(enabledBinaryOperations.begin(),
enabledBinaryOperations.end(),
[](const SimpleExpressionBinaryOperationType* type)
{
return type == &SimpleExpressionBinaryOperationType::OPERATION_SUBTRACT;
});
if (hasAddOperation && hasSubtractOperation)
{
binaryOperationsMatchers.emplace_back(
create.Or({
create.IntegerWithSign(),
create.FloatingPointWithSign()
})
.NoConsume()
.Transform([](const SimpleMatcherFactory::token_list_t& values)
{
return SimpleParserValue::Integer(values[0].get().GetPos(), static_cast<int>(SimpleBinaryOperationId::ADD));
}));
binaryOperationsMatchers.emplace_back(create.Or({create.IntegerWithSign(), create.FloatingPointWithSign()})
.NoConsume()
.Transform(
[](const SimpleMatcherFactory::token_list_t& values)
{
return SimpleParserValue::Integer(values[0].get().GetPos(),
static_cast<int>(SimpleBinaryOperationId::ADD));
}));
}
return create.Or(std::move(binaryOperationsMatchers)).Capture(CAPTURE_BINARY_OPERATION_TYPE);
}
@ -320,21 +330,23 @@ std::unique_ptr<SimpleExpressionMatchers::matcher_t> SimpleExpressionMatchers::P
{
if (enabledUnaryOperation->m_syntax.size() > 1)
{
unaryOperationsMatchers.emplace_back(
create.MultiChar(MULTI_TOKEN_OFFSET_UNARY + static_cast<int>(enabledUnaryOperation->m_id))
.Transform([enabledUnaryOperation](const SimpleMatcherFactory::token_list_t& values)
{
return SimpleParserValue::Integer(values[0].get().GetPos(), static_cast<int>(enabledUnaryOperation->m_id));
}));
unaryOperationsMatchers.emplace_back(create.MultiChar(MULTI_TOKEN_OFFSET_UNARY + static_cast<int>(enabledUnaryOperation->m_id))
.Transform(
[enabledUnaryOperation](const SimpleMatcherFactory::token_list_t& values)
{
return SimpleParserValue::Integer(values[0].get().GetPos(),
static_cast<int>(enabledUnaryOperation->m_id));
}));
}
else if (!enabledUnaryOperation->m_syntax.empty())
{
unaryOperationsMatchers.emplace_back(
create.Char(enabledUnaryOperation->m_syntax[0])
.Transform([enabledUnaryOperation](const SimpleMatcherFactory::token_list_t& values)
{
return SimpleParserValue::Integer(values[0].get().GetPos(), static_cast<int>(enabledUnaryOperation->m_id));
}));
unaryOperationsMatchers.emplace_back(create.Char(enabledUnaryOperation->m_syntax[0])
.Transform(
[enabledUnaryOperation](const SimpleMatcherFactory::token_list_t& values)
{
return SimpleParserValue::Integer(values[0].get().GetPos(),
static_cast<int>(enabledUnaryOperation->m_id));
}));
}
}
@ -348,40 +360,23 @@ std::unique_ptr<SimpleExpressionMatchers::matcher_t> SimpleExpressionMatchers::P
if (!m_enable_conditional_operator)
return create.False();
return create.And({
create.Char('?').Tag(TAG_CONDITIONAL_OPERATOR),
create.Label(LABEL_EXPRESSION),
create.Char(':').Tag(TAG_CONDITIONAL_OPERATOR_SEPARATOR),
create.Label(LABEL_EXPRESSION),
create.True().Tag(TAG_CONDITIONAL_OPERATOR_END)
});
return create.And({create.Char('?').Tag(TAG_CONDITIONAL_OPERATOR),
create.Label(LABEL_EXPRESSION),
create.Char(':').Tag(TAG_CONDITIONAL_OPERATOR_SEPARATOR),
create.Label(LABEL_EXPRESSION),
create.True().Tag(TAG_CONDITIONAL_OPERATOR_END)});
}
std::unique_ptr<SimpleExpressionMatchers::matcher_t> SimpleExpressionMatchers::Expression(const supplier_t* labelSupplier) const
{
const SimpleMatcherFactory create(labelSupplier);
return create.And({
create.OptionalLoop(ParseUnaryOperationType(labelSupplier)),
create.Or({
create.And({
create.Char('('),
create.Label(LABEL_EXPRESSION),
create.Char(')').Tag(TAG_PARENTHESIS_END)
}).Tag(TAG_PARENTHESIS),
create.And({
create.True().Tag(TAG_OPERAND_EXT),
ParseOperandExtension(labelSupplier),
create.True().Tag(TAG_OPERAND_EXT_END)
}),
ParseOperand(labelSupplier)
}),
create.Optional(create.Or({
ParseConditionalOperator(labelSupplier),
create.And({
ParseBinaryOperationType(labelSupplier),
create.Label(LABEL_EXPRESSION)
}).Tag(TAG_BINARY_OPERATION)
}))
}).Tag(TAG_EXPRESSION);
return create
.And({create.OptionalLoop(ParseUnaryOperationType(labelSupplier)),
create.Or({create.And({create.Char('('), create.Label(LABEL_EXPRESSION), create.Char(')').Tag(TAG_PARENTHESIS_END)}).Tag(TAG_PARENTHESIS),
create.And({create.True().Tag(TAG_OPERAND_EXT), ParseOperandExtension(labelSupplier), create.True().Tag(TAG_OPERAND_EXT_END)}),
ParseOperand(labelSupplier)}),
create.Optional(create.Or({ParseConditionalOperator(labelSupplier),
create.And({ParseBinaryOperationType(labelSupplier), create.Label(LABEL_EXPRESSION)}).Tag(TAG_BINARY_OPERATION)}))})
.Tag(TAG_EXPRESSION);
}

View File

@ -1,16 +1,16 @@
#pragma once
#include <memory>
#include "Parsing/Matcher/AbstractMatcher.h"
#include "Parsing/Matcher/MatcherLabel.h"
#include "Parsing/Sequence/SequenceResult.h"
#include "Parsing/Simple/Expression/ISimpleExpression.h"
#include "Parsing/Simple/SimpleParserValue.h"
#include "SimpleExpressionBinaryOperation.h"
#include "SimpleExpressionUnaryOperation.h"
#include "Utils/ClassUtils.h"
#include "Parsing/Matcher/AbstractMatcher.h"
#include "Parsing/Matcher/MatcherLabel.h"
#include "Parsing/Simple/Expression/ISimpleExpression.h"
#include "Parsing/Sequence/SequenceResult.h"
#include "Parsing/Simple/SimpleParserValue.h"
#include <Parsing/Simple/SimpleLexer.h>
#include <memory>
class SimpleExpressionMatchers
{
@ -35,7 +35,8 @@ private:
public:
SimpleExpressionMatchers();
SimpleExpressionMatchers(bool enableStringOperands, bool enableIdentifierOperands, bool enableFloatingPointOperands, bool enableIntOperands, bool enableConditionalOperator);
SimpleExpressionMatchers(
bool enableStringOperands, bool enableIdentifierOperands, bool enableFloatingPointOperands, bool enableIntOperands, bool enableConditionalOperator);
virtual ~SimpleExpressionMatchers();
SimpleExpressionMatchers(const SimpleExpressionMatchers& other) = default;
SimpleExpressionMatchers(SimpleExpressionMatchers&& other) noexcept = default;
@ -56,7 +57,8 @@ private:
std::unique_ptr<matcher_t> ParseConditionalOperator(const supplier_t* labelSupplier) const;
std::unique_ptr<ISimpleExpression> ProcessExpressionInParenthesis(SequenceResult<SimpleParserValue>& result) const;
std::unique_ptr<ISimpleExpression> ProcessConditionalOperation(std::unique_ptr<ISimpleExpression> condition, SequenceResult<SimpleParserValue>& result) const;
std::unique_ptr<ISimpleExpression> ProcessConditionalOperation(std::unique_ptr<ISimpleExpression> condition,
SequenceResult<SimpleParserValue>& result) const;
std::unique_ptr<ISimpleExpression> ProcessOperand(SequenceResult<SimpleParserValue>& result) const;
public:
@ -64,4 +66,4 @@ public:
std::unique_ptr<ISimpleExpression> ProcessExpression(SequenceResult<SimpleParserValue>& result) const;
virtual void ApplyTokensToLexerConfig(SimpleLexer::Config& lexerConfig);
};
};

View File

@ -1,10 +1,10 @@
#pragma once
#include <string>
#include "ISimpleExpression.h"
#include "SimpleExpressionValue.h"
#include <string>
class SimpleExpressionScopeValue final : public ISimpleExpression
{
public:

View File

@ -1,59 +1,57 @@
#include "SimpleExpressionUnaryOperation.h"
#include <cassert>
#include "SimpleExpressionBinaryOperation.h"
SimpleExpressionUnaryOperationType::SimpleExpressionUnaryOperationType(const SimpleUnaryOperationId id, std::string syntax, evaluation_function_t evaluationFunction)
#include <cassert>
SimpleExpressionUnaryOperationType::SimpleExpressionUnaryOperationType(const SimpleUnaryOperationId id,
std::string syntax,
evaluation_function_t evaluationFunction)
: m_id(id),
m_syntax(std::move(syntax)),
m_evaluation_function(std::move(evaluationFunction))
{
}
const SimpleExpressionUnaryOperationType SimpleExpressionUnaryOperationType::OPERATION_NOT(
SimpleUnaryOperationId::NOT,
"!",
[](const SimpleExpressionValue& operand) -> SimpleExpressionValue
{
return SimpleExpressionValue(!operand.IsTruthy());
}
);
const SimpleExpressionUnaryOperationType SimpleExpressionUnaryOperationType::OPERATION_NOT(SimpleUnaryOperationId::NOT,
"!",
[](const SimpleExpressionValue& operand) -> SimpleExpressionValue
{
return SimpleExpressionValue(!operand.IsTruthy());
});
const SimpleExpressionUnaryOperationType SimpleExpressionUnaryOperationType::OPERATION_BITWISE_NOT(
SimpleUnaryOperationId::BITWISE_NOT,
"~",
[](const SimpleExpressionValue& operand) -> SimpleExpressionValue
{
if (operand.m_type == SimpleExpressionValue::Type::INT)
return SimpleExpressionValue(~operand.m_int_value);
const SimpleExpressionUnaryOperationType
SimpleExpressionUnaryOperationType::OPERATION_BITWISE_NOT(SimpleUnaryOperationId::BITWISE_NOT,
"~",
[](const SimpleExpressionValue& operand) -> SimpleExpressionValue
{
if (operand.m_type == SimpleExpressionValue::Type::INT)
return SimpleExpressionValue(~operand.m_int_value);
return SimpleExpressionValue(0);
}
);
return SimpleExpressionValue(0);
});
const SimpleExpressionUnaryOperationType SimpleExpressionUnaryOperationType::OPERATION_NEGATIVE(
SimpleUnaryOperationId::NEGATIVE,
"-",
[](const SimpleExpressionValue& operand) -> SimpleExpressionValue
{
if (operand.m_type == SimpleExpressionValue::Type::INT)
return SimpleExpressionValue(-operand.m_int_value);
if (operand.m_type == SimpleExpressionValue::Type::DOUBLE)
return SimpleExpressionValue(-operand.m_double_value);
const SimpleExpressionUnaryOperationType
SimpleExpressionUnaryOperationType::OPERATION_NEGATIVE(SimpleUnaryOperationId::NEGATIVE,
"-",
[](const SimpleExpressionValue& operand) -> SimpleExpressionValue
{
if (operand.m_type == SimpleExpressionValue::Type::INT)
return SimpleExpressionValue(-operand.m_int_value);
if (operand.m_type == SimpleExpressionValue::Type::DOUBLE)
return SimpleExpressionValue(-operand.m_double_value);
return SimpleExpressionValue(0);
}
);
return SimpleExpressionValue(0);
});
const SimpleExpressionUnaryOperationType* const SimpleExpressionUnaryOperationType::ALL_OPERATION_TYPES[static_cast<int>(SimpleUnaryOperationId::COUNT)]
{
const SimpleExpressionUnaryOperationType* const SimpleExpressionUnaryOperationType::ALL_OPERATION_TYPES[static_cast<int>(SimpleUnaryOperationId::COUNT)]{
&OPERATION_NOT,
&OPERATION_BITWISE_NOT,
&OPERATION_NEGATIVE,
};
SimpleExpressionUnaryOperation::SimpleExpressionUnaryOperation(const SimpleExpressionUnaryOperationType* operationType, std::unique_ptr<ISimpleExpression> operand)
SimpleExpressionUnaryOperation::SimpleExpressionUnaryOperation(const SimpleExpressionUnaryOperationType* operationType,
std::unique_ptr<ISimpleExpression> operand)
: m_operation_type(operationType),
m_operand(std::move(operand))
{
@ -68,7 +66,8 @@ bool SimpleExpressionUnaryOperation::Equals(const ISimpleExpression* other) cons
{
const auto* otherUnaryOperation = dynamic_cast<const SimpleExpressionUnaryOperation*>(other);
return otherUnaryOperation && m_operation_type->m_id == otherUnaryOperation->m_operation_type->m_id && m_operand->Equals(otherUnaryOperation->m_operand.get());
return otherUnaryOperation && m_operation_type->m_id == otherUnaryOperation->m_operation_type->m_id
&& m_operand->Equals(otherUnaryOperation->m_operand.get());
}
bool SimpleExpressionUnaryOperation::IsStatic() const

View File

@ -1,12 +1,12 @@
#pragma once
#include <string>
#include <memory>
#include <functional>
#include "ISimpleExpression.h"
#include "SimpleExpressionValue.h"
#include <functional>
#include <memory>
#include <string>
enum class SimpleUnaryOperationId
{
NOT,

View File

@ -1,12 +1,13 @@
#pragma once
#include <memory>
#include <string>
#include "ISimpleExpression.h"
#include "Utils/ClassUtils.h"
#include <memory>
#include <string>
class ISimpleExpression;
class SimpleExpressionValue final : public ISimpleExpression
{
public:
@ -19,6 +20,7 @@ public:
Type m_type;
std::shared_ptr<std::string> m_string_value;
union
{
double m_double_value;

View File

@ -1,9 +1,9 @@
#pragma once
#include <vector>
#include "Parsing/Simple/SimpleParserValue.h"
#include "Parsing/Matcher/AbstractMatcher.h"
#include "Parsing/Simple/SimpleParserValue.h"
#include <vector>
class SimpleMatcherAnyCharacterBesides final : public AbstractMatcher<SimpleParserValue>
{

View File

@ -8,7 +8,6 @@ SimpleMatcherCharacter::SimpleMatcherCharacter(const char c)
MatcherResult<SimpleParserValue> SimpleMatcherCharacter::CanMatch(ILexer<SimpleParserValue>* lexer, const unsigned tokenOffset)
{
const auto& token = lexer->GetToken(tokenOffset);
return token.m_type == SimpleParserValueType::CHARACTER && token.CharacterValue() == m_char
? MatcherResult<SimpleParserValue>::Match(1)
: MatcherResult<SimpleParserValue>::NoMatch();
return token.m_type == SimpleParserValueType::CHARACTER && token.CharacterValue() == m_char ? MatcherResult<SimpleParserValue>::Match(1)
: MatcherResult<SimpleParserValue>::NoMatch();
}

View File

@ -1,7 +1,7 @@
#pragma once
#include "Parsing/Simple/SimpleParserValue.h"
#include "Parsing/Matcher/AbstractMatcher.h"
#include "Parsing/Simple/SimpleParserValue.h"
class SimpleMatcherCharacter final : public AbstractMatcher<SimpleParserValue>
{

View File

@ -1,15 +1,15 @@
#pragma once
#include <string>
#include "Parsing/Simple/SimpleParserValue.h"
#include "Parsing/Matcher/AbstractMatcherFactory.h"
#include "Parsing/Simple/SimpleParserValue.h"
#include <string>
class SimpleMatcherFactory : public AbstractMatcherFactory<SimpleParserValue>
{
public:
explicit SimpleMatcherFactory(const IMatcherForLabelSupplier<SimpleParserValue>* labelSupplier);
_NODISCARD MatcherFactoryWrapper<SimpleParserValue> Type(SimpleParserValueType type) const;
_NODISCARD MatcherFactoryWrapper<SimpleParserValue> Keyword(std::string value) const;
_NODISCARD MatcherFactoryWrapper<SimpleParserValue> KeywordIgnoreCase(std::string value) const;

View File

@ -11,6 +11,6 @@ MatcherResult<SimpleParserValue> SimpleMatcherKeyword::CanMatch(ILexer<SimplePar
{
const auto& token = lexer->GetToken(tokenOffset);
return token.m_type == SimpleParserValueType::IDENTIFIER && token.IdentifierHash() == m_hash && token.IdentifierValue() == m_value
? MatcherResult<SimpleParserValue>::Match(1)
: MatcherResult<SimpleParserValue>::NoMatch();
? MatcherResult<SimpleParserValue>::Match(1)
: MatcherResult<SimpleParserValue>::NoMatch();
}

View File

@ -1,9 +1,9 @@
#pragma once
#include <string>
#include "Parsing/Simple/SimpleParserValue.h"
#include "Parsing/Matcher/AbstractMatcher.h"
#include "Parsing/Simple/SimpleParserValue.h"
#include <string>
class SimpleMatcherKeyword final : public AbstractMatcher<SimpleParserValue>
{

View File

@ -17,10 +17,14 @@ MatcherResult<SimpleParserValue> SimpleMatcherKeywordIgnoreCase::CanMatch(ILexer
return MatcherResult<SimpleParserValue>::NoMatch();
const auto& identifierValue = token.IdentifierValue();
const auto isEqual = std::equal(identifierValue.begin(), identifierValue.end(), m_value.begin(), m_value.end(), [](const char a, const char b)
{
return tolower(a) == b;
});
const auto isEqual = std::equal(identifierValue.begin(),
identifierValue.end(),
m_value.begin(),
m_value.end(),
[](const char a, const char b)
{
return tolower(a) == b;
});
if (isEqual)
return MatcherResult<SimpleParserValue>::Match(1);

View File

@ -1,9 +1,9 @@
#pragma once
#include <string>
#include "Parsing/Simple/SimpleParserValue.h"
#include "Parsing/Matcher/AbstractMatcher.h"
#include "Parsing/Simple/SimpleParserValue.h"
#include <string>
class SimpleMatcherKeywordIgnoreCase final : public AbstractMatcher<SimpleParserValue>
{

View File

@ -9,6 +9,6 @@ MatcherResult<SimpleParserValue> SimpleMatcherKeywordPrefix::CanMatch(ILexer<Sim
{
const auto& token = lexer->GetToken(tokenOffset);
return token.m_type == SimpleParserValueType::IDENTIFIER && token.IdentifierValue().compare(0, m_value.size(), m_value) == 0
? MatcherResult<SimpleParserValue>::Match(1)
: MatcherResult<SimpleParserValue>::NoMatch();
? MatcherResult<SimpleParserValue>::Match(1)
: MatcherResult<SimpleParserValue>::NoMatch();
}

View File

@ -1,9 +1,9 @@
#pragma once
#include <string>
#include "Parsing/Simple/SimpleParserValue.h"
#include "Parsing/Matcher/AbstractMatcher.h"
#include "Parsing/Simple/SimpleParserValue.h"
#include <string>
class SimpleMatcherKeywordPrefix final : public AbstractMatcher<SimpleParserValue>
{

View File

@ -1,7 +1,7 @@
#pragma once
#include "Parsing/Simple/SimpleParserValue.h"
#include "Parsing/Matcher/AbstractMatcher.h"
#include "Parsing/Simple/SimpleParserValue.h"
class SimpleMatcherMultiCharacter final : public AbstractMatcher<SimpleParserValue>
{

View File

@ -7,7 +7,5 @@ SimpleMatcherValueType::SimpleMatcherValueType(const SimpleParserValueType type)
MatcherResult<SimpleParserValue> SimpleMatcherValueType::CanMatch(ILexer<SimpleParserValue>* lexer, const unsigned tokenOffset)
{
return lexer->GetToken(tokenOffset).m_type == m_type
? MatcherResult<SimpleParserValue>::Match(1)
: MatcherResult<SimpleParserValue>::NoMatch();
return lexer->GetToken(tokenOffset).m_type == m_type ? MatcherResult<SimpleParserValue>::Match(1) : MatcherResult<SimpleParserValue>::NoMatch();
}

View File

@ -1,7 +1,7 @@
#pragma once
#include "Parsing/Simple/SimpleParserValue.h"
#include "Parsing/Matcher/AbstractMatcher.h"
#include "Parsing/Simple/SimpleParserValue.h"
class SimpleMatcherValueType final : public AbstractMatcher<SimpleParserValue>
{

View File

@ -9,7 +9,6 @@ SimpleMatcherValueTypeAndHasSignPrefix::SimpleMatcherValueTypeAndHasSignPrefix(c
MatcherResult<SimpleParserValue> SimpleMatcherValueTypeAndHasSignPrefix::CanMatch(ILexer<SimpleParserValue>* lexer, const unsigned tokenOffset)
{
const auto& token = lexer->GetToken(tokenOffset);
return token.m_type == m_type && token.m_has_sign_prefix == m_has_sign_prefix
? MatcherResult<SimpleParserValue>::Match(1)
: MatcherResult<SimpleParserValue>::NoMatch();
return token.m_type == m_type && token.m_has_sign_prefix == m_has_sign_prefix ? MatcherResult<SimpleParserValue>::Match(1)
: MatcherResult<SimpleParserValue>::NoMatch();
}

View File

@ -1,7 +1,7 @@
#pragma once
#include "Parsing/Simple/SimpleParserValue.h"
#include "Parsing/Matcher/AbstractMatcher.h"
#include "Parsing/Simple/SimpleParserValue.h"
class SimpleMatcherValueTypeAndHasSignPrefix final : public AbstractMatcher<SimpleParserValue>
{

View File

@ -1,9 +1,9 @@
#include "SimpleExpressionInterpreter.h"
#include "Utils/ClassUtils.h"
#include "Expression/SimpleExpressionMatchers.h"
#include "Matcher/SimpleMatcherFactory.h"
#include "Parsing/Impl/AbstractParser.h"
#include "Utils/ClassUtils.h"
class SimpleExpressionInterpreterParserState
{
@ -47,10 +47,7 @@ public:
protected:
const std::vector<sequence_t*>& GetTestsForState() override
{
static std::vector<sequence_t*> sequences
{
new SimpleExpressionInterpreterExpressionSequence()
};
static std::vector<sequence_t*> sequences{new SimpleExpressionInterpreterExpressionSequence()};
return sequences;
}
};

View File

@ -52,7 +52,8 @@ void SimpleLexer::AddMultiCharacterTokenConfigToLookup(Config::MultiCharacterTok
}
else
{
m_multi_character_token_lookup[firstCharacterValue] = std::make_unique<MultiCharacterTokenLookupEntry>(tokenConfig.m_id, std::move(tokenConfig.m_value));
m_multi_character_token_lookup[firstCharacterValue] =
std::make_unique<MultiCharacterTokenLookupEntry>(tokenConfig.m_id, std::move(tokenConfig.m_value));
}
}
@ -123,12 +124,13 @@ SimpleParserValue SimpleLexer::GetNextToken()
if (m_config.m_read_strings && c == '\"')
return SimpleParserValue::String(pos, new std::string(m_config.m_string_escape_sequences ? ReadStringWithEscapeSequences() : ReadString()));
if (m_config.m_read_integer_numbers && (isdigit(c) || (c == '+' || c == '-' || (m_config.m_read_floating_point_numbers && c == '.')) && isdigit(PeekChar())))
if (m_config.m_read_integer_numbers
&& (isdigit(c) || (c == '+' || c == '-' || (m_config.m_read_floating_point_numbers && c == '.')) && isdigit(PeekChar())))
{
bool hasSignPrefix;
int integerValue;
if(m_config.m_read_floating_point_numbers)
if (m_config.m_read_floating_point_numbers)
{
bool isFloatingPointValue;
double floatingPointValue;

View File

@ -1,12 +1,12 @@
#pragma once
#include "Parsing/Impl/AbstractLexer.h"
#include "SimpleParserValue.h"
#include <cstdint>
#include <limits>
#include <memory>
#include "SimpleParserValue.h"
#include "Parsing/Impl/AbstractLexer.h"
class SimpleLexer : public AbstractLexer<SimpleParserValue>
{
public:
@ -55,4 +55,4 @@ protected:
public:
explicit SimpleLexer(IParserLineStream* stream);
SimpleLexer(IParserLineStream* stream, Config config);
};
};

View File

@ -1,10 +1,10 @@
#pragma once
#include <string>
#include "Parsing/IParserValue.h"
#include "Utils/ClassUtils.h"
#include "Parsing/TokenPos.h"
#include "Utils/ClassUtils.h"
#include <string>
enum class SimpleParserValueType
{
@ -34,6 +34,7 @@ public:
SimpleParserValueType m_type;
size_t m_hash;
bool m_has_sign_prefix;
union ValueType
{
char char_value;

View File

@ -1,7 +1,7 @@
#pragma once
#include <string>
#include <functional>
#include <string>
class TokenPos
{