Add sequences for commands

This commit is contained in:
Jan 2021-02-18 14:41:27 +01:00
parent cef9b08efb
commit bb877f87bb
49 changed files with 1201 additions and 25 deletions

View File

@ -1,9 +1,10 @@
#include "CommandsFileReader.h"
#include <chrono>
#include <iostream>
#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<CommandsLexer>(m_stream);
const auto lexer = std::make_unique<CommandsLexer>(m_stream);
const auto parser = std::make_unique<CommandsParser>(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<std::chrono::milliseconds>(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;
}

View File

@ -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<char>(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<char>(c));
}
case '=':
{
if (NextCharInLineIs('='))
{
const auto pos = GetPreviousCharacterPos();
NextChar();
return CommandsParserValue::Equals(pos);
}
return CommandsParserValue::Character(GetPreviousCharacterPos(), static_cast<char>(c));
}
case '&':
{
if (NextCharInLineIs('&'))
{
const auto pos = GetPreviousCharacterPos();
NextChar();
return CommandsParserValue::LogicalAnd(pos);
}
return CommandsParserValue::Character(GetPreviousCharacterPos(), static_cast<char>(c));
}
case '|':
{
if (NextCharInLineIs('|'))
{
const auto pos = GetPreviousCharacterPos();
NextChar();
return CommandsParserValue::LogicalOr(pos);
}
return CommandsParserValue::Character(GetPreviousCharacterPos(), static_cast<char>(c));
}
case '!':
{
if (NextCharInLineIs('='))
{
const auto pos = GetPreviousCharacterPos();
NextChar();
return CommandsParserValue::NotEqual(pos);
}
return CommandsParserValue::Character(GetPreviousCharacterPos(), static_cast<char>(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<char>(c));
}
}
c = NextChar();
}
return CommandsParserValue::EndOfFile(TokenPos());
}

View File

@ -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<CommandsParserState>()),
m_repository(targetRepository)
{
}
const std::vector<CommandsParser::sequence_t*>& CommandsParser::GetTestsForState()
{
static std::vector<sequence_t*> 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;
}

View File

@ -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<CommandsParserValue, CommandsParserState>
{
IDataRepository* m_repository;
protected:
const std::vector<sequence_t*>& GetTestsForState() override;
public:
CommandsParser(CommandsLexer* lexer, IDataRepository* targetRepository);
};

View File

@ -0,0 +1,6 @@
#pragma once
class CommandsParserState
{
public:
};

View File

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

View File

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

View File

