diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2015-04-17 22:27:25 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2015-04-17 22:29:08 +0200 |
commit | 59db91599c0097b80a7ed61c6bb71e046f4d9f54 (patch) | |
tree | 82aaa98d7c6186b12d9a2cdb81ac615182d95072 | |
parent | 9624984557151e405d62f134e12270475d7ca7e7 (diff) | |
download | solar-59db91599c0097b80a7ed61c6bb71e046f4d9f54.tar solar-59db91599c0097b80a7ed61c6bb71e046f4d9f54.zip |
Move initial rule handling to grammer_t
-rw-r--r-- | src/grammar.hpp | 10 | ||||
-rw-r--r-- | src/parse.cpp | 8 | ||||
-rw-r--r-- | src/parse.y | 8 |
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); } |