From d91b60407ce812de60f0700ffc15712cb9a05d15 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sat, 11 Apr 2015 03:02:29 +0200 Subject: parse: introduce rhs_t typedef --- src/parse.cpp | 17 ++++++++++------- src/parse.y | 7 +++++-- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/parse.cpp b/src/parse.cpp index 35b6f8f..4f2aece 100644 --- a/src/parse.cpp +++ b/src/parse.cpp @@ -1,6 +1,9 @@ #include "parse.hpp" +typedef std::pair, std::vector> 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> * 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> * 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> * parse_reduce_11(__attribute__((unused)) solar::grammar_t * grammar) { - return new std::pair, std::vector>(); +static inline rhs_t * parse_reduce_11(__attribute__((unused)) solar::grammar_t * grammar) { + return new rhs_t(); } -static inline std::pair, std::vector> * parse_reduce_12(std::pair, std::vector> * 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> * parse_reduce_13(std::pair, std::vector> * 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> * parse_reduce_14(std::pair, std::vector> * 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(); diff --git a/src/parse.y b/src/parse.y index dba747e..274e374 100644 --- a/src/parse.y +++ b/src/parse.y @@ -3,6 +3,9 @@ } %source { +typedef std::pair, std::vector> 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> *} +%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>()] +rhs |= [new rhs_t()] rhs |= rhs(rhs) symbol(sym) { rhs->first.push_back(*sym); -- cgit v1.2.3