Move token marking identifier into token_t, remove marking rules
This has the side effect that each token can only have one mark assigned to it.
This commit is contained in:
parent
83130ba7bd
commit
722a7eb202
@ -17,7 +17,6 @@ constexpr size_t g_max_tokens = 16;
|
||||
constexpr size_t g_max_groups = 8;
|
||||
constexpr size_t g_max_wgroups = 4;
|
||||
constexpr size_t g_max_branch_rules = 8;
|
||||
constexpr size_t g_max_mark_rules = 4;
|
||||
constexpr size_t g_max_cgroup_tokens = 16;
|
||||
constexpr size_t g_max_wgroup_weights = 8;
|
||||
constexpr size_t g_max_match_groups = 8;
|
||||
@ -27,7 +26,6 @@ using token_id_t = uint32_t;
|
||||
using group_id_t = uint32_t;
|
||||
using weighted_group_id_t = uint32_t;
|
||||
using branch_rule_id_t = uint32_t;
|
||||
using mark_rule_id_t = uint32_t;
|
||||
|
||||
enum class token_type_e {
|
||||
empty,
|
||||
@ -38,6 +36,7 @@ enum class token_type_e {
|
||||
struct token_t {
|
||||
token_type_e m_type = token_type_e::empty;
|
||||
mtl::fixed m_value;
|
||||
uint32_t m_mark;
|
||||
};
|
||||
|
||||
struct group_characteristic_t {
|
||||
@ -92,11 +91,6 @@ struct branch_rule_t {
|
||||
} m_group;
|
||||
};
|
||||
|
||||
struct mark_rule_t {
|
||||
token_id_t m_match;
|
||||
uint32_t m_tag;
|
||||
};
|
||||
|
||||
class ruleset_t {
|
||||
private:
|
||||
etl::vector<token_t, g_max_tokens> m_tokens;
|
||||
@ -104,7 +98,6 @@ private:
|
||||
etl::vector<weighted_group_t, g_max_wgroups> m_weighted_groups;
|
||||
|
||||
etl::vector<branch_rule_t, g_max_branch_rules> m_branch_rules;
|
||||
etl::vector<mark_rule_t, g_max_mark_rules> m_mark_rules;
|
||||
|
||||
public:
|
||||
/**
|
||||
@ -129,7 +122,7 @@ public:
|
||||
*
|
||||
* @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);
|
||||
token_id_t add_token(token_type_e type, mtl::fixed value = 0, uint32_t mark = 0);
|
||||
|
||||
/**
|
||||
* @brief Checks if the maximum number of group characteristics has been reached
|
||||
@ -225,29 +218,7 @@ public:
|
||||
*/
|
||||
branch_rule_id_t add_branch_rule_weighted(token_id_t match, weighted_group_id_t wgroup);
|
||||
|
||||
/**
|
||||
* @brief Checks if the maximum number of mark rules has been reached
|
||||
*
|
||||
* @ret @c true if the number of mark rules in the ruleset equals @c g_max_mark_rules, @c false otherwise
|
||||
*/
|
||||
bool mark_rules_full() const {
|
||||
return m_mark_rules.full();
|
||||
}
|
||||
|
||||
/** @brief Add a new marking rule to the ruleset
|
||||
*
|
||||
* Mark rules describe what tokens should have their positions output
|
||||
* each generation. If a token has a match, its position and a tag is output.
|
||||
*
|
||||
* @param match Token to match and mark
|
||||
* @param tag Marking identifier, does not need to be unique
|
||||
*
|
||||
* @ret @c mark_rule_id_t of the newly added mark rule
|
||||
*
|
||||
* @exception @c mtl::invalid_argument if an invalid token was supplied
|
||||
* @exception @c mtl::length_error if the maximum number of mark rules was reached
|
||||
*/
|
||||
mark_rule_id_t add_mark_rule(token_id_t match, uint32_t tag);
|
||||
};
|
||||
|
||||
class generator_t {
|
||||
|
||||
@ -22,12 +22,14 @@ mtl::mat<2, 2> create_rotation(mtl::fixed angle_cos) {
|
||||
|
||||
namespace fractal {
|
||||
|
||||
token_id_t ruleset_t::add_token(token_type_e type, mtl::fixed value) {
|
||||
// ---------- RULESET ----------
|
||||
|
||||
token_id_t ruleset_t::add_token(token_type_e type, mtl::fixed value, uint32_t mark) {
|
||||
if (m_tokens.full()) {
|
||||
throw mtl::length_error();
|
||||
}
|
||||
|
||||
token_t tok { .m_type = type, .m_value = value };
|
||||
token_t tok { .m_type = type, .m_value = value, .m_mark = mark};
|
||||
|
||||
m_tokens.push_back(tok);
|
||||
return m_tokens.size() - 1;
|
||||
@ -110,19 +112,6 @@ branch_rule_id_t ruleset_t::add_branch_rule_weighted(token_id_t match, weighted_
|
||||
return m_branch_rules.size() - 1;
|
||||
}
|
||||
|
||||
mark_rule_id_t ruleset_t::add_mark_rule(token_id_t match, uint32_t tag) {
|
||||
if (!valid_token(match)) {
|
||||
throw mtl::invalid_argument();
|
||||
}
|
||||
|
||||
mark_rule_t rule {
|
||||
.m_match = match,
|
||||
.m_tag = tag
|
||||
};
|
||||
|
||||
m_mark_rules.push_back(rule);
|
||||
return m_mark_rules.size() - 1;
|
||||
}
|
||||
|
||||
#if 0
|
||||
token_id_t generator_t::add_token(token_type_e type, mtl::fixed value) {
|
||||
|
||||
@ -33,7 +33,7 @@ int main(void) {
|
||||
|
||||
token_id_t branch = rules.add_token(token_type_e::empty);
|
||||
token_id_t petal = rules.add_token(token_type_e::empty);
|
||||
token_id_t mark = rules.add_token(token_type_e::empty);
|
||||
token_id_t mark = rules.add_token(token_type_e::empty, 0, 1);
|
||||
|
||||
log::info << "Added tokens" << endl;
|
||||
|
||||
@ -52,7 +52,6 @@ int main(void) {
|
||||
|
||||
rules.add_branch_rule(branch, branch_grp);
|
||||
rules.add_branch_rule(petal, petal_grp);
|
||||
rules.add_mark_rule(mark, 1);
|
||||
|
||||
log::info << "Added rules" << endl;
|
||||
log::info << "Finished configuring ruleset" << endl;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user