summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/grammar.hpp10
-rw-r--r--src/parse.cpp8
-rw-r--r--src/parse.y8
3 files changed, 12 insertions, 14 deletions
diff --git a/src/grammar.hpp b/src/grammar.hpp
index b54b46d..cc982b6 100644
--- a/src/grammar.hpp
+++ b/src/grammar.hpp
@@ -47,6 +47,16 @@ struct grammar_t {
std::vector<std::pair<std::string, std::string>> extra_args;
+ void add_rule(const rule_t &rule) {
+ if (rules.empty()) {
+ item_t init("");
+ init.get_rhs().push_back(symbol_t::make_nonterm(rule.item.get_lhs()));
+ rules.emplace_back(solar::rule_t {std::move(init), std::vector<std::pair<std::string, bool>>(), std::string()});
+ }
+
+ rules.push_back(rule);
+ }
+
const std::string & get_nonterm_type(const std::string &sym) const {
static const std::string empty;
diff --git a/src/parse.cpp b/src/parse.cpp
index 9a24c03..bad9e24 100644
--- a/src/parse.cpp
+++ b/src/parse.cpp
@@ -80,13 +80,7 @@ static inline void parse_reduce_8(std::string *type, std::string *name, __attrib
}
static inline void parse_reduce_9(solar::rule_t *rule, __attribute__((unused)) solar::grammar_t *grammar) {
- if (grammar->rules.empty()) {
- solar::item_t init("");
- init.get_rhs().push_back(solar::symbol_t::make_nonterm(rule->item.get_lhs().c_str()));
- grammar->rules.emplace_back(solar::rule_t {std::move(init), vars_t(), std::string()});
- }
-
- grammar->rules.push_back(*rule);
+ grammar->add_rule(*rule);
}
static inline solar::rule_t * parse_reduce_10(std::string *lhs, rhs_t *rhs, std::string *action, __attribute__((unused)) solar::grammar_t *grammar) {return new solar::rule_t {solar::item_t(*lhs, rhs->first), rhs->second, *action};}
diff --git a/src/parse.y b/src/parse.y
index 56fc567..8d8a081 100644
--- a/src/parse.y
+++ b/src/parse.y
@@ -94,13 +94,7 @@ directive |= "%extra_arg" BLOCK(type) varname(name) {
}
directive |= rule(rule) {
- if (grammar->rules.empty()) {
- solar::item_t init("");
- init.get_rhs().push_back(solar::symbol_t::make_nonterm(rule->item.get_lhs().c_str()));
- grammar->rules.emplace_back(solar::rule_t {std::move(init), vars_t(), std::string()});
- }
-
- grammar->rules.push_back(*rule);
+ grammar->add_rule(*rule);
}