summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2015-04-11 03:02:29 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2015-04-11 03:02:29 +0200
commitd91b60407ce812de60f0700ffc15712cb9a05d15 (patch)
tree107944cfcb4259cebeb2e9934fdd1caf9ded192e /src
parent42f74c83bf53d60d25408e6afb8aa92ca23e0a16 (diff)
downloadsolar-d91b60407ce812de60f0700ffc15712cb9a05d15.tar
solar-d91b60407ce812de60f0700ffc15712cb9a05d15.zip
parse: introduce rhs_t typedef
Diffstat (limited to 'src')
-rw-r--r--src/parse.cpp17
-rw-r--r--src/parse.y7
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<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();
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<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);