From 66fe6ba38889ee369d8747c5236f1b8138e51c16 Mon Sep 17 00:00:00 2001 From: Madeline Busig Date: Tue, 29 Apr 2025 05:55:13 -0700 Subject: [PATCH] Implement ruleset_t::add_token --- include/fractal.hpp | 3 +-- src/fractal.cpp | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/include/fractal.hpp b/include/fractal.hpp index 0c66d27..ff295af 100644 --- a/include/fractal.hpp +++ b/include/fractal.hpp @@ -30,7 +30,7 @@ enum class token_type_e { }; struct token_t { - token_type_e m_token = token_type_e::empty; + token_type_e m_type = token_type_e::empty; mtl::fixed m_value; }; @@ -111,7 +111,6 @@ public: * * @ret @c token_id_t of the newly added token, local to this ruleset * - * @exception @c mtl::invalid_argument if the given token type is invalid * @exception @c mtl::length_error if the maximum number of tokens is reached */ token_id_t add_token(token_type_e type, mtl::fixed value = 0); diff --git a/src/fractal.cpp b/src/fractal.cpp index d0382be..8f21041 100644 --- a/src/fractal.cpp +++ b/src/fractal.cpp @@ -8,6 +8,21 @@ namespace log = mtl::log; namespace fractal { +bool ruleset_t::tokens_full() const { + return m_tokens.full(); +} + +token_id_t ruleset_t::add_token(token_type_e type, mtl::fixed value) { + if (m_tokens.full()) { + throw mtl::length_error(); + } + + token_t tok { .m_type = type, .m_value = value }; + + m_tokens.push_back(tok); + return m_tokens.size() - 1; +} + #if 0 token_id_t generator_t::add_token(token_type_e type, mtl::fixed value) { log::debug << "Adding token with type " << (int)type << endl;