Compare commits

..

2 Commits

Author SHA1 Message Date
f2a45aa913 - Began outlining tokenizer.h and priority_queue.h
- Began outlining sdl implementation
- Added some helper definitions to various classes
- Added contains to string.h and wstring.h
2025-09-13 20:33:53 -04:00
3565bbbc52 - Fixed some logic errors with assertions for wide vs. byte files.
- Changed getline and getwline to use gets instead of the experimental functions. These, in theory, will be slightly faster.
2025-09-11 16:58:32 -04:00
18 changed files with 431 additions and 110 deletions

View File

@@ -238,6 +238,8 @@ add_library(fennec STATIC
${FENNEC_EXTRA_SOURCES} ${FENNEC_EXTRA_SOURCES}
include/fennec/renderers/interface/gfxresourcepool.h include/fennec/renderers/interface/gfxresourcepool.h
include/fennec/langproc/format/tokenizer.h
include/fennec/containers/priority_queue.h
) )
add_dependencies(fennec metaprogramming fennec-dependencies) add_dependencies(fennec metaprogramming fennec-dependencies)

View File

@@ -0,0 +1,66 @@
// =====================================================================================================================
// fennec, a free and open source game engine
// Copyright © 2025 Medusa Slockbower
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
// =====================================================================================================================
///
/// \file priority_queue.h
/// \brief
///
///
/// \details
/// \author Medusa Slockbower
///
/// \copyright Copyright © 2025 Medusa Slockbower ([GPLv3](https://www.gnu.org/licenses/gpl-3.0.en.html))
///
///
#ifndef FENNEC_CONTAINERS_PRIORITY_QUEUE_H
#define FENNEC_CONTAINERS_PRIORITY_QUEUE_H
#include <fennec/containers/object_pool.h>
#include <fennec/lang/compare.h>
#include <fennec/lang/types.h>
#include <fennec/memory/allocator.h>
namespace fennec
{
template<typename ValueT, class CompareT = less<ValueT>, class AllocT = allocator<ValueT>>
struct priority_queue {
public:
using value_t = ValueT;
using compare_t = CompareT;
using alloc_t = AllocT;
private:
struct node {
size_t parent, child;
size_t left, right;
int degree;
value_t key;
};
using table_t = object_pool<node>;
public:
table_t _table;
};
}
#endif // FENNEC_CONTAINERS_PRIORITY_QUEUE_H

View File

@@ -0,0 +1,96 @@
// =====================================================================================================================
// fennec, a free and open source game engine
// Copyright © 2025 Medusa Slockbower
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
// =====================================================================================================================
///
/// \file tokenizer.h
/// \brief
///
///
/// \details
/// \author Medusa Slockbower
///
/// \copyright Copyright © 2025 Medusa Slockbower ([GPLv3](https://www.gnu.org/licenses/gpl-3.0.en.html))
///
///
#ifndef FENNEC_LANGPROC_FORMAT_TOKENIZER_H
#define FENNEC_LANGPROC_FORMAT_TOKENIZER_H
#include <fennec/containers/list.h>
#include <fennec/langproc/strings/string.h>
//
// escape sequences are tricky, sometimes they must be separated by white space,
// other times they don't. Requiring a list of all possible escape sequences is unrealistic.
// We need to allow the user of this struct to specify rules for escape sequences. Here are some basic rules:
//
// An escape sequence is marked by an escape character, e.g. %, \, {{
// Multiple escape characters may be used in a single tokenizer and will have different rules
// Escape characters may also be operators, brackets, or quotes
// Escape sequences may contain operators, brackets, or quotes
//
// Here are a few examples of escape sequences from various formats and languages
// C: \\, \n, \0, \u200b
// PrintF: %s, %2.2f
// Python FMT: {{, }}
// SPSS: ''
//
namespace fennec
{
struct escape_sequence {
virtual size_t operator[](const std::string& str, size_t i) = 0;
};
struct tokenizer {
using escseq = escape_sequence*;
using escmap = map<char, escape_sequence*>;
string delimiter; // markers that separate tokens
string operators; // operators are treated as individual tokens
string brackets; // characters that mark brackets
string quotes; // characters that mark a string sequence, entire string sequence is treated as one token
escmap escapes; // characters that mark the start of an escape sequence and validate them
enum token_ : uint8_t {
token_string = 0,
token_newline = 1,
token_escaped = 2,
token_operator = 3,
token_bracket = 4,
token_quoted = 5,
};
using token = pair<string, uint8_t>;
private:
list<token> operator()(const string& line) {
list<token> res;
for (size_t i = 0; i < )
return res;
}
private:
};
}
#endif // FENNEC_LANGPROC_FORMAT_TOKENIZER_H