@ -0,0 +1,200 @@
#include "CommandsCommonMatchers.h"
#include <sstream>
#include "CommandsMatcherFactory.h"
std::unique_ptr<CommandsCommonMatchers::matcher_t> 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<int>(CommandsParserValueType::BUILT_IN_LAST) - static_cast<int>(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<int>(token.get().m_type) - static_cast<int>(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::matcher_t> 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<int>::max() - 1;
static constexpr int TAG_ADD = std::numeric_limits<int>::max() - 2;
static constexpr int TAG_MINUS = std::numeric_limits<int>::max() - 3;
static constexpr int TAG_MULTIPLY = std::numeric_limits<int>::max() - 4;
static constexpr int TAG_DIVIDE = std::numeric_limits<int>::max() - 5;
static constexpr int TAG_REMAINDER = std::numeric_limits<int>::max() - 6;
static constexpr int TAG_BITWISE_AND = std::numeric_limits<int>::max() - 7;
static constexpr int TAG_BITWISE_XOR = std::numeric_limits<int>::max() - 8;
static constexpr int TAG_BITWISE_OR = std::numeric_limits<int>::max() - 9;
static constexpr int TAG_SHIFT_LEFT = std::numeric_limits<int>::max() - 10;
static constexpr int TAG_SHIFT_RIGHT = std::numeric_limits<int>::max() - 11;
static constexpr int TAG_GREATER_THAN = std::numeric_limits<int>::max() - 12;
static constexpr int TAG_GREATER_EQUAL = std::numeric_limits<int>::max() - 13;
static constexpr int TAG_LESS_THAN = std::numeric_limits<int>::max() - 14;
static constexpr int TAG_LESS_EQUAL = std::numeric_limits<int>::max() - 15;
static constexpr int TAG_EQUALS = std::numeric_limits<int>::max() - 16;
static constexpr int TAG_NOT_EQUAL = std::numeric_limits<int>::max() - 17;
static constexpr int TAG_LOGICAL_AND = std::numeric_limits<int>::max() - 18;
static constexpr int TAG_LOGICAL_OR = std::numeric_limits<int>::max() - 19;
static constexpr int TAG_OPERAND = std::numeric_limits<int>::max() - 20;
static constexpr int TAG_OPERAND_TYPENAME = std::numeric_limits<int>::max() - 21;
static constexpr int TAG_OPERAND_ARRAY = std::numeric_limits<int>::max() - 22;
static constexpr int TAG_OPERAND_ARRAY_END = std::numeric_limits<int>::max() - 23;
static constexpr int TAG_OPERAND_INTEGER = std::numeric_limits<int>::max() - 24;
static constexpr int TAG_OPERAND_FLOATING_POINT = std::numeric_limits<int>::max() - 25;
static constexpr int TAG_EVALUATION_NOT = std::numeric_limits<int>::max() - 26;
static constexpr int TAG_EVALUATION_PARENTHESIS = std::numeric_limits<int>::max() - 27;
static constexpr int TAG_EVALUATION_PARENTHESIS_END = std::numeric_limits<int>::max() - 28;
static constexpr int TAG_EVALUATION = std::numeric_limits<int>::max() - 29;
static constexpr int TAG_EVALUATION_OPERATION = std::numeric_limits<int>::max() - 30;
static constexpr int CAPTURE_OPERAND_TYPENAME = std::numeric_limits<int>::max() - 1;
static constexpr int CAPTURE_OPERAND_ARRAY = std::numeric_limits<int>::max() - 1;
static constexpr int CAPTURE_OPERAND_INTEGER = std::numeric_limits<int>::max() - 2;
static constexpr int CAPTURE_OPERAND_FLOATING_POINT = std::numeric_limits<int>::max() - 3;
std::unique_ptr<CommandsCommonMatchers::matcher_t> 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::matcher_t> 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<CommandsParserValue>(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::matcher_t> 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::matcher_t> 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<IEvaluation> CommandsCommonMatchers::ParseEvaluation(SequenceResult<CommandsParserValue>& result)
{
return nullptr;
}

View File

@ -0,0 +1,33 @@
#pragma once
#include <limits>
#include <memory>
#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<CommandsParserValue> matcher_t;
typedef IMatcherForLabelSupplier<CommandsParserValue> supplier_t;
static constexpr int LABEL_TYPENAME = std::numeric_limits<int>::max() - 1;
static constexpr int LABEL_ARRAY_DEF = std::numeric_limits<int>::max() - 2;
static constexpr int LABEL_EVALUATION = std::numeric_limits<int>::max() - 3;
static std::unique_ptr<matcher_t> Typename(const supplier_t* labelSupplier);
static std::unique_ptr<matcher_t> ArrayDef(const supplier_t* labelSupplier);
private:
static std::unique_ptr<matcher_t> OperandArray(const supplier_t* labelSupplier);
static std::unique_ptr<matcher_t> Operand(const supplier_t* labelSupplier);
static std::unique_ptr<matcher_t> OperationType(const supplier_t* labelSupplier);
public:
static std::unique_ptr<matcher_t> Evaluation(const supplier_t* labelSupplier);
static std::unique_ptr<IEvaluation> ParseEvaluation(SequenceResult<CommandsParserValue>& result);
};

View File

@ -0,0 +1,14 @@
#include "CommandsMatcherCharacter.h"
CommandsMatcherCharacter::CommandsMatcherCharacter(const char c)
: m_char(c)
{
}
MatcherResult<CommandsParserValue> CommandsMatcherCharacter::CanMatch(ILexer<CommandsParserValue>* lexer, const unsigned tokenOffset)
{
const auto& token = lexer->GetToken(tokenOffset);
return token.m_type == CommandsParserValueType::CHARACTER && token.CharacterValue() == m_char
? MatcherResult<CommandsParserValue>::Match(1)
: MatcherResult<CommandsParserValue>::NoMatch();
}

View File

@ -0,0 +1,15 @@
#pragma once
#include "Parsing/Commands/Impl/CommandsParserValue.h"
#include "Parsing/Matcher/AbstractMatcher.h"
class CommandsMatcherCharacter final : public AbstractMatcher<CommandsParserValue>
{
char m_char;
protected:
MatcherResult<CommandsParserValue> CanMatch(ILexer<CommandsParserValue>* lexer, unsigned tokenOffset) override;
public:
explicit CommandsMatcherCharacter(char c);
};

View File

@ -0,0 +1,40 @@
#include "CommandsMatcherFactory.h"
#include "CommandsMatcherCharacter.h"
#include "CommandsMatcherKeyword.h"
#include "CommandsMatcherValueType.h"
CommandsMatcherFactory::CommandsMatcherFactory(const IMatcherForLabelSupplier<CommandsParserValue>* labelSupplier)
: AbstractMatcherFactory(labelSupplier)
{
}
MatcherFactoryWrapper<CommandsParserValue> CommandsMatcherFactory::Type(CommandsParserValueType type) const
{
return MatcherFactoryWrapper<CommandsParserValue>(std::make_unique<CommandsMatcherValueType>(type));
}
MatcherFactoryWrapper<CommandsParserValue> CommandsMatcherFactory::Keyword(std::string value) const
{
return MatcherFactoryWrapper<CommandsParserValue>(std::make_unique<CommandsMatcherKeyword>(std::move(value)));
}
MatcherFactoryWrapper<CommandsParserValue> CommandsMatcherFactory::Identifier() const
{
return MatcherFactoryWrapper<CommandsParserValue>(std::make_unique<CommandsMatcherValueType>(CommandsParserValueType::IDENTIFIER));
}
MatcherFactoryWrapper<CommandsParserValue> CommandsMatcherFactory::Integer() const
{
return MatcherFactoryWrapper<CommandsParserValue>(std::make_unique<CommandsMatcherValueType>(CommandsParserValueType::INTEGER));
}
MatcherFactoryWrapper<CommandsParserValue> CommandsMatcherFactory::FloatingPoint() const
{
return MatcherFactoryWrapper<CommandsParserValue>(std::make_unique<CommandsMatcherValueType>(CommandsParserValueType::FLOATING_POINT));
}
MatcherFactoryWrapper<CommandsParserValue> CommandsMatcherFactory::Char(char c) const
{
return MatcherFactoryWrapper<CommandsParserValue>(std::make_unique<CommandsMatcherCharacter>(c));
}

View File

@ -0,0 +1,19 @@
#pragma once
#include <string>
#include "Parsing/Commands/Impl/CommandsParserValue.h"
#include "Parsing/Matcher/AbstractMatcherFactory.h"
class CommandsMatcherFactory final : public AbstractMatcherFactory<CommandsParserValue>
{
public:
explicit CommandsMatcherFactory(const IMatcherForLabelSupplier<CommandsParserValue>* labelSupplier);
_NODISCARD MatcherFactoryWrapper<CommandsParserValue> Type(CommandsParserValueType type) const;
_NODISCARD MatcherFactoryWrapper<CommandsParserValue> Keyword(std::string value) const;
_NODISCARD MatcherFactoryWrapper<CommandsParserValue> Identifier() const;
_NODISCARD MatcherFactoryWrapper<CommandsParserValue> Integer() const;
_NODISCARD MatcherFactoryWrapper<CommandsParserValue> FloatingPoint() const;
_NODISCARD MatcherFactoryWrapper<CommandsParserValue> Char(char c) const;
};

View File

@ -0,0 +1,16 @@
#include "CommandsMatcherKeyword.h"
CommandsMatcherKeyword::CommandsMatcherKeyword(std::string value)
: m_value(std::move(value))
{
const std::hash<std::string> hash;
m_hash = hash(m_value);
}
MatcherResult<CommandsParserValue> CommandsMatcherKeyword::CanMatch(ILexer<CommandsParserValue>* 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<CommandsParserValue>::Match(1)
: MatcherResult<CommandsParserValue>::NoMatch();
}

View File

@ -0,0 +1,18 @@
#pragma once
#include <string>
#include "Parsing/Commands/Impl/CommandsParserValue.h"
#include "Parsing/Matcher/AbstractMatcher.h"
class CommandsMatcherKeyword final : public AbstractMatcher<CommandsParserValue>
{
size_t m_hash;
std::string m_value;
protected:
MatcherResult<CommandsParserValue> CanMatch(ILexer<CommandsParserValue>* lexer, unsigned tokenOffset) override;
public:
explicit CommandsMatcherKeyword(std::string value);
};

View File

@ -0,0 +1,13 @@
#include "CommandsMatcherValueType.h"
CommandsMatcherValueType::CommandsMatcherValueType(CommandsParserValueType type)
: m_type(type)
{
}
MatcherResult<CommandsParserValue> CommandsMatcherValueType::CanMatch(ILexer<CommandsParserValue>* lexer, const unsigned tokenOffset)
{
return lexer->GetToken(tokenOffset).m_type == m_type
? MatcherResult<CommandsParserValue>::Match(1)
: MatcherResult<CommandsParserValue>::NoMatch();
}

View File

@ -0,0 +1,15 @@
#pragma once
#include "Parsing/Commands/Impl/CommandsParserValue.h"
#include "Parsing/Matcher/AbstractMatcher.h"
class CommandsMatcherValueType final : public AbstractMatcher<CommandsParserValue>
{
CommandsParserValueType m_type;
protected:
MatcherResult<CommandsParserValue> CanMatch(ILexer<CommandsParserValue>* lexer, unsigned tokenOffset) override;
public:
explicit CommandsMatcherValueType(CommandsParserValueType type);
};

View File

@ -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<CommandsParserValue>& result) const
{
}

View File

@ -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<CommandsParserValue>& result) const override;
public:
SequenceAction();
};

