parse: introduce rhs_t typedef
This commit is contained in:
parent
42f74c83bf
commit
d91b60407c
2 changed files with 15 additions and 9 deletions
|
@ -1,6 +1,9 @@
|
|||
#include "parse.hpp"
|
||||
|
||||
|
||||
typedef std::pair<std::vector<solar::symbol_t>, std::vector<std::string>> rhs_t;
|
||||
|
||||
|
||||
static inline void free_string(std::string *v) {
|
||||
delete v;
|
||||
}
|
||||
|
@ -17,7 +20,7 @@ static inline void free_rule(solar::rule_t *v) {
|
|||
typedef union parse_symbol_value {
|
||||
parse_token_value_t token;
|
||||
std::string * symbol_action;
|
||||
std::pair<std::vector<solar::symbol_t>, std::vector<std::string>> * symbol_rhs;
|
||||
rhs_t * symbol_rhs;
|
||||
solar::rule_t * symbol_rule;
|
||||
solar::symbol_t * symbol_symbol;
|
||||
solar::symbol_t * symbol_term;
|
||||
|
@ -80,31 +83,31 @@ static inline void parse_reduce_9(solar::rule_t * rule, __attribute__((unused))
|
|||
grammar->rules.push_back(*rule);
|
||||
}
|
||||
|
||||
static inline solar::rule_t * parse_reduce_10(std::string * lhs, std::pair<std::vector<solar::symbol_t>, std::vector<std::string>> * rhs, std::string * action, __attribute__((unused)) solar::grammar_t * grammar) {
|
||||
static inline solar::rule_t * parse_reduce_10(std::string * lhs, rhs_t * rhs, std::string * action, __attribute__((unused)) solar::grammar_t * grammar) {
|
||||
auto *ret = new solar::rule_t {solar::item_t(*lhs, rhs->first), rhs->second, *action};
|
||||
delete rhs;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline std::pair<std::vector<solar::symbol_t>, std::vector<std::string>> * parse_reduce_11(__attribute__((unused)) solar::grammar_t * grammar) {
|
||||
return new std::pair<std::vector<solar::symbol_t>, std::vector<std::string>>();
|
||||
static inline rhs_t * parse_reduce_11(__attribute__((unused)) solar::grammar_t * grammar) {
|
||||
return new rhs_t();
|
||||
}
|
||||
|
||||
static inline std::pair<std::vector<solar::symbol_t>, std::vector<std::string>> * parse_reduce_12(std::pair<std::vector<solar::symbol_t>, std::vector<std::string>> * rhs, solar::symbol_t * sym, __attribute__((unused)) solar::grammar_t * grammar) {
|
||||
static inline rhs_t * parse_reduce_12(rhs_t * rhs, solar::symbol_t * sym, __attribute__((unused)) solar::grammar_t * grammar) {
|
||||
rhs->first.push_back(*sym);
|
||||
rhs->second.emplace_back();
|
||||
|
||||
return rhs;
|
||||
}
|
||||
|
||||
static inline std::pair<std::vector<solar::symbol_t>, std::vector<std::string>> * parse_reduce_13(std::pair<std::vector<solar::symbol_t>, std::vector<std::string>> * rhs, solar::symbol_t * sym, std::string * var, __attribute__((unused)) solar::grammar_t * grammar) {
|
||||
static inline rhs_t * parse_reduce_13(rhs_t * rhs, solar::symbol_t * sym, std::string * var, __attribute__((unused)) solar::grammar_t * grammar) {
|
||||
rhs->first.push_back(*sym);
|
||||
rhs->second.push_back(*var);
|
||||
|
||||
return rhs;
|
||||
}
|
||||
|
||||
static inline std::pair<std::vector<solar::symbol_t>, std::vector<std::string>> * parse_reduce_14(std::pair<std::vector<solar::symbol_t>, std::vector<std::string>> * rhs, std::string * str, __attribute__((unused)) solar::grammar_t * grammar) {
|
||||
static inline rhs_t * parse_reduce_14(rhs_t * rhs, std::string * str, __attribute__((unused)) solar::grammar_t * grammar) {
|
||||
for (char c : *str) {
|
||||
rhs->first.push_back(solar::symbol_t::make_char(c));
|
||||
rhs->second.emplace_back();
|
||||
|
|
|
@ -3,6 +3,9 @@
|
|||
}
|
||||
|
||||
%source {
|
||||
typedef std::pair<std::vector<solar::symbol_t>, std::vector<std::string>> rhs_t;
|
||||
|
||||
|
||||
static inline void free_string(std::string *v) {
|
||||
delete v;
|
||||
}
|
||||
|
@ -41,7 +44,7 @@ static inline void free_rule(solar::rule_t *v) {
|
|||
%type rule {solar::rule_t *}
|
||||
%destructor rule free_rule
|
||||
|
||||
%type rhs {std::pair<std::vector<solar::symbol_t>, std::vector<std::string>> *}
|
||||
%type rhs {rhs_t *}
|
||||
|
||||
%type action {std::string *}
|
||||
%destructor action free_string
|
||||
|
@ -105,7 +108,7 @@ rule |= SYMBOL_LC(lhs) "|=" rhs(rhs) action(action) {
|
|||
}
|
||||
|
||||
|
||||
rhs |= [new std::pair<std::vector<solar::symbol_t>, std::vector<std::string>>()]
|
||||
rhs |= [new rhs_t()]
|
||||
|
||||
rhs |= rhs(rhs) symbol(sym) {
|
||||
rhs->first.push_back(*sym);
|
||||
|
|
Reference in a new issue