View File

@@ -250,9 +250,6 @@ public:
// Binary Read Operations ============================================================================================== // Binary Read Operations ==============================================================================================
char getc();
wchar_t getwc();
size_t read(void* data, size_t size, size_t n); size_t read(void* data, size_t size, size_t n);
template<typename T> template<typename T>
@@ -265,9 +262,6 @@ public:
return read(static_cast<void*>(data), sizeof(T), n); return read(static_cast<void*>(data), sizeof(T), n);
} }
string getline();
wstring getwline();
// Binary Write Operations ============================================================================================= // Binary Write Operations =============================================================================================
@@ -297,6 +291,15 @@ public:
} }
// Read Operations =====================================================================================================
char getc();
wchar_t getwc();
string getline();
wstring getwline();
// Printing Operations ================================================================================================= // Printing Operations =================================================================================================

View File

@@ -58,6 +58,7 @@ struct cstring
{ {
public: public:
static constexpr size_t npos = -1; static constexpr size_t npos = -1;
using char_t = char;
// Constructors ======================================================================================================== // Constructors ========================================================================================================

View File

@@ -47,6 +47,7 @@ struct _string
{ {
public: public:
static constexpr size_t npos = -1; static constexpr size_t npos = -1;
using char_t = char;
using alloc_t = allocation<char, AllocT>; using alloc_t = allocation<char, AllocT>;
@@ -197,7 +198,7 @@ public:
if (i >= size()) { // bounds check if (i >= size()) { // bounds check
return -1; return -1;
} }
n = fennec::min(n, fennec::max(_str, str.size()) + 1); n = fennec::min(n, fennec::max(size(), str.size()) + 1);
return ::strncmp(_str + i, str, n); return ::strncmp(_str + i, str, n);
} }
@@ -216,10 +217,23 @@ public:
return ::strncmp(_str + i, str.data(), n); return ::strncmp(_str + i, str.data(), n);
} }
constexpr bool operator==(const cstring& str) const {
return compare(str) == 0;
}
constexpr bool operator==(const _string& str) const { constexpr bool operator==(const _string& str) const {
return compare(str) == 0; return compare(str) == 0;
} }
///
/// \brief Check if the string contains a character
/// \param c
/// \param i
/// \return
constexpr bool contains(char c, size_t i = 0) const {
return find(c, i) != size();
}
/// ///
/// \brief Finds the index of the first occurrence of `c` in the string /// \brief Finds the index of the first occurrence of `c` in the string
/// \param c the character to find /// \param c the character to find
@@ -242,7 +256,7 @@ public:
return size(); return size();
} }
const char* loc = ::strstr(_str, str); const char* loc = ::strstr(_str, str._str);
return loc ? loc - _str : size(); return loc ? loc - _str : size();
} }
@@ -325,7 +339,7 @@ public:
/// \param n the number of characters /// \param n the number of characters
/// \return /// \return
constexpr _string substring(size_t i, size_t n = npos) const { constexpr _string substring(size_t i, size_t n = npos) const {
if (i >= size()) { if (i >= size() || n == 0) {
return _string(""); return _string("");
} }
n = fennec::min(n, size() - i); n = fennec::min(n, size() - i);
@@ -420,6 +434,25 @@ public:
} }
// Iteration ===========================================================================================================
constexpr char* begin() {
return _str.data();
}
constexpr const char* begin() const {
return _str.data();
}
constexpr char* end() {
return _str.data() + _str.capacity();
}
constexpr const char* end() const {
return _str.data() + _str.capacity();
}
private: private:
alloc_t _str; alloc_t _str;
}; };

View File