View File

@ -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<CommandsParserValue>& result) const
{
}

View File

@ -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<CommandsParserValue>& result) const override;
public:
SequenceArrayCount();
};

View File

@ -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<CommandsParserValue>& result) const
{
}

View File

@ -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<CommandsParserValue>& result) const override;
public:
SequenceArraySize();
};

View File

@ -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<CommandsParserValue>& result) const
{
}

View File

@ -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<CommandsParserValue>& result) const override;
public:
SequenceAsset();
};

View File

@ -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<CommandsParserValue>& result) const
{
}

View File

@ -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<CommandsParserValue>& result) const override;
public:
SequenceBlock();
};

View File

@ -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<CommandsParserValue>& result) const
{
}

View File

@ -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<CommandsParserValue>& result) const override;
public:
SequenceCondition();
};

View File

@ -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<CommandsParserValue>& result) const
{
}

View File

@ -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<CommandsParserValue>& result) const override;
public:
SequenceCount();
};

View File

@ -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<CommandsParserValue>& result) const
{
}

View File

@ -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<CommandsParserValue>& result) const override;
public:
SequenceGame();
};

View File

@ -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<CommandsParserValue>& result) const
{
}

View File

@ -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<CommandsParserValue>& result) const override;
public:
SequenceName();
};

View File

@ -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<CommandsParserValue>& result) const
{
}

View File

@ -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<CommandsParserValue>& result) const override;
public:
SequenceReorder();
};

View File

@ -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<CommandsParserValue>& result) const
{
}

View File

@ -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<CommandsParserValue>& result) const override;
public:
SequenceReusable();
};

View File

@ -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<CommandsParserValue>& result) const
{
}

View File

@ -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<CommandsParserValue>& result) const override;
public:
SequenceScriptString();
};

View File

@ -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<CommandsParserValue>& result) const
{
}

View File

@ -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<CommandsParserValue>& result) const override;
public:
SequenceSetBlock();
};

View File

@ -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<CommandsParserValue>& result) const
{
}

View File

@ -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<CommandsParserValue>& result) const override;
public:
SequenceString();
};

View File

@ -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<CommandsParserValue>& result) const
{
}

View File

@ -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<CommandsParserValue>& result) const override;
public:
SequenceUse();
};

View File

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