2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2026-03-07 05:23:02 +00:00

Add Simple Parsing implementations for basic parsers

This commit is contained in:
Jan
2021-03-09 11:04:04 +01:00
parent 8d9080066f
commit 88ff98f334
14 changed files with 503 additions and 0 deletions

View File

@@ -0,0 +1,69 @@
#pragma once
#include <string>
#include "Parsing/IParserValue.h"
#include "Utils/ClassUtils.h"
#include "Parsing/TokenPos.h"
enum class SimpleParserValueType
{
// Meta tokens
INVALID,
END_OF_FILE,
// Single character
CHARACTER,
// Generic token types
INTEGER,
FLOATING_POINT,
STRING,
IDENTIFIER,
// End
MAX
};
class SimpleParserValue final : public IParserValue
{
public:
TokenPos m_pos;
SimpleParserValueType m_type;
size_t m_hash;
union ValueType
{
char char_value;
int int_value;
double double_value;
std::string* string_value;
} m_value;
static SimpleParserValue Invalid(TokenPos pos);
static SimpleParserValue EndOfFile(TokenPos pos);
static SimpleParserValue Character(TokenPos pos, char c);
static SimpleParserValue Integer(TokenPos pos, int value);
static SimpleParserValue FloatingPoint(TokenPos pos, double value);
static SimpleParserValue String(TokenPos pos, std::string* stringValue);
static SimpleParserValue Identifier(TokenPos pos, std::string* identifier);
private:
SimpleParserValue(TokenPos pos, SimpleParserValueType type);
public:
~SimpleParserValue() override;
SimpleParserValue(const SimpleParserValue& other) = delete;
SimpleParserValue(SimpleParserValue&& other) noexcept;
SimpleParserValue& operator=(const SimpleParserValue& other) = delete;
SimpleParserValue& operator=(SimpleParserValue&& 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;
};