Move initial rule handling to grammer_t
This commit is contained in:
parent
9624984557
commit
59db91599c
3 changed files with 12 additions and 14 deletions
|
@ -47,6 +47,16 @@ struct grammar_t {
|
||||||
std::vector<std::pair<std::string, std::string>> extra_args;
|
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 {
|
const std::string & get_nonterm_type(const std::string &sym) const {
|
||||||
static const std::string empty;
|
static const std::string empty;
|
||||||
|
|
||||||
|
|
|
@ -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) {
|
static inline void parse_reduce_9(solar::rule_t *rule, __attribute__((unused)) solar::grammar_t *grammar) {
|
||||||
if (grammar->rules.empty()) {
|
grammar->add_rule(*rule);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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};}
|
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};}
|
||||||
|
|
|
@ -94,13 +94,7 @@ directive |= "%extra_arg" BLOCK(type) varname(name) {
|
||||||
}
|
}
|
||||||
|
|
||||||
directive |= rule(rule) {
|
directive |= rule(rule) {
|
||||||
if (grammar->rules.empty()) {
|
grammar->add_rule(*rule);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Reference in a new issue