diff --git a/CMakeLists.txt b/CMakeLists.txt index ec342e3..e5f63bb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,43 +22,20 @@ endif() set(CMAKE_CXX_EXTENSIONS OFF) -if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" - OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") - set(warning_options -Weverything - -Wno-c++98-compat - -Wno-padded - -Wno-c++98-compat-pedantic - -Wno-exit-time-destructors - -Wno-missing-prototypes - -Wno-weak-vtables - -Wno-global-constructors - -Wno-format-nonliteral - -Wno-switch-enum - -Wno-missing-noreturn - -Wno-covered-switch-default - -Wno-c++2a-compat - ) +if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Weverything -Wno-c++98-compat -Wno-padded -Wno-weak-vtables -Wno-exit-time-destructors -Wno-c++2a-compat") elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - set(warning_options -Wall -Wpedantic -Wextra) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wpedantic -Wextra") elseif(MSVC) - set(warning_options /W4 /wd4503 /wd4512) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4 /wd4503 /wd4512 /utf-8") endif() if(CMAKE_SYSTEM_NAME STREQUAL "Linux") set(add_link_deps pthread) endif() -if(MSVC) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /utf-8") -endif() - enable_testing() add_subdirectory(test) add_subdirectory(example) add_subdirectory(lint) - -# find_package(LLVM CONFIG) -# if(LLVM_FOUND) -# add_subdirectory(pl0) -# endif() diff --git a/peglib.h b/peglib.h index ea29db4..739eac9 100644 --- a/peglib.h +++ b/peglib.h @@ -1026,20 +1026,20 @@ public: i += len; } if (!chldsv.empty()) { - for (size_t i = 0; i < chldsv.size(); i++) { - sv.emplace_back(std::move(chldsv[i])); + for (size_t j = 0; j < chldsv.size(); j++) { + sv.emplace_back(std::move(chldsv[j])); } } if (!chldsv.tags.empty()) { - for (size_t i = 0; i < chldsv.tags.size(); i++) { - sv.tags.emplace_back(std::move(chldsv.tags[i])); + for (size_t j = 0; j < chldsv.tags.size(); j++) { + sv.tags.emplace_back(std::move(chldsv.tags[j])); } } sv.s_ = chldsv.c_str(); sv.n_ = chldsv.length(); if (!chldsv.tokens.empty()) { - for (size_t i = 0; i < chldsv.tokens.size(); i++) { - sv.tokens.emplace_back(std::move(chldsv.tokens[i])); + for (size_t j = 0; j < chldsv.tokens.size(); j++) { + sv.tokens.emplace_back(std::move(chldsv.tokens[j])); } } return i; @@ -1239,8 +1239,8 @@ class AndPredicate : public Ope { public: AndPredicate(const std::shared_ptr &ope) : ope_(ope) {} - size_t parse_core(const char *s, size_t n, SemanticValues &sv, Context &c, - any &dt) const override { + size_t parse_core(const char *s, size_t n, SemanticValues & /*sv*/, + Context &c, any &dt) const override { auto &chldsv = c.push(); c.push_capture_scope(); auto se = make_scope_exit([&]() { @@ -1265,8 +1265,8 @@ class NotPredicate : public Ope { public: NotPredicate(const std::shared_ptr &ope) : ope_(ope) {} - size_t parse_core(const char *s, size_t n, SemanticValues &sv, Context &c, - any &dt) const override { + size_t parse_core(const char *s, size_t n, SemanticValues & /*sv*/, + Context &c, any &dt) const override { auto save_error_pos = c.error_pos; auto &chldsv = c.push(); c.push_capture_scope(); @@ -1347,8 +1347,8 @@ public: assert(!ranges_.empty()); } - size_t parse_core(const char *s, size_t n, SemanticValues &sv, Context &c, - any &dt) const override { + size_t parse_core(const char *s, size_t n, SemanticValues & /*sv*/, + Context &c, any & /*dt*/) const override { if (n < 1) { c.set_error_pos(s); return static_cast(-1); @@ -1386,8 +1386,8 @@ class Character : public Ope, public std::enable_shared_from_this { public: Character(char ch) : ch_(ch) {} - size_t parse_core(const char *s, size_t n, SemanticValues &sv, Context &c, - any &dt) const override { + size_t parse_core(const char *s, size_t n, SemanticValues & /*sv*/, + Context &c, any & /*dt*/) const override { if (n < 1 || s[0] != ch_) { c.set_error_pos(s); return static_cast(-1); @@ -1403,8 +1403,8 @@ public: class AnyCharacter : public Ope, public std::enable_shared_from_this { public: - size_t parse_core(const char *s, size_t n, SemanticValues &sv, Context &c, - any &dt) const override { + size_t parse_core(const char *s, size_t n, SemanticValues & /*sv*/, + Context &c, any & /*dt*/) const override { auto len = codepoint_length(s, n); if (len < 1) { c.set_error_pos(s); @@ -1471,8 +1471,8 @@ class Ignore : public Ope { public: Ignore(const std::shared_ptr &ope) : ope_(ope) {} - size_t parse_core(const char *s, size_t n, SemanticValues &sv, Context &c, - any &dt) const override { + size_t parse_core(const char *s, size_t n, SemanticValues & /*sv*/, + Context &c, any &dt) const override { const auto &rule = *ope_; auto &chldsv = c.push(); auto se = make_scope_exit([&]() { c.pop(); }); @@ -1491,8 +1491,8 @@ typedef std::functionaccept(*this); done_ = false; } - void visit(Dictionary &ope) override { done_ = true; } + void visit(Dictionary & /*ope*/) override { done_ = true; } void visit(LiteralString &ope) override { done_ = !ope.lit_.empty(); } void visit(CharacterClass & /*ope*/) override { done_ = true; } void visit(Character & /*ope*/) override { done_ = true; } @@ -2357,8 +2361,8 @@ public: } std::string name; - const char *s = nullptr; - ; + const char *s_ = nullptr; + size_t id = 0; Action action; std::function enter; @@ -2503,8 +2507,8 @@ inline size_t Ope::parse(const char *s, size_t n, SemanticValues &sv, } inline size_t Dictionary::parse_core(const char *s, size_t n, - SemanticValues &sv, Context &c, - any &dt) const { + SemanticValues & /*sv*/, Context &c, + any & /*dt*/) const { auto len = trie_.match(s, n); if (len > 0) { return len; } c.set_error_pos(s); @@ -2660,7 +2664,8 @@ inline size_t BackReference::parse_core(const char *s, size_t n, any &dt) const { auto size = static_cast(c.capture_scope_stack_size); for (auto i = size - 1; i >= 0; i--) { - const auto &cs = c.capture_scope_stack[i]; + auto index = static_cast(i); + const auto &cs = c.capture_scope_stack[index]; if (cs.find(name_) != cs.end()) { const auto &lit = cs.at(name_); auto init_is_word = false; @@ -2695,12 +2700,12 @@ inline size_t PrecedenceClimbing::parse_expression(const char *s, size_t n, auto &rule = get_reference_for_binop(c); auto action = rule.action; - rule.action = [&](SemanticValues &sv, any &dt) -> any { - tok = sv.token(); + rule.action = [&](SemanticValues &sv2, any &dt2) -> any { + tok = sv2.token(); if (action) { - return action(sv, dt); - } else if (!sv.empty()) { - return sv[0]; + return action(sv2, dt2); + } else if (!sv2.empty()) { + return sv2[0]; } return any(); }; @@ -3124,7 +3129,7 @@ private: auto &rule = grammar[name]; rule <= ope; rule.name = name; - rule.s = sv.c_str(); + rule.s_ = sv.c_str(); rule.ignoreSemanticValue = ignore; rule.is_macro = is_macro; rule.params = params; @@ -3360,7 +3365,7 @@ private: if (atom_name != atom1_name || atom_name == binop_name) { if (log) { - auto line = line_info(s, rule.s); + auto line = line_info(s, rule.s_); log(line.first, line.second, "'precedence' instruction cannt be applied to '" + rule.name + "'."); @@ -3372,7 +3377,7 @@ private: rule.disable_action = true; } catch (...) { if (log) { - auto line = line_info(s, rule.s); + auto line = line_info(s, rule.s_); log(line.first, line.second, "'precedence' instruction cannt be applied to '" + rule.name + "'.");