@@ -60,6 +60,7 @@ struct wcstring
{ {
public: public:
static constexpr size_t npos = -1; static constexpr size_t npos = -1;
using char_t = wchar_t;
// Constructors ======================================================================================================== // Constructors ========================================================================================================

View File

@@ -47,6 +47,7 @@ struct _wstring
{ {
public: public:
static constexpr size_t npos = -1; static constexpr size_t npos = -1;
using char_t = wchar_t;
using alloc_t = allocation<wchar_t, AllocT>; using alloc_t = allocation<wchar_t, AllocT>;
@@ -216,10 +217,23 @@ public:
return ::wcsncmp(_str + i, str.data(), n); return ::wcsncmp(_str + i, str.data(), n);
} }
constexpr bool operator==(const wcstring& str) const {
return compare(str) == 0;
}
constexpr bool operator==(const _wstring& str) const { constexpr bool operator==(const _wstring& str) const {
return compare(str) == 0; return compare(str) == 0;
} }
///
/// \brief Check if the string contains a character
/// \param c
/// \param i
/// \return
constexpr bool contains(char c, size_t i = 0) const {
return find(c, i) != size();
}
/// ///
/// \brief Finds the index of the first occurrence of `c` in the string /// \brief Finds the index of the first occurrence of `c` in the string
/// \param c the wchar_tacter to find /// \param c the wchar_tacter to find

View File

@@ -306,8 +306,8 @@ public:
// Quaternion Quaternion Arithmetic Operators ========================================================================== // Quaternion Quaternion Arithmetic Operators ==========================================================================
constexpr friend quaternion operator+(const quaternion& lhs, const quaternion& rhs) { constexpr friend quat_t operator+(const quat_t& lhs, const quat_t& rhs) {
return quaternion( return quat_t(
lhs.w + rhs.w, lhs.w + rhs.w,
lhs.x + rhs.x, lhs.x + rhs.x,
lhs.y + rhs.y, lhs.y + rhs.y,
@@ -315,8 +315,8 @@ public:
); );
} }
constexpr friend quaternion operator-(const quaternion& lhs, const quaternion& rhs) { constexpr friend quat_t operator-(const quat_t& lhs, const quat_t& rhs) {
return quaternion( return quat_t(
lhs.w - rhs.w, lhs.w - rhs.w,
lhs.x - rhs.x, lhs.x - rhs.x,
lhs.y - rhs.y, lhs.y - rhs.y,
@@ -324,8 +324,8 @@ public:
); );
} }
constexpr friend quaternion operator*(const quaternion& lhs, const quaternion& rhs) { constexpr friend quat_t operator*(const quat_t& lhs, const quat_t& rhs) {
return quaternion( return quat_t(
lhs.w*rhs.w - lhs.x*rhs.x - lhs.y*rhs.y - lhs.z * rhs.z, lhs.w*rhs.w - lhs.x*rhs.x - lhs.y*rhs.y - lhs.z * rhs.z,
lhs.w*rhs.x + lhs.x*rhs.w + lhs.y*rhs.z - lhs.z * rhs.y, lhs.w*rhs.x + lhs.x*rhs.w + lhs.y*rhs.z - lhs.z * rhs.y,
lhs.w*rhs.y - lhs.x*rhs.z + lhs.y*rhs.w + lhs.z * rhs.x, lhs.w*rhs.y - lhs.x*rhs.z + lhs.y*rhs.w + lhs.z * rhs.x,
@@ -336,7 +336,7 @@ public:
// Quaternion Quaternion Arithmetic Assignment Operators =============================================================== // Quaternion Quaternion Arithmetic Assignment Operators ===============================================================
constexpr friend quaternion& operator+=(quaternion& lhs, const quaternion& rhs) { constexpr friend quat_t& operator+=(quat_t& lhs, const quat_t& rhs) {
lhs.w += rhs.w; lhs.w += rhs.w;
lhs.x += rhs.x; lhs.x += rhs.x;
lhs.y += rhs.y; lhs.y += rhs.y;
@@ -344,7 +344,7 @@ public:
return lhs; return lhs;
} }
constexpr friend quaternion& operator-=(quaternion& lhs, const quaternion& rhs) { constexpr friend quat_t& operator-=(quat_t& lhs, const quat_t& rhs) {
lhs.w -= rhs.w; lhs.w -= rhs.w;
lhs.x -= rhs.x; lhs.x -= rhs.x;
lhs.y -= rhs.y; lhs.y -= rhs.y;
@@ -352,7 +352,7 @@ public:
return lhs; return lhs;
} }
constexpr friend quaternion& operator*=(quaternion& lhs, const quaternion& rhs) { constexpr friend quat_t& operator*=(quat_t& lhs, const quat_t& rhs) {
return lhs = lhs * rhs; return lhs = lhs * rhs;
} }

View File

@@ -280,7 +280,7 @@ public:
/// \details This simply acts as a proxy for allocating memory. It does not call any constructors or /// \details This simply acts as a proxy for allocating memory. It does not call any constructors or
/// initialize any values as if they were the provided data type. Any operations present work /// initialize any values as if they were the provided data type. Any operations present work
/// only on individual bytes. /// only on individual bytes.
template<typename T, class AllocT> template<typename T, class AllocT = allocator<T>>
struct allocation struct allocation
{ {
public: public:

View File

@@ -33,6 +33,7 @@
#include <fennec/lang/types.h> #include <fennec/lang/types.h>
#include <fennec/langproc/strings/string.h> #include <fennec/langproc/strings/string.h>
#include <fennec/renderers/interface/gfxcontext.h>
namespace fennec namespace fennec
{ {
@@ -115,15 +116,21 @@ public:
// Modifiers =========================================================================================================== // Modifiers ===========================================================================================================
virtual void resize(size_t, size_t) = 0;
virtual void position(size_t, size_t) = 0;
virtual void set_fullscreen(bool) = 0; virtual void set_fullscreen(bool) = 0;
virtual void set_borderless(bool) = 0; virtual void set_borderless(bool) = 0;
virtual void grab_mouse(bool) = 0; virtual void grab_mouse(bool) = 0;
virtual void grab_keyboard(bool) = 0; virtual void grab_keyboard(bool) = 0;
virtual void set_title(const cstring&) = 0; virtual void set_title(const cstring&) = 0;
virtual void set_title(const string&) = 0; virtual void set_title(const string&) = 0;
virtual void vsync(int8_t) = 0;
virtual void set_progress(bool, float) = 0; virtual void set_progress(bool, float) = 0;
virtual void vsync(int8_t) = 0;
// Graphics ============================================================================================================ // Graphics ============================================================================================================
virtual void begin_frame() = 0; virtual void begin_frame() = 0;
@@ -131,6 +138,7 @@ public:
protected: protected:
window* _parent; window* _parent;
gfxcontext* _context;
config _config; config _config;
window(window* parent, const config& cfg) window(window* parent, const config& cfg)

View File

@@ -38,7 +38,25 @@ namespace fennec
class sdlwindow : public window { class sdlwindow : public window {
public: public:
sdlwindow(window* parent, const config& cfg);
bool running() override;
void set_fullscreen(bool) override;
void set_borderless(bool) override;
void grab_mouse(bool) override;
void grab_keyboard(bool) override;
void set_title(const cstring&) override;
void set_title(const string&) override;
void set_progress(bool, float) override;
void vsync(int8_t) override;
void begin_frame() override;
void end_frame() override;
private: private:

View File

@@ -37,6 +37,7 @@ namespace fennec
class gfxpass; // Overarching rendering scheme class gfxpass; // Overarching rendering scheme
class gfxcontext; // Globals for an API's context class gfxcontext; // Globals for an API's context
class gfxresourcepool; // Handles resource creation, allocation, and mapping class gfxresourcepool; // Handles resource creation, allocation, and mapping
class gfxpass; // A pass of the renderer, holds a set of subpasses with one coherent objective
class gfxsubpass; // A subpass of the renderer, implements, for example, the steps of composing and lighting a deferred renderer class gfxsubpass; // A subpass of the renderer, implements, for example, the steps of composing and lighting a deferred renderer
class gfxpipeline; // A user-defined pipeline, e.g. the Vulkan pipeline needed to render the G-Buffer class gfxpipeline; // A user-defined pipeline, e.g. the Vulkan pipeline needed to render the G-Buffer

View File

@@ -39,17 +39,22 @@ namespace fennec
{ {
/// ///
/// \brief Defines a renderer interface to implement different graphics APIs, e.g. OpenGL Vulkan /// \brief Defines an interface that holds a series of passes with one coherent objective
/// \details This represents the overarching renderer, and not any platform specific behaviour. /// \details This represents the overarching renderer, and not any platform specific behaviour.
/// I.E. This acts as a proxy for creating API objects, but the behaviour of those objects /// I.E. This acts as a proxy for creating API objects, but the behaviour of those objects
/// is defined elsewhere. /// is defined elsewhere.
class gfxpass { class gfxpass {
public: public:
gfxsubpass* add_subpass();
private: private:
}; };
class gfxsubpass {
};
} }
#endif // FENNEC_PLATFORM_INTERFACE_GFXCONTEXT_H #endif // FENNEC_PLATFORM_INTERFACE_GFXCONTEXT_H

View File

@@ -19,6 +19,7 @@
#include <errno.h> #include <errno.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <bits/posix2_lim.h>
#include <fennec/langproc/filesystem/file.h> #include <fennec/langproc/filesystem/file.h>
#include <fennec/langproc/filesystem/path.h> #include <fennec/langproc/filesystem/path.h>
@@ -921,7 +922,7 @@ bool file::eof() const {
char file::getc() { char file::getc() {
assert(_error == nullptr, "Attempted an Operation on a File in an Errored State"); assert(_error == nullptr, "Attempted an Operation on a File in an Errored State");
assert(not(_mode & fmode_wide), "Attempted Byte Operation on Wide File"); assert(not(_mode & fmode_wide), "Attempted Wide Operation on Byte File");
// Check if there is a file // Check if there is a file
if (_handle == nullptr) { if (_handle == nullptr) {
@@ -933,7 +934,7 @@ char file::getc() {
wchar_t file::getwc() { wchar_t file::getwc() {
assert(_error == nullptr, "Attempted an Operation on a File in an Errored State"); assert(_error == nullptr, "Attempted an Operation on a File in an Errored State");
assert(_mode & fmode_wide, "Attempted Wide Operation on Byte File"); assert(_mode & fmode_wide, "Attempted Byte Operation on Wide File");
// Check if there is a file // Check if there is a file
if (_handle == nullptr) { if (_handle == nullptr) {
@@ -959,92 +960,6 @@ size_t file::read(void* data, size_t size, size_t n) {
return read; return read;
} }
string file::getline() {
assert(_error == nullptr, "Attempted an Operation on a File in an Errored State");
assert(not(_mode & fmode_wide), "Attempted Byte Operation on Wide File");
// Check if there is a file
if (_handle == nullptr) {
return 0;
}
// Read the next line;
char* line = nullptr;
size_t size = 0;
const size_t read = ::getline(&line, &size, _handle);
if (read == npos && ferror(_handle)) {
_error = strerror(errno);
if (line) free(line);
return string("");
}
string res = string(line, read);
free(line);
return res;
}
wstring file::getwline() {
assert(_error == nullptr, "Attempted an Operation on a File in an Errored State");
assert(_mode & fmode_wide, "Attempted Wide Operation on Byte File");
// Check if there is a file
if (_handle == nullptr) {
return _wstring{ L"" };
}
// Read the next line;
wchar_t arr[257] = { L'\0' };
wcstring buff = arr;
wstring res{L""};
// read until first newline or end of file
while (fgetws(arr, 257, _handle)) {
res += wcstring(arr, buff.length());
if (buff.length() < 256 || buff[256] == L'\n') {
return res;
}
}
_error = strerror(errno);
return wstring(L"");
}
bool file::putc(char c) {
assert(_error == nullptr, "Attempted an Operation on a File in an Errored State");
assert(not(_mode & fmode_wide), "Attempted Byte Operation on Wide File");
// Check if there is a file
if (_handle == nullptr) {
return false;
}
int res;
if ((res = fputc(c, _handle)) != c && res != EOF) {
_error = strerror(errno);
return true;
}
return false;
}
bool file::putwc(wchar_t c) {
assert(_error == nullptr, "Attempted an Operation on a File in an Errored State");
assert(_mode & fmode_wide, "Attempted Wide Operation on Byte File");
// Check if there is a file
if (_handle == nullptr) {
return false;
}
int res;
if ((res = fputc(c, _handle)) != c && res != EOF) {
_error = strerror(errno);
return true;
}
return false;
}
size_t file::write(const void* data, size_t size, size_t n) { size_t file::write(const void* data, size_t size, size_t n) {
assert(_error == nullptr, "Attempted an Operation on a File in an Errored State"); assert(_error == nullptr, "Attempted an Operation on a File in an Errored State");
@@ -1063,4 +978,92 @@ size_t file::write(const void* data, size_t size, size_t n) {
return r; return r;
} }
string file::getline() {
assert(_error == nullptr, "Attempted an Operation on a File in an Errored State");
assert(not(_mode & fmode_wide), "Attempted Wide Operation on Byte File");
// Check if there is a file
if (_handle == nullptr) {
return string{ "" };
}
// Read the next line;
char arr[LINE_MAX + 2] = { L'\0' };
cstring buff = arr;
string res{""};
// read until first newline or end of file
while (fgets(arr, LINE_MAX + 2, _handle)) {
res += cstring(arr, buff.length());
if (buff.length() < LINE_MAX || buff[LINE_MAX] == L'\n') {
return res;
}
}
_error = strerror(errno);
return string("");
}
wstring file::getwline() {
assert(_error == nullptr, "Attempted an Operation on a File in an Errored State");
assert(_mode & fmode_wide, "Attempted Byte Operation on Wide File");
// Check if there is a file
if (_handle == nullptr) {
return _wstring{ L"" };
}
// Read the next line;
wchar_t arr[LINE_MAX + 2] = { L'\0' };
wcstring buff = arr;
wstring res{L""};
// read until first newline or end of file
while (fgetws(arr, LINE_MAX + 2, _handle)) {
res += wcstring(arr, buff.length());
if (buff.length() < LINE_MAX || buff[LINE_MAX] == L'\n') {
return res;
}
}
_error = strerror(errno);
return wstring(L"");
}
bool file::putc(char c) {
assert(_error == nullptr, "Attempted an Operation on a File in an Errored State");
assert(not(_mode & fmode_wide), "Attempted Wide Operation on Byte File");
// Check if there is a file
if (_handle == nullptr) {
return false;
}
int res;
if ((res = fputc(c, _handle)) != c && res != EOF) {
_error = strerror(errno);
return true;
}
return false;
}
bool file::putwc(wchar_t c) {
assert(_error == nullptr, "Attempted an Operation on a File in an Errored State");
assert(_mode & fmode_wide, "Attempted Byte Operation on Wide File");
// Check if there is a file
if (_handle == nullptr) {
return false;
}
int res;
if ((res = fputc(c, _handle)) != c && res != EOF) {
_error = strerror(errno);
return true;
}
return false;
}
} }

View File

@@ -8,6 +8,7 @@ add_executable(fennec-test
main.cpp main.cpp
tests/containers/performance/test_iterator_visitor.h tests/containers/performance/test_iterator_visitor.h
tests/containers/test_sequence.h tests/containers/test_sequence.h
tests/langproc/test_format.h
) )
target_compile_definitions(fennec-test PUBLIC FENNEC_TEST_CWD="${CMAKE_SOURCE_DIR}/bin/${FENNEC_BUILD_NAME}" target_compile_definitions(fennec-test PUBLIC FENNEC_TEST_CWD="${CMAKE_SOURCE_DIR}/bin/${FENNEC_BUILD_NAME}"

View File

@@ -0,0 +1,63 @@
// =====================================================================================================================
// fennec, a free and open source game engine
// Copyright © 2025 Medusa Slockbower
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
// =====================================================================================================================
///
/// \file test_format.h
/// \brief
///
///
/// \details
/// \author Medusa Slockbower
///
/// \copyright Copyright © 2025 Medusa Slockbower ([GPLv3](https://www.gnu.org/licenses/gpl-3.0.en.html))
///
///
#ifndef FENNEC_TEST_LANGPROC_FORMAT_H
#define FENNEC_TEST_LANGPROC_FORMAT_H
#include <fennec/langproc/format/tokenizer.h>
namespace fennec
{
namespace test
{
inline void fennec_test_langproc_format() {
tokenizer math = {
.delimiter { " " },
.operators {"+-/*="},
.braces { "()" },
.escapes { "" },
.terminator { "" },
};
const auto res = math.parse("1 + 2 = 3");
fennec_test_run(res.size(), size_t(5));
for (const auto& token : res) {
std::cout << token.second << ", ";
}
}
}
}
#endif // FENNEC_TEST_LANGPROC_FORMAT_H

View File

@@ -23,6 +23,7 @@
#include "./langproc/test_strings.h" #include "./langproc/test_strings.h"
#include "./langproc/test_io.h" #include "./langproc/test_io.h"
#include "langproc/test_format.h"
namespace fennec::test namespace fennec::test
{ {
@@ -33,6 +34,11 @@ namespace fennec::test
fennec_test_langproc_strings(); fennec_test_langproc_strings();
fennec_test_spacer(3); fennec_test_spacer(3);
fennec_test_header("format");
fennec_test_spacer(2);
fennec_test_langproc_format();
fennec_test_spacer(3);
fennec_test_header("io"); fennec_test_header("io");
fennec_test_spacer(2); fennec_test_spacer(2);
fennec_test_langproc_io(); fennec_test_langproc_io();