diff --git a/README.md b/README.md index bb171a7..db747f3 100644 --- a/README.md +++ b/README.md @@ -93,7 +93,6 @@ struct SemanticValue { // Utility method template T& get(); template const T& get() const; - std::string str() const; }; struct SemanticValues : protected std::vector @@ -102,16 +101,10 @@ struct SemanticValues : protected std::vector size_t n; // Token length size_t choice; // Choice number (0 based index) - using std::vector::size; - using std::vector::operator[]; - using std::vector::begin; - using std::vector::end; - // NOTE: There are more std::vector methods available... - // Transform the semantice values vector to another vector - template auto map(size_t beg, size_t end, F f) const -> vector::type>; - template auto map(F f) const -> vector::type>; - template auto map(size_t beg = 0, size_t end = -1) const -> vector; + template auto transform(size_t beg, size_t end, F f) const -> vector::type>; + template auto transform(F f) const -> vector::type>; + template auto transform(size_t beg = 0, size_t end = -1) const -> vector; } ``` diff --git a/peglib.h b/peglib.h index a03a220..0b83364 100644 --- a/peglib.h +++ b/peglib.h @@ -171,10 +171,6 @@ struct SemanticValue const T& get() const { return val.get(); } - - std::string str() const { - return std::string(s, n); - } }; struct SemanticValues : protected std::vector @@ -185,13 +181,6 @@ struct SemanticValues : protected std::vector SemanticValues() : s(nullptr), n(0), choice(0) {} - std::string str(size_t i = 0) const { - if (i > 0) { - return (*this)[i].str(); - } - return std::string(s, n); - } - typedef SemanticValue T; using std::vector::iterator; using std::vector::const_iterator; @@ -217,7 +206,7 @@ struct SemanticValues : protected std::vector using std::vector::emplace_back; template - auto map(F f) const -> vector::type> { + auto transform(F f) const -> vector::type> { vector::type> r; for (const auto& v: *this) { r.push_back(f(v)); @@ -226,7 +215,7 @@ struct SemanticValues : protected std::vector } template - auto map(size_t beg, size_t end, F f) const -> vector::type> { + auto transform(size_t beg, size_t end, F f) const -> vector::type> { vector::type> r; end = std::min(end, size()); for (size_t i = beg; i < end; i++) { @@ -236,8 +225,8 @@ struct SemanticValues : protected std::vector } template - auto map(size_t beg = 0, size_t end = -1) const -> vector { - return this->map(beg, end, [](const SemanticValue& v) { return v.get(); }); + auto transform(size_t beg = 0, size_t end = -1) const -> vector { + return this->transform(beg, end, [](const SemanticValue& v) { return v.get(); }); } }; @@ -469,11 +458,11 @@ struct Context std::vector cache_register; std::vector cache_success; - std::map, std::tuple> cache_result; - std::vector> stack; size_t stack_size; + std::map, std::tuple> cache_result; + Context(const char* _s, size_t _l, size_t _def_count, bool enablePackratParsing) : s(_s) , l(_l) @@ -2252,7 +2241,7 @@ private: std::shared_ptr ast = sv[0].get>(); return ast; } - return std::make_shared(info.name, info.tag, sv.map>()); + return std::make_shared(info.name, info.tag, sv.transform>()); }; } @@ -2271,7 +2260,7 @@ private: std::shared_ptr ast = sv[0].get>(); return ast; } - return std::make_shared(name.c_str(), AstDefaultTag, sv.map>()); + return std::make_shared(name.c_str(), AstDefaultTag, sv.transform>()); }; } }