From bb877f87bb7d81b70f9aa85c49462bde1d440599 Mon Sep 17 00:00:00 2001 From: Jan Date: Thu, 18 Feb 2021 14:41:27 +0100 Subject: [PATCH] Add sequences for commands --- .../Parsing/Commands/CommandsFileReader.cpp | 28 +-- .../Parsing/Commands/Impl/CommandsLexer.cpp | 139 +++++++++++- .../Parsing/Commands/Impl/CommandsParser.cpp | 46 ++++ .../Parsing/Commands/Impl/CommandsParser.h | 18 +- .../Commands/Impl/CommandsParserState.cpp | 0 .../Commands/Impl/CommandsParserState.h | 6 + .../Commands/Impl/CommandsParserValue.cpp | 4 +- .../Commands/Impl/CommandsParserValue.h | 9 + .../Matcher/CommandsCommonMatchers.cpp | 200 ++++++++++++++++++ .../Commands/Matcher/CommandsCommonMatchers.h | 33 +++ .../Matcher/CommandsMatcherCharacter.cpp | 14 ++ .../Matcher/CommandsMatcherCharacter.h | 15 ++ .../Matcher/CommandsMatcherFactory.cpp | 40 ++++ .../Commands/Matcher/CommandsMatcherFactory.h | 19 ++ .../Matcher/CommandsMatcherKeyword.cpp | 16 ++ .../Commands/Matcher/CommandsMatcherKeyword.h | 18 ++ .../Matcher/CommandsMatcherValueType.cpp | 13 ++ .../Matcher/CommandsMatcherValueType.h | 15 ++ .../Commands/Sequence/SequenceAction.cpp | 41 ++++ .../Commands/Sequence/SequenceAction.h | 18 ++ .../Commands/Sequence/SequenceArrayCount.cpp | 23 ++ .../Commands/Sequence/SequenceArrayCount.h | 15 ++ .../Commands/Sequence/SequenceArraySize.cpp | 23 ++ .../Commands/Sequence/SequenceArraySize.h | 15 ++ .../Commands/Sequence/SequenceAsset.cpp | 21 ++ .../Parsing/Commands/Sequence/SequenceAsset.h | 15 ++ .../Commands/Sequence/SequenceBlock.cpp | 21 ++ .../Parsing/Commands/Sequence/SequenceBlock.h | 17 ++ .../Commands/Sequence/SequenceCondition.cpp | 27 +++ .../Commands/Sequence/SequenceCondition.h | 19 ++ .../Commands/Sequence/SequenceCount.cpp | 26 +++ .../Parsing/Commands/Sequence/SequenceCount.h | 18 ++ .../Commands/Sequence/SequenceGame.cpp | 19 ++ .../Parsing/Commands/Sequence/SequenceGame.h | 14 ++ .../Commands/Sequence/SequenceName.cpp | 21 ++ .../Parsing/Commands/Sequence/SequenceName.h | 14 ++ .../Commands/Sequence/SequenceReorder.cpp | 27 +++ .../Commands/Sequence/SequenceReorder.h | 17 ++ .../Commands/Sequence/SequenceReusable.cpp | 21 ++ .../Commands/Sequence/SequenceReusable.h | 14 ++ .../Sequence/SequenceScriptString.cpp | 21 ++ .../Commands/Sequence/SequenceScriptString.h | 14 ++ .../Commands/Sequence/SequenceSetBlock.cpp | 27 +++ .../Commands/Sequence/SequenceSetBlock.h | 15 ++ .../Commands/Sequence/SequenceString.cpp | 21 ++ .../Commands/Sequence/SequenceString.h | 14 ++ .../Parsing/Commands/Sequence/SequenceUse.cpp | 20 ++ .../Parsing/Commands/Sequence/SequenceUse.h | 14 ++ .../Parsing/Header/HeaderFileReader.cpp | 1 - 49 files changed, 1201 insertions(+), 25 deletions(-) create mode 100644 src/ZoneCodeGeneratorLib/Parsing/Commands/Impl/CommandsParserState.cpp create mode 100644 src/ZoneCodeGeneratorLib/Parsing/Commands/Impl/CommandsParserState.h create mode 100644 src/ZoneCodeGeneratorLib/Parsing/Commands/Matcher/CommandsCommonMatchers.cpp create mode 100644 src/ZoneCodeGeneratorLib/Parsing/Commands/Matcher/CommandsCommonMatchers.h create mode 100644 src/ZoneCodeGeneratorLib/Parsing/Commands/Matcher/CommandsMatcherCharacter.cpp create mode 100644 src/ZoneCodeGeneratorLib/Parsing/Commands/Matcher/CommandsMatcherCharacter.h create mode 100644 src/ZoneCodeGeneratorLib/Parsing/Commands/Matcher/CommandsMatcherFactory.cpp create mode 100644 src/ZoneCodeGeneratorLib/Parsing/Commands/Matcher/CommandsMatcherFactory.h create mode 100644 src/ZoneCodeGeneratorLib/Parsing/Commands/Matcher/CommandsMatcherKeyword.cpp create mode 100644 src/ZoneCodeGeneratorLib/Parsing/Commands/Matcher/CommandsMatcherKeyword.h create mode 100644 src/ZoneCodeGeneratorLib/Parsing/Commands/Matcher/CommandsMatcherValueType.cpp create mode 100644 src/ZoneCodeGeneratorLib/Parsing/Commands/Matcher/CommandsMatcherValueType.h create mode 100644 src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceAction.cpp create mode 100644 src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceAction.h create mode 100644 src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceArrayCount.cpp create mode 100644 src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceArrayCount.h create mode 100644 src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceArraySize.cpp create mode 100644 src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceArraySize.h create mode 100644 src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceAsset.cpp create mode 100644 src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceAsset.h create mode 100644 src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceBlock.cpp create mode 100644 src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceBlock.h create mode 100644 src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceCondition.cpp create mode 100644 src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceCondition.h create mode 100644 src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceCount.cpp create mode 100644 src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceCount.h create mode 100644 src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceGame.cpp create mode 100644 src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceGame.h create mode 100644 src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceName.cpp create mode 100644 src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceName.h create mode 100644 src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceReorder.cpp create mode 100644 src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceReorder.h create mode 100644 src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceReusable.cpp create mode 100644 src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceReusable.h create mode 100644 src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceScriptString.cpp create mode 100644 src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceScriptString.h create mode 100644 src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceSetBlock.cpp create mode 100644 src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceSetBlock.h create mode 100644 src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceString.cpp create mode 100644 src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceString.h create mode 100644 src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceUse.cpp create mode 100644 src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceUse.h diff --git a/src/ZoneCodeGeneratorLib/Parsing/Commands/CommandsFileReader.cpp b/src/ZoneCodeGeneratorLib/Parsing/Commands/CommandsFileReader.cpp index acf4dda4..e706fae5 100644 --- a/src/ZoneCodeGeneratorLib/Parsing/Commands/CommandsFileReader.cpp +++ b/src/ZoneCodeGeneratorLib/Parsing/Commands/CommandsFileReader.cpp @@ -1,9 +1,10 @@ #include "CommandsFileReader.h" +#include #include #include "Impl/CommandsLexer.h" -#include "Parsing/ParsingException.h" +#include "Impl/CommandsParser.h" #include "Parsing/Impl/CommentRemovingStreamProxy.h" #include "Parsing/Impl/DefinesStreamProxy.h" #include "Parsing/Impl/IncludingStreamProxy.h" @@ -53,24 +54,13 @@ bool CommandsFileReader::ReadCommandsFile(IDataRepository* repository) SetupStreamProxies(); - auto lexer = std::make_unique(m_stream); + const auto lexer = std::make_unique(m_stream); + const auto parser = std::make_unique(lexer.get(), repository); - try - { - while (true) - { - auto line = m_stream->NextLine(); + const auto start = std::chrono::steady_clock::now(); + const auto result = parser->Parse(); + const auto end = std::chrono::steady_clock::now(); + std::cout << "Processing commands took " << std::chrono::duration_cast(end - start).count() << "ms" << std::endl; - if (line.IsEof()) - break; - - std::cout << "Line " << line.m_filename.get() << ":" << line.m_line_number << ": " << line.m_line << "\n"; - } - } - catch (const ParsingException& e) - { - std::cout << "Error: " << e.FullMessage() << std::endl; - } - - return true; + return result; } diff --git a/src/ZoneCodeGeneratorLib/Parsing/Commands/Impl/CommandsLexer.cpp b/src/ZoneCodeGeneratorLib/Parsing/Commands/Impl/CommandsLexer.cpp index 45b01ad8..99d66933 100644 --- a/src/ZoneCodeGeneratorLib/Parsing/Commands/Impl/CommandsLexer.cpp +++ b/src/ZoneCodeGeneratorLib/Parsing/Commands/Impl/CommandsLexer.cpp @@ -7,5 +7,142 @@ CommandsLexer::CommandsLexer(IParserLineStream* stream) CommandsParserValue CommandsLexer::GetNextToken() { - return CommandsParserValue::Invalid(TokenPos()); + auto c = NextChar(); + + while (c != EOF) + { + switch (c) + { + case '\"': + { + return CommandsParserValue::String(GetPreviousCharacterPos(), new std::string(ReadString())); + } + + case '<': + { + if (!IsLineEnd()) + { + const auto pos = GetPreviousCharacterPos(); + const auto nextChar = PeekChar(); + + if (nextChar == '=') + { + NextChar(); + return CommandsParserValue::LessEqual(pos); + } + if (nextChar == '<') + { + NextChar(); + return CommandsParserValue::ShiftLeft(pos); + } + } + + return CommandsParserValue::Character(GetPreviousCharacterPos(), static_cast(c)); + } + + case '>': + { + if (!IsLineEnd()) + { + const auto pos = GetPreviousCharacterPos(); + const auto nextChar = PeekChar(); + + if (nextChar == '=') + { + NextChar(); + return CommandsParserValue::GreaterEqual(pos); + } + if (nextChar == '>') + { + NextChar(); + return CommandsParserValue::ShiftRight(pos); + } + } + + return CommandsParserValue::Character(GetPreviousCharacterPos(), static_cast(c)); + } + + case '=': + { + if (NextCharInLineIs('=')) + { + const auto pos = GetPreviousCharacterPos(); + NextChar(); + return CommandsParserValue::Equals(pos); + } + + return CommandsParserValue::Character(GetPreviousCharacterPos(), static_cast(c)); + } + + case '&': + { + if (NextCharInLineIs('&')) + { + const auto pos = GetPreviousCharacterPos(); + NextChar(); + return CommandsParserValue::LogicalAnd(pos); + } + + return CommandsParserValue::Character(GetPreviousCharacterPos(), static_cast(c)); + } + + case '|': + { + if (NextCharInLineIs('|')) + { + const auto pos = GetPreviousCharacterPos(); + NextChar(); + return CommandsParserValue::LogicalOr(pos); + } + + return CommandsParserValue::Character(GetPreviousCharacterPos(), static_cast(c)); + } + + case '!': + { + if (NextCharInLineIs('=')) + { + const auto pos = GetPreviousCharacterPos(); + NextChar(); + return CommandsParserValue::NotEqual(pos); + } + + return CommandsParserValue::Character(GetPreviousCharacterPos(), static_cast(c)); + } + + default: + { + if (isspace(c)) + break; + + const auto pos = GetPreviousCharacterPos(); + if (isdigit(c)) + { + bool isFloatingPointValue; + double doubleValue; + int integerValue; + + ReadNumber(isFloatingPointValue, doubleValue, integerValue); + + if (isFloatingPointValue) + return CommandsParserValue::FloatingPoint(pos, doubleValue); + + return CommandsParserValue::Integer(pos, integerValue); + } + + if (isalpha(c) || c == '_') + { + auto identifier = ReadIdentifier(); + + return CommandsParserValue::Identifier(pos, new std::string(std::move(identifier))); + } + + return CommandsParserValue::Character(pos, static_cast(c)); + } + } + + c = NextChar(); + } + + return CommandsParserValue::EndOfFile(TokenPos()); } diff --git a/src/ZoneCodeGeneratorLib/Parsing/Commands/Impl/CommandsParser.cpp b/src/ZoneCodeGeneratorLib/Parsing/Commands/Impl/CommandsParser.cpp index e69de29b..fa4ed298 100644 --- a/src/ZoneCodeGeneratorLib/Parsing/Commands/Impl/CommandsParser.cpp +++ b/src/ZoneCodeGeneratorLib/Parsing/Commands/Impl/CommandsParser.cpp @@ -0,0 +1,46 @@ +#include "CommandsParser.h" + +#include "Parsing/Commands/Sequence/SequenceAction.h" +#include "Parsing/Commands/Sequence/SequenceArrayCount.h" +#include "Parsing/Commands/Sequence/SequenceArraySize.h" +#include "Parsing/Commands/Sequence/SequenceAsset.h" +#include "Parsing/Commands/Sequence/SequenceBlock.h" +#include "Parsing/Commands/Sequence/SequenceCondition.h" +#include "Parsing/Commands/Sequence/SequenceCount.h" +#include "Parsing/Commands/Sequence/SequenceGame.h" +#include "Parsing/Commands/Sequence/SequenceName.h" +#include "Parsing/Commands/Sequence/SequenceReorder.h" +#include "Parsing/Commands/Sequence/SequenceReusable.h" +#include "Parsing/Commands/Sequence/SequenceScriptString.h" +#include "Parsing/Commands/Sequence/SequenceSetBlock.h" +#include "Parsing/Commands/Sequence/SequenceString.h" +#include "Parsing/Commands/Sequence/SequenceUse.h" + +CommandsParser::CommandsParser(CommandsLexer* lexer, IDataRepository* targetRepository) + : AbstractParser(lexer, std::make_unique()), + m_repository(targetRepository) +{ +} + +const std::vector& CommandsParser::GetTestsForState() +{ + static std::vector tests({ + new SequenceAction(), + new SequenceArrayCount(), + new SequenceArraySize(), + new SequenceAsset(), + new SequenceBlock(), + new SequenceCondition(), + new SequenceCount(), + new SequenceGame(), + new SequenceName(), + new SequenceReorder(), + new SequenceReusable(), + new SequenceScriptString(), + new SequenceSetBlock(), + new SequenceString(), + new SequenceUse() + }); + + return tests; +} diff --git a/src/ZoneCodeGeneratorLib/Parsing/Commands/Impl/CommandsParser.h b/src/ZoneCodeGeneratorLib/Parsing/Commands/Impl/CommandsParser.h index 3b8ed562..b77c5e84 100644 --- a/src/ZoneCodeGeneratorLib/Parsing/Commands/Impl/CommandsParser.h +++ b/src/ZoneCodeGeneratorLib/Parsing/Commands/Impl/CommandsParser.h @@ -1,6 +1,18 @@ #pragma once -class CommandsParser +#include "CommandsLexer.h" +#include "CommandsParserState.h" +#include "CommandsParserValue.h" +#include "Parsing/Impl/AbstractParser.h" +#include "Persistence/IDataRepository.h" + +class CommandsParser final : public AbstractParser { - -}; \ No newline at end of file + IDataRepository* m_repository; + +protected: + const std::vector& GetTestsForState() override; + +public: + CommandsParser(CommandsLexer* lexer, IDataRepository* targetRepository); +}; diff --git a/src/ZoneCodeGeneratorLib/Parsing/Commands/Impl/CommandsParserState.cpp b/src/ZoneCodeGeneratorLib/Parsing/Commands/Impl/CommandsParserState.cpp new file mode 100644 index 00000000..e69de29b diff --git a/src/ZoneCodeGeneratorLib/Parsing/Commands/Impl/CommandsParserState.h b/src/ZoneCodeGeneratorLib/Parsing/Commands/Impl/CommandsParserState.h new file mode 100644 index 00000000..33856f96 --- /dev/null +++ b/src/ZoneCodeGeneratorLib/Parsing/Commands/Impl/CommandsParserState.h @@ -0,0 +1,6 @@ +#pragma once + +class CommandsParserState +{ +public: +}; \ No newline at end of file diff --git a/src/ZoneCodeGeneratorLib/Parsing/Commands/Impl/CommandsParserValue.cpp b/src/ZoneCodeGeneratorLib/Parsing/Commands/Impl/CommandsParserValue.cpp index 18d48e38..a0b4493b 100644 --- a/src/ZoneCodeGeneratorLib/Parsing/Commands/Impl/CommandsParserValue.cpp +++ b/src/ZoneCodeGeneratorLib/Parsing/Commands/Impl/CommandsParserValue.cpp @@ -131,7 +131,8 @@ CommandsParserValue::~CommandsParserValue() } CommandsParserValue::CommandsParserValue(CommandsParserValue&& other) noexcept - : m_type(other.m_type), + : m_pos(other.m_pos), + m_type(other.m_type), m_hash(other.m_hash), m_value(other.m_value) { @@ -140,6 +141,7 @@ CommandsParserValue::CommandsParserValue(CommandsParserValue&& other) noexcept CommandsParserValue& CommandsParserValue::operator=(CommandsParserValue&& other) noexcept { + m_pos = other.m_pos; m_type = other.m_type; m_value = other.m_value; m_hash = other.m_hash; diff --git a/src/ZoneCodeGeneratorLib/Parsing/Commands/Impl/CommandsParserValue.h b/src/ZoneCodeGeneratorLib/Parsing/Commands/Impl/CommandsParserValue.h index d2c452bf..44dd5089 100644 --- a/src/ZoneCodeGeneratorLib/Parsing/Commands/Impl/CommandsParserValue.h +++ b/src/ZoneCodeGeneratorLib/Parsing/Commands/Impl/CommandsParserValue.h @@ -26,6 +26,15 @@ enum class CommandsParserValueType LOGICAL_AND, LOGICAL_OR, + // Built-in types + BUILT_IN_FIRST, + UNSIGNED = BUILT_IN_FIRST, + CHAR, + SHORT, + INT, + LONG, + BUILT_IN_LAST = LONG, + // Generic token types INTEGER, FLOATING_POINT, diff --git a/src/ZoneCodeGeneratorLib/Parsing/Commands/Matcher/CommandsCommonMatchers.cpp b/src/ZoneCodeGeneratorLib/Parsing/Commands/Matcher/CommandsCommonMatchers.cpp new file mode 100644 index 00000000..3c42a878 --- /dev/null +++ b/src/ZoneCodeGeneratorLib/Parsing/Commands/Matcher/CommandsCommonMatchers.cpp @@ -0,0 +1,200 @@ +#include "CommandsCommonMatchers.h" + +#include + +#include "CommandsMatcherFactory.h" + +std::unique_ptr CommandsCommonMatchers::Typename(const supplier_t* labelSupplier) +{ + static constexpr const char* BUILT_IN_TYPE_NAMES[] + { + "unsigned", + "char", + "short", + "int", + "long" + }; + static_assert(_countof(BUILT_IN_TYPE_NAMES) == static_cast(CommandsParserValueType::BUILT_IN_LAST) - static_cast(CommandsParserValueType::BUILT_IN_FIRST) + 1); + + const CommandsMatcherFactory create(labelSupplier); + + return create.Or({ + create.And({ + create.Optional(create.Type(CommandsParserValueType::UNSIGNED)), + create.Or({ + create.Type(CommandsParserValueType::CHAR), + create.Type(CommandsParserValueType::SHORT), + create.Type(CommandsParserValueType::INT), + create.And({ + create.Type(CommandsParserValueType::LONG), + create.Optional(create.Type(CommandsParserValueType::LONG)) + }) + }) + }).Transform([](CommandsMatcherFactory::token_list_t& values) + { + std::ostringstream str; + auto first = false; + + for (const auto& token : values) + { + if (first) + first = false; + else + str << " "; + str << BUILT_IN_TYPE_NAMES[static_cast(token.get().m_type) - static_cast(CommandsParserValueType::BUILT_IN_FIRST)]; + } + + return CommandsParserValue::TypeName(values[0].get().GetPos(), new std::string(str.str())); + }), + create.And({ + create.Identifier(), + create.OptionalLoop(create.And({ + create.Char(':'), + create.Char(':'), + create.Identifier() + })) + }).Transform([](CommandsMatcherFactory::token_list_t& values) + { + std::ostringstream str; + str << values[0].get().IdentifierValue(); + + for (auto i = 3u; i < values.size(); i += 3) + str << "::" << values[i].get().IdentifierValue(); + + return CommandsParserValue::TypeName(values[0].get().GetPos(), new std::string(str.str())); + }) + }); +} + +std::unique_ptr CommandsCommonMatchers::ArrayDef(const supplier_t* labelSupplier) +{ + const CommandsMatcherFactory create(labelSupplier); + + return create.And({ + create.Char('['), + create.Or({ + create.Integer(), + create.Identifier() + }), + create.Char(']') + }).Transform([](CommandsMatcherFactory::token_list_t& values) + { + if (values[1].get().m_type == CommandsParserValueType::INTEGER) + return CommandsParserValue::Integer(values[1].get().GetPos(), values[1].get().IntegerValue()); + + return CommandsParserValue::Identifier(values[1].get().GetPos(), new std::string(values[1].get().IdentifierValue())); + }); +} + +static constexpr int TAG_OPERATION_TYPE = std::numeric_limits::max() - 1; +static constexpr int TAG_ADD = std::numeric_limits::max() - 2; +static constexpr int TAG_MINUS = std::numeric_limits::max() - 3; +static constexpr int TAG_MULTIPLY = std::numeric_limits::max() - 4; +static constexpr int TAG_DIVIDE = std::numeric_limits::max() - 5; +static constexpr int TAG_REMAINDER = std::numeric_limits::max() - 6; +static constexpr int TAG_BITWISE_AND = std::numeric_limits::max() - 7; +static constexpr int TAG_BITWISE_XOR = std::numeric_limits::max() - 8; +static constexpr int TAG_BITWISE_OR = std::numeric_limits::max() - 9; +static constexpr int TAG_SHIFT_LEFT = std::numeric_limits::max() - 10; +static constexpr int TAG_SHIFT_RIGHT = std::numeric_limits::max() - 11; +static constexpr int TAG_GREATER_THAN = std::numeric_limits::max() - 12; +static constexpr int TAG_GREATER_EQUAL = std::numeric_limits::max() - 13; +static constexpr int TAG_LESS_THAN = std::numeric_limits::max() - 14; +static constexpr int TAG_LESS_EQUAL = std::numeric_limits::max() - 15; +static constexpr int TAG_EQUALS = std::numeric_limits::max() - 16; +static constexpr int TAG_NOT_EQUAL = std::numeric_limits::max() - 17; +static constexpr int TAG_LOGICAL_AND = std::numeric_limits::max() - 18; +static constexpr int TAG_LOGICAL_OR = std::numeric_limits::max() - 19; +static constexpr int TAG_OPERAND = std::numeric_limits::max() - 20; +static constexpr int TAG_OPERAND_TYPENAME = std::numeric_limits::max() - 21; +static constexpr int TAG_OPERAND_ARRAY = std::numeric_limits::max() - 22; +static constexpr int TAG_OPERAND_ARRAY_END = std::numeric_limits::max() - 23; +static constexpr int TAG_OPERAND_INTEGER = std::numeric_limits::max() - 24; +static constexpr int TAG_OPERAND_FLOATING_POINT = std::numeric_limits::max() - 25; +static constexpr int TAG_EVALUATION_NOT = std::numeric_limits::max() - 26; +static constexpr int TAG_EVALUATION_PARENTHESIS = std::numeric_limits::max() - 27; +static constexpr int TAG_EVALUATION_PARENTHESIS_END = std::numeric_limits::max() - 28; +static constexpr int TAG_EVALUATION = std::numeric_limits::max() - 29; +static constexpr int TAG_EVALUATION_OPERATION = std::numeric_limits::max() - 30; + +static constexpr int CAPTURE_OPERAND_TYPENAME = std::numeric_limits::max() - 1; +static constexpr int CAPTURE_OPERAND_ARRAY = std::numeric_limits::max() - 1; +static constexpr int CAPTURE_OPERAND_INTEGER = std::numeric_limits::max() - 2; +static constexpr int CAPTURE_OPERAND_FLOATING_POINT = std::numeric_limits::max() - 3; + +std::unique_ptr CommandsCommonMatchers::OperandArray(const supplier_t* labelSupplier) +{ + const CommandsMatcherFactory create(labelSupplier); + + return create.And({ + create.Char('['), + create.Label(LABEL_EVALUATION), + create.Char(']').Tag(TAG_OPERAND_ARRAY_END) + }).Tag(TAG_OPERAND_ARRAY); +} + +std::unique_ptr CommandsCommonMatchers::Operand(const supplier_t* labelSupplier) +{ + const CommandsMatcherFactory create(labelSupplier); + + return create.Or({ + create.And({ + create.Label(LABEL_TYPENAME).Capture(CAPTURE_OPERAND_TYPENAME), + create.OptionalLoop(MatcherFactoryWrapper(OperandArray(labelSupplier)).Capture(CAPTURE_OPERAND_ARRAY)) + }).Tag(TAG_OPERAND_TYPENAME), + create.Integer().Tag(TAG_OPERAND_INTEGER).Capture(CAPTURE_OPERAND_INTEGER), + create.FloatingPoint().Tag(TAG_OPERAND_FLOATING_POINT).Capture(CAPTURE_OPERAND_FLOATING_POINT) + }).Tag(TAG_OPERAND); +} + +std::unique_ptr CommandsCommonMatchers::OperationType(const supplier_t* labelSupplier) +{ + const CommandsMatcherFactory create(labelSupplier); + + return create.Or({ + create.Char('+').Tag(TAG_ADD), + create.Char('-').Tag(TAG_MINUS), + create.Char('*').Tag(TAG_MULTIPLY), + create.Char('/').Tag(TAG_DIVIDE), + create.Char('%').Tag(TAG_REMAINDER), + create.Char('&').Tag(TAG_BITWISE_AND), + create.Char('^').Tag(TAG_BITWISE_XOR), + create.Char('|').Tag(TAG_BITWISE_OR), + create.Type(CommandsParserValueType::SHIFT_LEFT).Tag(TAG_SHIFT_LEFT), + create.Type(CommandsParserValueType::SHIFT_RIGHT).Tag(TAG_SHIFT_RIGHT), + create.Char('>').Tag(TAG_GREATER_THAN), + create.Type(CommandsParserValueType::GREATER_EQUAL).Tag(TAG_GREATER_EQUAL), + create.Char('<').Tag(TAG_LESS_THAN), + create.Type(CommandsParserValueType::LESS_EQUAL).Tag(TAG_LESS_EQUAL), + create.Type(CommandsParserValueType::EQUALS).Tag(TAG_EQUALS), + create.Type(CommandsParserValueType::NOT_EQUAL).Tag(TAG_NOT_EQUAL), + create.Type(CommandsParserValueType::LOGICAL_AND).Tag(TAG_LOGICAL_AND), + create.Type(CommandsParserValueType::LOGICAL_OR).Tag(TAG_LOGICAL_OR) + }).Tag(TAG_OPERATION_TYPE); +} + +std::unique_ptr CommandsCommonMatchers::Evaluation(const supplier_t* labelSupplier) +{ + const CommandsMatcherFactory create(labelSupplier); + + return create.And({ + create.Or({ + create.And({ + create.Optional(create.Char('!').Tag(TAG_EVALUATION_NOT)), + create.Char('('), + create.Label(LABEL_EVALUATION), + create.Char(')').Tag(TAG_EVALUATION_PARENTHESIS_END) + }).Tag(TAG_EVALUATION_PARENTHESIS), + Operand(labelSupplier) + }), + create.Optional(create.And({ + OperationType(labelSupplier), + create.Label(LABEL_EVALUATION) + })).Tag(TAG_EVALUATION_OPERATION) + }).Tag(TAG_EVALUATION); +} + +std::unique_ptr CommandsCommonMatchers::ParseEvaluation(SequenceResult& result) +{ + return nullptr; +} diff --git a/src/ZoneCodeGeneratorLib/Parsing/Commands/Matcher/CommandsCommonMatchers.h b/src/ZoneCodeGeneratorLib/Parsing/Commands/Matcher/CommandsCommonMatchers.h new file mode 100644 index 00000000..5a9568bb --- /dev/null +++ b/src/ZoneCodeGeneratorLib/Parsing/Commands/Matcher/CommandsCommonMatchers.h @@ -0,0 +1,33 @@ +#pragma once + +#include +#include + +#include "Domain/Evaluation/IEvaluation.h" +#include "Parsing/Commands/Impl/CommandsParserValue.h" +#include "Parsing/Matcher/AbstractMatcher.h" +#include "Parsing/Matcher/MatcherLabel.h" +#include "Parsing/Sequence/SequenceResult.h" + +class CommandsCommonMatchers +{ +public: + typedef AbstractMatcher matcher_t; + typedef IMatcherForLabelSupplier supplier_t; + + static constexpr int LABEL_TYPENAME = std::numeric_limits::max() - 1; + static constexpr int LABEL_ARRAY_DEF = std::numeric_limits::max() - 2; + static constexpr int LABEL_EVALUATION = std::numeric_limits::max() - 3; + + static std::unique_ptr Typename(const supplier_t* labelSupplier); + static std::unique_ptr ArrayDef(const supplier_t* labelSupplier); + +private: + static std::unique_ptr OperandArray(const supplier_t* labelSupplier); + static std::unique_ptr Operand(const supplier_t* labelSupplier); + static std::unique_ptr OperationType(const supplier_t* labelSupplier); + +public: + static std::unique_ptr Evaluation(const supplier_t* labelSupplier); + static std::unique_ptr ParseEvaluation(SequenceResult& result); +}; diff --git a/src/ZoneCodeGeneratorLib/Parsing/Commands/Matcher/CommandsMatcherCharacter.cpp b/src/ZoneCodeGeneratorLib/Parsing/Commands/Matcher/CommandsMatcherCharacter.cpp new file mode 100644 index 00000000..7ed5c9de --- /dev/null +++ b/src/ZoneCodeGeneratorLib/Parsing/Commands/Matcher/CommandsMatcherCharacter.cpp @@ -0,0 +1,14 @@ +#include "CommandsMatcherCharacter.h" + +CommandsMatcherCharacter::CommandsMatcherCharacter(const char c) + : m_char(c) +{ +} + +MatcherResult CommandsMatcherCharacter::CanMatch(ILexer* lexer, const unsigned tokenOffset) +{ + const auto& token = lexer->GetToken(tokenOffset); + return token.m_type == CommandsParserValueType::CHARACTER && token.CharacterValue() == m_char + ? MatcherResult::Match(1) + : MatcherResult::NoMatch(); +} diff --git a/src/ZoneCodeGeneratorLib/Parsing/Commands/Matcher/CommandsMatcherCharacter.h b/src/ZoneCodeGeneratorLib/Parsing/Commands/Matcher/CommandsMatcherCharacter.h new file mode 100644 index 00000000..794c372b --- /dev/null +++ b/src/ZoneCodeGeneratorLib/Parsing/Commands/Matcher/CommandsMatcherCharacter.h @@ -0,0 +1,15 @@ +#pragma once + +#include "Parsing/Commands/Impl/CommandsParserValue.h" +#include "Parsing/Matcher/AbstractMatcher.h" + +class CommandsMatcherCharacter final : public AbstractMatcher +{ + char m_char; + +protected: + MatcherResult CanMatch(ILexer* lexer, unsigned tokenOffset) override; + +public: + explicit CommandsMatcherCharacter(char c); +}; diff --git a/src/ZoneCodeGeneratorLib/Parsing/Commands/Matcher/CommandsMatcherFactory.cpp b/src/ZoneCodeGeneratorLib/Parsing/Commands/Matcher/CommandsMatcherFactory.cpp new file mode 100644 index 00000000..0bd92ed5 --- /dev/null +++ b/src/ZoneCodeGeneratorLib/Parsing/Commands/Matcher/CommandsMatcherFactory.cpp @@ -0,0 +1,40 @@ +#include "CommandsMatcherFactory.h" + +#include "CommandsMatcherCharacter.h" +#include "CommandsMatcherKeyword.h" +#include "CommandsMatcherValueType.h" + +CommandsMatcherFactory::CommandsMatcherFactory(const IMatcherForLabelSupplier* labelSupplier) + : AbstractMatcherFactory(labelSupplier) +{ +} + +MatcherFactoryWrapper CommandsMatcherFactory::Type(CommandsParserValueType type) const +{ + return MatcherFactoryWrapper(std::make_unique(type)); +} + +MatcherFactoryWrapper CommandsMatcherFactory::Keyword(std::string value) const +{ + return MatcherFactoryWrapper(std::make_unique(std::move(value))); +} + +MatcherFactoryWrapper CommandsMatcherFactory::Identifier() const +{ + return MatcherFactoryWrapper(std::make_unique(CommandsParserValueType::IDENTIFIER)); +} + +MatcherFactoryWrapper CommandsMatcherFactory::Integer() const +{ + return MatcherFactoryWrapper(std::make_unique(CommandsParserValueType::INTEGER)); +} + +MatcherFactoryWrapper CommandsMatcherFactory::FloatingPoint() const +{ + return MatcherFactoryWrapper(std::make_unique(CommandsParserValueType::FLOATING_POINT)); +} + +MatcherFactoryWrapper CommandsMatcherFactory::Char(char c) const +{ + return MatcherFactoryWrapper(std::make_unique(c)); +} diff --git a/src/ZoneCodeGeneratorLib/Parsing/Commands/Matcher/CommandsMatcherFactory.h b/src/ZoneCodeGeneratorLib/Parsing/Commands/Matcher/CommandsMatcherFactory.h new file mode 100644 index 00000000..42013f37 --- /dev/null +++ b/src/ZoneCodeGeneratorLib/Parsing/Commands/Matcher/CommandsMatcherFactory.h @@ -0,0 +1,19 @@ +#pragma once + +#include + +#include "Parsing/Commands/Impl/CommandsParserValue.h" +#include "Parsing/Matcher/AbstractMatcherFactory.h" + +class CommandsMatcherFactory final : public AbstractMatcherFactory +{ +public: + explicit CommandsMatcherFactory(const IMatcherForLabelSupplier* labelSupplier); + + _NODISCARD MatcherFactoryWrapper Type(CommandsParserValueType type) const; + _NODISCARD MatcherFactoryWrapper Keyword(std::string value) const; + _NODISCARD MatcherFactoryWrapper Identifier() const; + _NODISCARD MatcherFactoryWrapper Integer() const; + _NODISCARD MatcherFactoryWrapper FloatingPoint() const; + _NODISCARD MatcherFactoryWrapper Char(char c) const; +}; diff --git a/src/ZoneCodeGeneratorLib/Parsing/Commands/Matcher/CommandsMatcherKeyword.cpp b/src/ZoneCodeGeneratorLib/Parsing/Commands/Matcher/CommandsMatcherKeyword.cpp new file mode 100644 index 00000000..52166634 --- /dev/null +++ b/src/ZoneCodeGeneratorLib/Parsing/Commands/Matcher/CommandsMatcherKeyword.cpp @@ -0,0 +1,16 @@ +#include "CommandsMatcherKeyword.h" + +CommandsMatcherKeyword::CommandsMatcherKeyword(std::string value) + : m_value(std::move(value)) +{ + const std::hash hash; + m_hash = hash(m_value); +} + +MatcherResult CommandsMatcherKeyword::CanMatch(ILexer* lexer, const unsigned tokenOffset) +{ + const auto& token = lexer->GetToken(tokenOffset); + return token.m_type == CommandsParserValueType::IDENTIFIER && token.IdentifierHash() == m_hash && token.IdentifierValue() == m_value + ? MatcherResult::Match(1) + : MatcherResult::NoMatch(); +} diff --git a/src/ZoneCodeGeneratorLib/Parsing/Commands/Matcher/CommandsMatcherKeyword.h b/src/ZoneCodeGeneratorLib/Parsing/Commands/Matcher/CommandsMatcherKeyword.h new file mode 100644 index 00000000..290c09e7 --- /dev/null +++ b/src/ZoneCodeGeneratorLib/Parsing/Commands/Matcher/CommandsMatcherKeyword.h @@ -0,0 +1,18 @@ +#pragma once + +#include + +#include "Parsing/Commands/Impl/CommandsParserValue.h" +#include "Parsing/Matcher/AbstractMatcher.h" + +class CommandsMatcherKeyword final : public AbstractMatcher +{ + size_t m_hash; + std::string m_value; + +protected: + MatcherResult CanMatch(ILexer* lexer, unsigned tokenOffset) override; + +public: + explicit CommandsMatcherKeyword(std::string value); +}; diff --git a/src/ZoneCodeGeneratorLib/Parsing/Commands/Matcher/CommandsMatcherValueType.cpp b/src/ZoneCodeGeneratorLib/Parsing/Commands/Matcher/CommandsMatcherValueType.cpp new file mode 100644 index 00000000..6c4e3532 --- /dev/null +++ b/src/ZoneCodeGeneratorLib/Parsing/Commands/Matcher/CommandsMatcherValueType.cpp @@ -0,0 +1,13 @@ +#include "CommandsMatcherValueType.h" + +CommandsMatcherValueType::CommandsMatcherValueType(CommandsParserValueType type) + : m_type(type) +{ +} + +MatcherResult CommandsMatcherValueType::CanMatch(ILexer* lexer, const unsigned tokenOffset) +{ + return lexer->GetToken(tokenOffset).m_type == m_type + ? MatcherResult::Match(1) + : MatcherResult::NoMatch(); +} diff --git a/src/ZoneCodeGeneratorLib/Parsing/Commands/Matcher/CommandsMatcherValueType.h b/src/ZoneCodeGeneratorLib/Parsing/Commands/Matcher/CommandsMatcherValueType.h new file mode 100644 index 00000000..59c806ed --- /dev/null +++ b/src/ZoneCodeGeneratorLib/Parsing/Commands/Matcher/CommandsMatcherValueType.h @@ -0,0 +1,15 @@ +#pragma once + +#include "Parsing/Commands/Impl/CommandsParserValue.h" +#include "Parsing/Matcher/AbstractMatcher.h" + +class CommandsMatcherValueType final : public AbstractMatcher +{ + CommandsParserValueType m_type; + +protected: + MatcherResult CanMatch(ILexer* lexer, unsigned tokenOffset) override; + +public: + explicit CommandsMatcherValueType(CommandsParserValueType type); +}; diff --git a/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceAction.cpp b/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceAction.cpp new file mode 100644 index 00000000..1e3475f4 --- /dev/null +++ b/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceAction.cpp @@ -0,0 +1,41 @@ +#include "SequenceAction.h" + +#include "Parsing/Commands/Matcher/CommandsMatcherFactory.h" +#include "Parsing/Commands/Matcher/CommandsCommonMatchers.h" + +SequenceAction::SequenceAction() +{ + const CommandsMatcherFactory create(this); + + AddLabeledMatchers(CommandsCommonMatchers::Typename(this), CommandsCommonMatchers::LABEL_TYPENAME); + AddLabeledMatchers( + { + create.Char('('), + create.Optional(create.And({ + create.Label(CommandsCommonMatchers::LABEL_TYPENAME).Capture(CAPTURE_ARG_TYPE), + create.OptionalLoop(create.And({ + create.Char(','), + create.Label(CommandsCommonMatchers::LABEL_TYPENAME).Capture(CAPTURE_ARG_TYPE) + })) + })), + create.Char(')') + }, LABEL_ACTION_ARGS); + + AddMatchers({ + create.Keyword("set"), + create.Keyword("action"), + create.Or({ + create.And({ + create.Label(CommandsCommonMatchers::LABEL_TYPENAME).Capture(CAPTURE_TYPE), + create.Identifier().Capture(CAPTURE_ACTION_NAME) + }), + create.Identifier().Capture(CAPTURE_ACTION_NAME) + }), + create.Label(LABEL_ACTION_ARGS), + create.Char(';') + }); +} + +void SequenceAction::ProcessMatch(CommandsParserState* state, SequenceResult& result) const +{ +} diff --git a/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceAction.h b/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceAction.h new file mode 100644 index 00000000..b418ec81 --- /dev/null +++ b/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceAction.h @@ -0,0 +1,18 @@ +#pragma once + +#include "Parsing/Commands/Impl/CommandsParser.h" + +class SequenceAction final : public CommandsParser::sequence_t +{ + static constexpr auto CAPTURE_ACTION_NAME = 1; + static constexpr auto CAPTURE_TYPE = 2; + static constexpr auto CAPTURE_ARG_TYPE = 3; + + static constexpr auto LABEL_ACTION_ARGS = 1; + +protected: + void ProcessMatch(CommandsParserState* state, SequenceResult& result) const override; + +public: + SequenceAction(); +}; diff --git a/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceArrayCount.cpp b/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceArrayCount.cpp new file mode 100644 index 00000000..adb769d8 --- /dev/null +++ b/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceArrayCount.cpp @@ -0,0 +1,23 @@ +#include "SequenceArrayCount.h" + +#include "Parsing/Commands/Matcher/CommandsMatcherFactory.h" +#include "Parsing/Commands/Matcher/CommandsCommonMatchers.h" + +SequenceArrayCount::SequenceArrayCount() +{ + const CommandsMatcherFactory create(this); + + AddLabeledMatchers(CommandsCommonMatchers::Typename(this), CommandsCommonMatchers::LABEL_TYPENAME); + AddLabeledMatchers(CommandsCommonMatchers::Evaluation(this), CommandsCommonMatchers::LABEL_EVALUATION); + AddMatchers({ + create.Keyword("set"), + create.Keyword("arraycount"), + create.Label(CommandsCommonMatchers::LABEL_TYPENAME).Capture(CAPTURE_TYPE), + create.Label(CommandsCommonMatchers::LABEL_EVALUATION).Capture(CAPTURE_EVALUATION), + create.Char(';') + }); +} + +void SequenceArrayCount::ProcessMatch(CommandsParserState* state, SequenceResult& result) const +{ +} diff --git a/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceArrayCount.h b/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceArrayCount.h new file mode 100644 index 00000000..136e8dcf --- /dev/null +++ b/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceArrayCount.h @@ -0,0 +1,15 @@ +#pragma once + +#include "Parsing/Commands/Impl/CommandsParser.h" + +class SequenceArrayCount final : public CommandsParser::sequence_t +{ + static constexpr auto CAPTURE_TYPE = 1; + static constexpr auto CAPTURE_EVALUATION = 2; + +protected: + void ProcessMatch(CommandsParserState* state, SequenceResult& result) const override; + +public: + SequenceArrayCount(); +}; diff --git a/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceArraySize.cpp b/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceArraySize.cpp new file mode 100644 index 00000000..06398eba --- /dev/null +++ b/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceArraySize.cpp @@ -0,0 +1,23 @@ +#include "SequenceArraySize.h" + +#include "Parsing/Commands/Matcher/CommandsMatcherFactory.h" +#include "Parsing/Commands/Matcher/CommandsCommonMatchers.h" + +SequenceArraySize::SequenceArraySize() +{ + const CommandsMatcherFactory create(this); + + AddLabeledMatchers(CommandsCommonMatchers::Typename(this), CommandsCommonMatchers::LABEL_TYPENAME); + AddLabeledMatchers(CommandsCommonMatchers::Evaluation(this), CommandsCommonMatchers::LABEL_EVALUATION); + AddMatchers({ + create.Keyword("set"), + create.Keyword("arraysize"), + create.Label(CommandsCommonMatchers::LABEL_TYPENAME).Capture(CAPTURE_TYPE), + create.Label(CommandsCommonMatchers::LABEL_EVALUATION).Capture(CAPTURE_EVALUATION), + create.Char(';') + }); +} + +void SequenceArraySize::ProcessMatch(CommandsParserState* state, SequenceResult& result) const +{ +} diff --git a/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceArraySize.h b/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceArraySize.h new file mode 100644 index 00000000..795318bb --- /dev/null +++ b/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceArraySize.h @@ -0,0 +1,15 @@ +#pragma once + +#include "Parsing/Commands/Impl/CommandsParser.h" + +class SequenceArraySize final : public CommandsParser::sequence_t +{ + static constexpr auto CAPTURE_TYPE = 1; + static constexpr auto CAPTURE_EVALUATION = 2; + +protected: + void ProcessMatch(CommandsParserState* state, SequenceResult& result) const override; + +public: + SequenceArraySize(); +}; diff --git a/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceAsset.cpp b/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceAsset.cpp new file mode 100644 index 00000000..476b467a --- /dev/null +++ b/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceAsset.cpp @@ -0,0 +1,21 @@ +#include "SequenceAsset.h" + +#include "Parsing/Commands/Matcher/CommandsMatcherFactory.h" +#include "Parsing/Commands/Matcher/CommandsCommonMatchers.h" + +SequenceAsset::SequenceAsset() +{ + const CommandsMatcherFactory create(this); + + AddLabeledMatchers(CommandsCommonMatchers::Typename(this), CommandsCommonMatchers::LABEL_TYPENAME); + AddMatchers({ + create.Keyword("asset"), + create.Label(CommandsCommonMatchers::LABEL_TYPENAME).Capture(CAPTURE_TYPE), + create.Identifier().Capture(CAPTURE_ENUM_ENTRY), + create.Char(';') + }); +} + +void SequenceAsset::ProcessMatch(CommandsParserState* state, SequenceResult& result) const +{ +} diff --git a/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceAsset.h b/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceAsset.h new file mode 100644 index 00000000..b4cae4f3 --- /dev/null +++ b/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceAsset.h @@ -0,0 +1,15 @@ +#pragma once + +#include "Parsing/Commands/Impl/CommandsParser.h" + +class SequenceAsset final : public CommandsParser::sequence_t +{ + static constexpr auto CAPTURE_TYPE = 1; + static constexpr auto CAPTURE_ENUM_ENTRY = 2; + +protected: + void ProcessMatch(CommandsParserState* state, SequenceResult& result) const override; + +public: + SequenceAsset(); +}; diff --git a/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceBlock.cpp b/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceBlock.cpp new file mode 100644 index 00000000..da163bf0 --- /dev/null +++ b/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceBlock.cpp @@ -0,0 +1,21 @@ +#include "SequenceBlock.h" + +#include "Parsing/Commands/Matcher/CommandsMatcherFactory.h" +#include "Parsing/Commands/Matcher/CommandsCommonMatchers.h" + +SequenceBlock::SequenceBlock() +{ + const CommandsMatcherFactory create(this); + + AddMatchers({ + create.Keyword("block"), + create.Identifier().Capture(CAPTURE_BLOCK_ENUM_ENTRY), + create.Identifier().Capture(CAPTURE_BLOCK_TYPE), + create.Optional(create.Keyword("default").Tag(TAG_DEFAULT)), + create.Char(';') + }); +} + +void SequenceBlock::ProcessMatch(CommandsParserState* state, SequenceResult& result) const +{ +} diff --git a/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceBlock.h b/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceBlock.h new file mode 100644 index 00000000..5c19eda4 --- /dev/null +++ b/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceBlock.h @@ -0,0 +1,17 @@ +#pragma once + +#include "Parsing/Commands/Impl/CommandsParser.h" + +class SequenceBlock final : public CommandsParser::sequence_t +{ + static constexpr auto TAG_DEFAULT = 1; + + static constexpr auto CAPTURE_BLOCK_ENUM_ENTRY = 1; + static constexpr auto CAPTURE_BLOCK_TYPE = 2; + +protected: + void ProcessMatch(CommandsParserState* state, SequenceResult& result) const override; + +public: + SequenceBlock(); +}; diff --git a/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceCondition.cpp b/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceCondition.cpp new file mode 100644 index 00000000..c970f679 --- /dev/null +++ b/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceCondition.cpp @@ -0,0 +1,27 @@ +#include "SequenceCondition.h" + +#include "Parsing/Commands/Matcher/CommandsMatcherFactory.h" +#include "Parsing/Commands/Matcher/CommandsCommonMatchers.h" + +SequenceCondition::SequenceCondition() +{ + const CommandsMatcherFactory create(this); + + AddLabeledMatchers(CommandsCommonMatchers::Typename(this), CommandsCommonMatchers::LABEL_TYPENAME); + AddLabeledMatchers(CommandsCommonMatchers::Evaluation(this), CommandsCommonMatchers::LABEL_EVALUATION); + AddMatchers({ + create.Keyword("set"), + create.Keyword("condition"), + create.Label(CommandsCommonMatchers::LABEL_TYPENAME).Capture(CAPTURE_TYPE), + create.Or({ + create.Keyword("always").Tag(TAG_ALWAYS), + create.Keyword("never").Tag(TAG_NEVER), + create.Label(CommandsCommonMatchers::LABEL_EVALUATION).Tag(TAG_EVALUATION).Capture(CAPTURE_EVALUATION) + }), + create.Char(';') + }); +} + +void SequenceCondition::ProcessMatch(CommandsParserState* state, SequenceResult& result) const +{ +} diff --git a/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceCondition.h b/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceCondition.h new file mode 100644 index 00000000..b10f4600 --- /dev/null +++ b/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceCondition.h @@ -0,0 +1,19 @@ +#pragma once + +#include "Parsing/Commands/Impl/CommandsParser.h" + +class SequenceCondition final : public CommandsParser::sequence_t +{ + static constexpr auto TAG_ALWAYS = 1; + static constexpr auto TAG_NEVER = 2; + static constexpr auto TAG_EVALUATION = 3; + + static constexpr auto CAPTURE_TYPE = 1; + static constexpr auto CAPTURE_EVALUATION = 2; + +protected: + void ProcessMatch(CommandsParserState* state, SequenceResult& result) const override; + +public: + SequenceCondition(); +}; diff --git a/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceCount.cpp b/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceCount.cpp new file mode 100644 index 00000000..555bb048 --- /dev/null +++ b/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceCount.cpp @@ -0,0 +1,26 @@ +#include "SequenceCount.h" + +#include "Parsing/Commands/Matcher/CommandsMatcherFactory.h" +#include "Parsing/Commands/Matcher/CommandsCommonMatchers.h" + +SequenceCount::SequenceCount() +{ + const CommandsMatcherFactory create(this); + + AddLabeledMatchers(CommandsCommonMatchers::Typename(this), CommandsCommonMatchers::LABEL_TYPENAME); + AddLabeledMatchers(CommandsCommonMatchers::Evaluation(this), CommandsCommonMatchers::LABEL_EVALUATION); + AddLabeledMatchers(CommandsCommonMatchers::ArrayDef(this), CommandsCommonMatchers::LABEL_ARRAY_DEF); + AddMatchers({ + create.Keyword("set"), + create.Keyword("count"), + create.OptionalLoop(create.Char('*').Tag(TAG_POINTER_RESOLVE)), + create.Label(CommandsCommonMatchers::LABEL_TYPENAME).Capture(CAPTURE_TYPE), + create.OptionalLoop(create.Label(CommandsCommonMatchers::LABEL_ARRAY_DEF).Capture(CAPTURE_ARRAY_INDEX)), + create.Label(CommandsCommonMatchers::LABEL_EVALUATION).Capture(CAPTURE_EVALUATION), + create.Char(';') + }); +} + +void SequenceCount::ProcessMatch(CommandsParserState* state, SequenceResult& result) const +{ +} diff --git a/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceCount.h b/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceCount.h new file mode 100644 index 00000000..3cc16f01 --- /dev/null +++ b/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceCount.h @@ -0,0 +1,18 @@ +#pragma once + +#include "Parsing/Commands/Impl/CommandsParser.h" + +class SequenceCount final : public CommandsParser::sequence_t +{ + static constexpr auto TAG_POINTER_RESOLVE = 1; + + static constexpr auto CAPTURE_TYPE = 1; + static constexpr auto CAPTURE_ARRAY_INDEX = 2; + static constexpr auto CAPTURE_EVALUATION = 3; + +protected: + void ProcessMatch(CommandsParserState* state, SequenceResult& result) const override; + +public: + SequenceCount(); +}; diff --git a/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceGame.cpp b/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceGame.cpp new file mode 100644 index 00000000..a29f43c1 --- /dev/null +++ b/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceGame.cpp @@ -0,0 +1,19 @@ +#include "SequenceGame.h" + +#include "Parsing/Commands/Matcher/CommandsMatcherFactory.h" +#include "Parsing/Commands/Matcher/CommandsCommonMatchers.h" + +SequenceGame::SequenceGame() +{ + const CommandsMatcherFactory create(this); + + AddMatchers({ + create.Keyword("game"), + create.Identifier().Capture(CAPTURE_GAME), + create.Char(';') + }); +} + +void SequenceGame::ProcessMatch(CommandsParserState* state, SequenceResult& result) const +{ +} diff --git a/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceGame.h b/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceGame.h new file mode 100644 index 00000000..2de63c08 --- /dev/null +++ b/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceGame.h @@ -0,0 +1,14 @@ +#pragma once + +#include "Parsing/Commands/Impl/CommandsParser.h" + +class SequenceGame final : public CommandsParser::sequence_t +{ + static constexpr auto CAPTURE_GAME = 1; + +protected: + void ProcessMatch(CommandsParserState* state, SequenceResult& result) const override; + +public: + SequenceGame(); +}; diff --git a/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceName.cpp b/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceName.cpp new file mode 100644 index 00000000..f250fdc0 --- /dev/null +++ b/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceName.cpp @@ -0,0 +1,21 @@ +#include "SequenceName.h" + +#include "Parsing/Commands/Matcher/CommandsMatcherFactory.h" +#include "Parsing/Commands/Matcher/CommandsCommonMatchers.h" + +SequenceName::SequenceName() +{ + const CommandsMatcherFactory create(this); + + AddLabeledMatchers(CommandsCommonMatchers::Typename(this), CommandsCommonMatchers::LABEL_TYPENAME); + AddMatchers({ + create.Keyword("set"), + create.Keyword("name"), + create.Label(CommandsCommonMatchers::LABEL_TYPENAME).Capture(CAPTURE_TYPE), + create.Char(';') + }); +} + +void SequenceName::ProcessMatch(CommandsParserState* state, SequenceResult& result) const +{ +} diff --git a/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceName.h b/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceName.h new file mode 100644 index 00000000..56b5da84 --- /dev/null +++ b/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceName.h @@ -0,0 +1,14 @@ +#pragma once + +#include "Parsing/Commands/Impl/CommandsParser.h" + +class SequenceName final : public CommandsParser::sequence_t +{ + static constexpr auto CAPTURE_TYPE = 1; + +protected: + void ProcessMatch(CommandsParserState* state, SequenceResult& result) const override; + +public: + SequenceName(); +}; diff --git a/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceReorder.cpp b/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceReorder.cpp new file mode 100644 index 00000000..7a880a5b --- /dev/null +++ b/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceReorder.cpp @@ -0,0 +1,27 @@ +#include "SequenceReorder.h" + +#include "Parsing/Commands/Matcher/CommandsMatcherFactory.h" +#include "Parsing/Commands/Matcher/CommandsCommonMatchers.h" + +SequenceReorder::SequenceReorder() +{ + const CommandsMatcherFactory create(this); + + AddLabeledMatchers(CommandsCommonMatchers::Typename(this), CommandsCommonMatchers::LABEL_TYPENAME); + AddMatchers({ + create.Keyword("reorder"), + create.Optional(create.Label(CommandsCommonMatchers::LABEL_TYPENAME).Capture(CAPTURE_TYPE)), + create.Char(':'), + create.Optional(create.And({ + create.Char('.'), + create.Char('.'), + create.Char('.') + }).Tag(TAG_FIND_FIRST)), + create.Loop(create.Identifier().Capture(CAPTURE_ENTRY)), + create.Char(';') + }); +} + +void SequenceReorder::ProcessMatch(CommandsParserState* state, SequenceResult& result) const +{ +} diff --git a/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceReorder.h b/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceReorder.h new file mode 100644 index 00000000..69025476 --- /dev/null +++ b/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceReorder.h @@ -0,0 +1,17 @@ +#pragma once + +#include "Parsing/Commands/Impl/CommandsParser.h" + +class SequenceReorder final : public CommandsParser::sequence_t +{ + static constexpr auto TAG_FIND_FIRST = 1; + + static constexpr auto CAPTURE_TYPE = 1; + static constexpr auto CAPTURE_ENTRY = 2; + +protected: + void ProcessMatch(CommandsParserState* state, SequenceResult& result) const override; + +public: + SequenceReorder(); +}; diff --git a/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceReusable.cpp b/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceReusable.cpp new file mode 100644 index 00000000..7531bf5f --- /dev/null +++ b/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceReusable.cpp @@ -0,0 +1,21 @@ +#include "SequenceReusable.h" + +#include "Parsing/Commands/Matcher/CommandsMatcherFactory.h" +#include "Parsing/Commands/Matcher/CommandsCommonMatchers.h" + +SequenceReusable::SequenceReusable() +{ + const CommandsMatcherFactory create(this); + + AddLabeledMatchers(CommandsCommonMatchers::Typename(this), CommandsCommonMatchers::LABEL_TYPENAME); + AddMatchers({ + create.Keyword("set"), + create.Keyword("reusable"), + create.Label(CommandsCommonMatchers::LABEL_TYPENAME).Capture(CAPTURE_TYPE), + create.Char(';') + }); +} + +void SequenceReusable::ProcessMatch(CommandsParserState* state, SequenceResult& result) const +{ +} diff --git a/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceReusable.h b/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceReusable.h new file mode 100644 index 00000000..90aaa995 --- /dev/null +++ b/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceReusable.h @@ -0,0 +1,14 @@ +#pragma once + +#include "Parsing/Commands/Impl/CommandsParser.h" + +class SequenceReusable final : public CommandsParser::sequence_t +{ + static constexpr auto CAPTURE_TYPE = 1; + +protected: + void ProcessMatch(CommandsParserState* state, SequenceResult& result) const override; + +public: + SequenceReusable(); +}; diff --git a/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceScriptString.cpp b/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceScriptString.cpp new file mode 100644 index 00000000..a1a57c60 --- /dev/null +++ b/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceScriptString.cpp @@ -0,0 +1,21 @@ +#include "SequenceScriptString.h" + +#include "Parsing/Commands/Matcher/CommandsMatcherFactory.h" +#include "Parsing/Commands/Matcher/CommandsCommonMatchers.h" + +SequenceScriptString::SequenceScriptString() +{ + const CommandsMatcherFactory create(this); + + AddLabeledMatchers(CommandsCommonMatchers::Typename(this), CommandsCommonMatchers::LABEL_TYPENAME); + AddMatchers({ + create.Keyword("set"), + create.Keyword("scriptstring"), + create.Label(CommandsCommonMatchers::LABEL_TYPENAME).Capture(CAPTURE_TYPE), + create.Char(';') + }); +} + +void SequenceScriptString::ProcessMatch(CommandsParserState* state, SequenceResult& result) const +{ +} diff --git a/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceScriptString.h b/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceScriptString.h new file mode 100644 index 00000000..d6b90306 --- /dev/null +++ b/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceScriptString.h @@ -0,0 +1,14 @@ +#pragma once + +#include "Parsing/Commands/Impl/CommandsParser.h" + +class SequenceScriptString final : public CommandsParser::sequence_t +{ + static constexpr auto CAPTURE_TYPE = 1; + +protected: + void ProcessMatch(CommandsParserState* state, SequenceResult& result) const override; + +public: + SequenceScriptString(); +}; diff --git a/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceSetBlock.cpp b/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceSetBlock.cpp new file mode 100644 index 00000000..1830df07 --- /dev/null +++ b/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceSetBlock.cpp @@ -0,0 +1,27 @@ +#include "SequenceSetBlock.h" + +#include "Parsing/Commands/Matcher/CommandsMatcherFactory.h" +#include "Parsing/Commands/Matcher/CommandsCommonMatchers.h" + +SequenceSetBlock::SequenceSetBlock() +{ + const CommandsMatcherFactory create(this); + + AddLabeledMatchers(CommandsCommonMatchers::Typename(this), CommandsCommonMatchers::LABEL_TYPENAME); + AddMatchers({ + create.Keyword("set"), + create.Keyword("block"), + create.Or({ + create.And({ + create.Label(CommandsCommonMatchers::LABEL_TYPENAME).Capture(CAPTURE_TYPE), + create.Identifier().Capture(CAPTURE_BLOCK_ENUM_ENTRY) + }), + create.Identifier().Capture(CAPTURE_BLOCK_ENUM_ENTRY) + }), + create.Char(';') + }); +} + +void SequenceSetBlock::ProcessMatch(CommandsParserState* state, SequenceResult& result) const +{ +} diff --git a/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceSetBlock.h b/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceSetBlock.h new file mode 100644 index 00000000..684337fe --- /dev/null +++ b/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceSetBlock.h @@ -0,0 +1,15 @@ +#pragma once + +#include "Parsing/Commands/Impl/CommandsParser.h" + +class SequenceSetBlock final : public CommandsParser::sequence_t +{ + static constexpr auto CAPTURE_TYPE = 1; + static constexpr auto CAPTURE_BLOCK_ENUM_ENTRY = 2; + +protected: + void ProcessMatch(CommandsParserState* state, SequenceResult& result) const override; + +public: + SequenceSetBlock(); +}; diff --git a/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceString.cpp b/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceString.cpp new file mode 100644 index 00000000..e1e3bd70 --- /dev/null +++ b/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceString.cpp @@ -0,0 +1,21 @@ +#include "SequenceString.h" + +#include "Parsing/Commands/Matcher/CommandsMatcherFactory.h" +#include "Parsing/Commands/Matcher/CommandsCommonMatchers.h" + +SequenceString::SequenceString() +{ + const CommandsMatcherFactory create(this); + + AddLabeledMatchers(CommandsCommonMatchers::Typename(this), CommandsCommonMatchers::LABEL_TYPENAME); + AddMatchers({ + create.Keyword("set"), + create.Keyword("string"), + create.Label(CommandsCommonMatchers::LABEL_TYPENAME).Capture(CAPTURE_TYPE), + create.Char(';') + }); +} + +void SequenceString::ProcessMatch(CommandsParserState* state, SequenceResult& result) const +{ +} diff --git a/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceString.h b/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceString.h new file mode 100644 index 00000000..b902c3c6 --- /dev/null +++ b/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceString.h @@ -0,0 +1,14 @@ +#pragma once + +#include "Parsing/Commands/Impl/CommandsParser.h" + +class SequenceString final : public CommandsParser::sequence_t +{ + static constexpr auto CAPTURE_TYPE = 1; + +protected: + void ProcessMatch(CommandsParserState* state, SequenceResult& result) const override; + +public: + SequenceString(); +}; diff --git a/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceUse.cpp b/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceUse.cpp new file mode 100644 index 00000000..0defd8aa --- /dev/null +++ b/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceUse.cpp @@ -0,0 +1,20 @@ +#include "SequenceUse.h" + +#include "Parsing/Commands/Matcher/CommandsMatcherFactory.h" +#include "Parsing/Commands/Matcher/CommandsCommonMatchers.h" + +SequenceUse::SequenceUse() +{ + const CommandsMatcherFactory create(this); + + AddLabeledMatchers(CommandsCommonMatchers::Typename(this), CommandsCommonMatchers::LABEL_TYPENAME); + AddMatchers({ + create.Keyword("use"), + create.Label(CommandsCommonMatchers::LABEL_TYPENAME).Capture(CAPTURE_TYPE), + create.Char(';') + }); +} + +void SequenceUse::ProcessMatch(CommandsParserState* state, SequenceResult& result) const +{ +} diff --git a/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceUse.h b/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceUse.h new file mode 100644 index 00000000..82aaae15 --- /dev/null +++ b/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceUse.h @@ -0,0 +1,14 @@ +#pragma once + +#include "Parsing/Commands/Impl/CommandsParser.h" + +class SequenceUse final : public CommandsParser::sequence_t +{ + static constexpr auto CAPTURE_TYPE = 1; + +protected: + void ProcessMatch(CommandsParserState* state, SequenceResult& result) const override; + +public: + SequenceUse(); +}; diff --git a/src/ZoneCodeGeneratorLib/Parsing/Header/HeaderFileReader.cpp b/src/ZoneCodeGeneratorLib/Parsing/Header/HeaderFileReader.cpp index 07f6150c..17e19afe 100644 --- a/src/ZoneCodeGeneratorLib/Parsing/Header/HeaderFileReader.cpp +++ b/src/ZoneCodeGeneratorLib/Parsing/Header/HeaderFileReader.cpp @@ -6,7 +6,6 @@ #include "Impl/HeaderLexer.h" #include "Impl/HeaderParser.h" -#include "Parsing/ParsingException.h" #include "Parsing/Impl/CommentRemovingStreamProxy.h" #include "Parsing/Impl/DefinesStreamProxy.h" #include "Parsing/Impl/IncludingStreamProxy.h"