2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2025-07-01 08:41:52 +00:00

Implement sequence matcher and parser magic

This commit is contained in:
Jan
2021-02-13 00:12:26 +01:00
parent fe1f391bcc
commit 0f70f9586c
48 changed files with 1061 additions and 141 deletions

View File

@ -16,7 +16,8 @@ CommandsParserValue CommandsParserValue::EndOfFile(const TokenPos pos)
CommandsParserValue CommandsParserValue::Character(const TokenPos pos, const char c)
{
CommandsParserValue pv(pos, c);
CommandsParserValue pv(pos, CommandsParserValueType::CHARACTER);
pv.m_value.char_value = c;
return pv;
}
@ -93,6 +94,7 @@ CommandsParserValue CommandsParserValue::Identifier(const TokenPos pos, std::str
{
CommandsParserValue pv(pos, CommandsParserValueType::IDENTIFIER);
pv.m_value.string_value = identifier;
pv.m_hash = std::hash<std::string>()(*identifier);
return pv;
}
@ -103,10 +105,11 @@ CommandsParserValue CommandsParserValue::TypeName(const TokenPos pos, std::strin
return pv;
}
CommandsParserValue::CommandsParserValue(const TokenPos pos, const int type)
CommandsParserValue::CommandsParserValue(const TokenPos pos, const CommandsParserValueType type)
: m_pos(pos),
m_type(type),
m_value()
m_hash(0),
m_value{}
{
}
@ -129,6 +132,7 @@ CommandsParserValue::~CommandsParserValue()
CommandsParserValue::CommandsParserValue(CommandsParserValue&& other) noexcept
: m_type(other.m_type),
m_hash(other.m_hash),
m_value(other.m_value)
{
other.m_value = ValueType();
@ -138,11 +142,28 @@ CommandsParserValue& CommandsParserValue::operator=(CommandsParserValue&& other)
{
m_type = other.m_type;
m_value = other.m_value;
m_hash = other.m_hash;
other.m_value = ValueType();
return *this;
}
bool CommandsParserValue::IsEof() const
{
return m_type == CommandsParserValueType::END_OF_FILE;
}
const TokenPos& CommandsParserValue::GetPos() const
{
return m_pos;
}
char CommandsParserValue::CharacterValue() const
{
assert(m_type == CommandsParserValueType::CHARACTER);
return m_value.char_value;
}
int CommandsParserValue::IntegerValue() const
{
assert(m_type == CommandsParserValueType::INTEGER);
@ -167,6 +188,12 @@ std::string& CommandsParserValue::IdentifierValue() const
return *m_value.string_value;
}
size_t CommandsParserValue::IdentifierHash() const
{
assert(m_type == CommandsParserValueType::IDENTIFIER);
return m_hash;
}
std::string& CommandsParserValue::TypeNameValue() const
{
assert(m_type == CommandsParserValueType::TYPE_NAME);

View File

@ -2,53 +2,52 @@
#include <string>
#include "Parsing/IParserValue.h"
#include "Utils/ClassUtils.h"
#include "Parsing/TokenPos.h"
class CommandsParserValueType
enum class CommandsParserValueType
{
CommandsParserValueType() = default;
// Meta tokens
INVALID,
END_OF_FILE,
public:
enum
{
FIRST = 0x100,
// Single character
CHARACTER,
// Meta tokens
INVALID = FIRST,
END_OF_FILE,
// Symbol tokens
SHIFT_LEFT,
SHIFT_RIGHT,
EQUALS,
NOT_EQUAL,
GREATER_EQUAL,
LESS_EQUAL,
LOGICAL_AND,
LOGICAL_OR,
// Symbol tokens
SHIFT_LEFT,
SHIFT_RIGHT,
EQUALS,
NOT_EQUAL,
GREATER_EQUAL,
LESS_EQUAL,
LOGICAL_AND,
LOGICAL_OR,
// Generic token types
INTEGER,
FLOATING_POINT,
STRING,
IDENTIFIER,
// Generic token types
INTEGER,
FLOATING_POINT,
STRING,
IDENTIFIER,
// Parser created
TYPE_NAME,
// Parser created
TYPE_NAME,
// End
MAX
};
// End
MAX
};
class CommandsParserValue
class CommandsParserValue final : public IParserValue
{
public:
TokenPos m_pos;
int m_type;
CommandsParserValueType m_type;
size_t m_hash;
union ValueType
{
char char_value;
int int_value;
double double_value;
std::string* string_value;
@ -72,18 +71,23 @@ public:
static CommandsParserValue TypeName(TokenPos pos, std::string* typeName);
private:
CommandsParserValue(TokenPos pos, int type);
CommandsParserValue(TokenPos pos, CommandsParserValueType type);
public:
~CommandsParserValue();
~CommandsParserValue() override;
CommandsParserValue(const CommandsParserValue& other) = delete;
CommandsParserValue(CommandsParserValue&& other) noexcept;
CommandsParserValue& operator=(const CommandsParserValue& other) = delete;
CommandsParserValue& operator=(CommandsParserValue&& other) noexcept;
_NODISCARD bool IsEof() const override;
_NODISCARD const TokenPos& GetPos() const override;
_NODISCARD char CharacterValue() const;
_NODISCARD int IntegerValue() const;
_NODISCARD double FloatingPointValue() const;
_NODISCARD std::string& StringValue() const;
_NODISCARD std::string& IdentifierValue() const;
_NODISCARD size_t IdentifierHash() const;
_NODISCARD std::string& TypeNameValue() const;
};