mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-07-01 08:41:52 +00:00
Add Tests for ZCG cpp
This commit is contained in:
@ -0,0 +1,11 @@
|
||||
#include "CommandsLexer.h"
|
||||
|
||||
CommandsLexer::CommandsLexer(IParserLineStream* stream)
|
||||
: AbstractLexer(stream)
|
||||
{
|
||||
}
|
||||
|
||||
CommandsParserValue CommandsLexer::GetNextToken()
|
||||
{
|
||||
return CommandsParserValue::Invalid(TokenPos());
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include "CommandsParserValue.h"
|
||||
#include "Parsing/AbstractLexer.h"
|
||||
|
||||
class CommandsLexer final : public AbstractLexer<CommandsParserValue>
|
||||
{
|
||||
protected:
|
||||
CommandsParserValue GetNextToken() override;
|
||||
|
||||
public:
|
||||
explicit CommandsLexer(IParserLineStream* stream);
|
||||
};
|
@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
class CommandsParser
|
||||
{
|
||||
|
||||
};
|
@ -0,0 +1,174 @@
|
||||
#include "CommandsParserValue.h"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
CommandsParserValue CommandsParserValue::Invalid(const TokenPos pos)
|
||||
{
|
||||
CommandsParserValue pv(pos, CommandsParserValueType::INVALID);
|
||||
return pv;
|
||||
}
|
||||
|
||||
CommandsParserValue CommandsParserValue::EndOfFile(const TokenPos pos)
|
||||
{
|
||||
CommandsParserValue pv(pos, CommandsParserValueType::END_OF_FILE);
|
||||
return pv;
|
||||
}
|
||||
|
||||
CommandsParserValue CommandsParserValue::Character(const TokenPos pos, const char c)
|
||||
{
|
||||
CommandsParserValue pv(pos, c);
|
||||
return pv;
|
||||
}
|
||||
|
||||
CommandsParserValue CommandsParserValue::ShiftLeft(const TokenPos pos)
|
||||
{
|
||||
CommandsParserValue pv(pos, CommandsParserValueType::SHIFT_LEFT);
|
||||
return pv;
|
||||
}
|
||||
|
||||
CommandsParserValue CommandsParserValue::ShiftRight(const TokenPos pos)
|
||||
{
|
||||
CommandsParserValue pv(pos, CommandsParserValueType::SHIFT_RIGHT);
|
||||
return pv;
|
||||
}
|
||||
|
||||
CommandsParserValue CommandsParserValue::Equals(const TokenPos pos)
|
||||
{
|
||||
CommandsParserValue pv(pos, CommandsParserValueType::EQUALS);
|
||||
return pv;
|
||||
}
|
||||
|
||||
CommandsParserValue CommandsParserValue::NotEqual(const TokenPos pos)
|
||||
{
|
||||
CommandsParserValue pv(pos, CommandsParserValueType::NOT_EQUAL);
|
||||
return pv;
|
||||
}
|
||||
|
||||
CommandsParserValue CommandsParserValue::GreaterEqual(const TokenPos pos)
|
||||
{
|
||||
CommandsParserValue pv(pos, CommandsParserValueType::GREATER_EQUAL);
|
||||
return pv;
|
||||
}
|
||||
|
||||
CommandsParserValue CommandsParserValue::LessEqual(const TokenPos pos)
|
||||
{
|
||||
CommandsParserValue pv(pos, CommandsParserValueType::LESS_EQUAL);
|
||||
return pv;
|
||||
}
|
||||
|
||||
CommandsParserValue CommandsParserValue::LogicalAnd(const TokenPos pos)
|
||||
{
|
||||
CommandsParserValue pv(pos, CommandsParserValueType::LOGICAL_AND);
|
||||
return pv;
|
||||
}
|
||||
|
||||
CommandsParserValue CommandsParserValue::LogicalOr(const TokenPos pos)
|
||||
{
|
||||
CommandsParserValue pv(pos, CommandsParserValueType::LOGICAL_OR);
|
||||
return pv;
|
||||
}
|
||||
|
||||
CommandsParserValue CommandsParserValue::Integer(const TokenPos pos, const int value)
|
||||
{
|
||||
CommandsParserValue pv(pos, CommandsParserValueType::INTEGER);
|
||||
pv.m_value.int_value = value;
|
||||
return pv;
|
||||
}
|
||||
|
||||
CommandsParserValue CommandsParserValue::FloatingPoint(const TokenPos pos, const double value)
|
||||
{
|
||||
CommandsParserValue pv(pos, CommandsParserValueType::FLOATING_POINT);
|
||||
pv.m_value.double_value = value;
|
||||
return pv;
|
||||
}
|
||||
|
||||
CommandsParserValue CommandsParserValue::String(const TokenPos pos, std::string* stringValue)
|
||||
{
|
||||
CommandsParserValue pv(pos, CommandsParserValueType::STRING);
|
||||
pv.m_value.string_value = stringValue;
|
||||
return pv;
|
||||
}
|
||||
|
||||
CommandsParserValue CommandsParserValue::Identifier(const TokenPos pos, std::string* identifier)
|
||||
{
|
||||
CommandsParserValue pv(pos, CommandsParserValueType::IDENTIFIER);
|
||||
pv.m_value.string_value = identifier;
|
||||
return pv;
|
||||
}
|
||||
|
||||
CommandsParserValue CommandsParserValue::TypeName(const TokenPos pos, std::string* typeName)
|
||||
{
|
||||
CommandsParserValue pv(pos, CommandsParserValueType::TYPE_NAME);
|
||||
pv.m_value.string_value = typeName;
|
||||
return pv;
|
||||
}
|
||||
|
||||
CommandsParserValue::CommandsParserValue(const TokenPos pos, const int type)
|
||||
: m_pos(pos),
|
||||
m_type(type),
|
||||
m_value()
|
||||
{
|
||||
}
|
||||
|
||||
CommandsParserValue::~CommandsParserValue()
|
||||
{
|
||||
switch (m_type)
|
||||
{
|
||||
case CommandsParserValueType::STRING:
|
||||
case CommandsParserValueType::IDENTIFIER:
|
||||
case CommandsParserValueType::TYPE_NAME:
|
||||
delete m_value.string_value;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
m_value = ValueType();
|
||||
}
|
||||
|
||||
CommandsParserValue::CommandsParserValue(CommandsParserValue&& other) noexcept
|
||||
: m_type(other.m_type),
|
||||
m_value(other.m_value)
|
||||
{
|
||||
other.m_value = ValueType();
|
||||
}
|
||||
|
||||
CommandsParserValue& CommandsParserValue::operator=(CommandsParserValue&& other) noexcept
|
||||
{
|
||||
m_type = other.m_type;
|
||||
m_value = other.m_value;
|
||||
other.m_value = ValueType();
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
int CommandsParserValue::IntegerValue() const
|
||||
{
|
||||
assert(m_type == CommandsParserValueType::INTEGER);
|
||||
return m_value.int_value;
|
||||
}
|
||||
|
||||
double CommandsParserValue::FloatingPointValue() const
|
||||
{
|
||||
assert(m_type == CommandsParserValueType::FLOATING_POINT);
|
||||
return m_value.double_value;
|
||||
}
|
||||
|
||||
std::string& CommandsParserValue::StringValue() const
|
||||
{
|
||||
assert(m_type == CommandsParserValueType::STRING);
|
||||
return *m_value.string_value;
|
||||
}
|
||||
|
||||
std::string& CommandsParserValue::IdentifierValue() const
|
||||
{
|
||||
assert(m_type == CommandsParserValueType::IDENTIFIER);
|
||||
return *m_value.string_value;
|
||||
}
|
||||
|
||||
std::string& CommandsParserValue::TypeNameValue() const
|
||||
{
|
||||
assert(m_type == CommandsParserValueType::TYPE_NAME);
|
||||
return *m_value.string_value;
|
||||
}
|
@ -0,0 +1,88 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "Parsing/TokenPos.h"
|
||||
#include "Utils/ClassUtils.h"
|
||||
|
||||
class CommandsParserValueType
|
||||
{
|
||||
CommandsParserValueType() = default;
|
||||
public:
|
||||
enum
|
||||
{
|
||||
FIRST = 0x100,
|
||||
|
||||
// Meta tokens
|
||||
INVALID = FIRST,
|
||||
END_OF_FILE,
|
||||
|
||||
// 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,
|
||||
|
||||
// Parser created
|
||||
TYPE_NAME,
|
||||
|
||||
// End
|
||||
MAX
|
||||
};
|
||||
};
|
||||
|
||||
class CommandsParserValue
|
||||
{
|
||||
public:
|
||||
TokenPos m_pos;
|
||||
int m_type;
|
||||
union ValueType
|
||||
{
|
||||
int int_value;
|
||||
double double_value;
|
||||
std::string* string_value;
|
||||
} m_value;
|
||||
|
||||
static CommandsParserValue Invalid(TokenPos pos);
|
||||
static CommandsParserValue EndOfFile(TokenPos pos);
|
||||
static CommandsParserValue Character(TokenPos pos, char c);
|
||||
static CommandsParserValue ShiftLeft(TokenPos pos);
|
||||
static CommandsParserValue ShiftRight(TokenPos pos);
|
||||
static CommandsParserValue Equals(TokenPos pos);
|
||||
static CommandsParserValue NotEqual(TokenPos pos);
|
||||
static CommandsParserValue GreaterEqual(TokenPos pos);
|
||||
static CommandsParserValue LessEqual(TokenPos pos);
|
||||
static CommandsParserValue LogicalAnd(TokenPos pos);
|
||||
static CommandsParserValue LogicalOr(TokenPos pos);
|
||||
static CommandsParserValue Integer(TokenPos pos, int value);
|
||||
static CommandsParserValue FloatingPoint(TokenPos pos, double value);
|
||||
static CommandsParserValue String(TokenPos pos, std::string* stringValue);
|
||||
static CommandsParserValue Identifier(TokenPos pos, std::string* identifier);
|
||||
static CommandsParserValue TypeName(TokenPos pos, std::string* typeName);
|
||||
|
||||
private:
|
||||
CommandsParserValue(TokenPos pos, int type);
|
||||
|
||||
public:
|
||||
~CommandsParserValue();
|
||||
CommandsParserValue(const CommandsParserValue& other) = delete;
|
||||
CommandsParserValue(CommandsParserValue&& other) noexcept;
|
||||
CommandsParserValue& operator=(const CommandsParserValue& other) = delete;
|
||||
CommandsParserValue& operator=(CommandsParserValue&& other) noexcept;
|
||||
|
||||
_NODISCARD int IntegerValue() const;
|
||||
_NODISCARD double FloatingPointValue() const;
|
||||
_NODISCARD std::string& StringValue() const;
|
||||
_NODISCARD std::string& IdentifierValue() const;
|
||||
_NODISCARD std::string& TypeNameValue() const;
|
||||
};
|
Reference in New Issue
Block a user