From 4157c74ecedd37fba8ca2e3afa25814828af7dce Mon Sep 17 00:00:00 2001 From: Madeline Busig Date: Wed, 7 May 2025 00:07:17 -0700 Subject: [PATCH] Add function for finding token matches --- include/fractal.hpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/include/fractal.hpp b/include/fractal.hpp index fd6cdb8..3541799 100644 --- a/include/fractal.hpp +++ b/include/fractal.hpp @@ -243,6 +243,8 @@ public: size_t num_weighted_groups() const { return m_weighted_groups.size(); } size_t num_branch_rules() const { return m_branch_rules.size(); } + template + void find_token_matches(token_id_t token, CONTGROUP_T& out_groups, CONTWGROUP_T& out_wgroups) const; }; class generator_t { @@ -494,5 +496,18 @@ public: }; #endif +template +void ruleset_t::find_token_matches(token_id_t token, CONTGROUP_T& out_groups, CONTWGROUP_T& out_wgroups) const { + for (auto rule : m_branch_rules) { + if (rule.m_match == token) { + if (rule.m_weighted) { + out_wgroups.push_back(rule.m_group.weighted); + } else { + out_groups.push_back(rule.m_group.basic); + } + } + } +} + } // namespace fractal