diff --git a/README.md b/README.md index ece7c9f..64af037 100644 --- a/README.md +++ b/README.md @@ -261,25 +261,7 @@ The following are available operators: Predicate control ----------------- -```c++ -peg parser("NUMBER <- [0-9]+"); - -parser["NUMBER"] = [](const char* s, size_t n) { - return stol(string(s, n), nullptr, 10); -}; - -parser["NUMBER"].predicate = [](const char* s, size_t n, const any& val, const any& dt) { - return val.get() == 100; -}; - -long val; -auto ret = parser.parse("100", val); -assert(ret == true); -assert(val == 100); - -ret = parser.parse("200", val); -assert(ret == false); -``` + * TODO Adjust definitions ------------------ diff --git a/peglib.h b/peglib.h index 90a0760..107e4e2 100644 --- a/peglib.h +++ b/peglib.h @@ -279,10 +279,12 @@ any call(F fn, Args&&... args) { return any(fn(std::forward(args)...)); } +#if 0 /* * Predicate */ typedef std::function Predicate; +#endif class Action { @@ -1233,7 +1235,9 @@ public: std::string name; size_t id; +#if 0 Predicate predicate; +#endif std::vector actions; std::function error_message; bool ignoreSemanticValue; @@ -1300,10 +1304,12 @@ inline size_t Holder::parse(const char* s, size_t n, SemanticValues& sv, Context val = reduce(chldsv, dt, action); } +#if 0 // Predicate check if (success(len) && outer_->predicate && !outer_->predicate(anchors, anchorn, val, dt)) { len = -1; } +#endif c.pop(); }); diff --git a/test/test.cc b/test/test.cc index 0442f43..1c58e25 100644 --- a/test/test.cc +++ b/test/test.cc @@ -484,6 +484,7 @@ TEST_CASE("Calculator test with AST", "[general]") REQUIRE(val == -3); } +#if 0 TEST_CASE("Predicate test", "[general]") { peg parser("NUMBER <- [0-9]+"); @@ -504,6 +505,7 @@ TEST_CASE("Predicate test", "[general]") ret = parser.parse("200", val); REQUIRE(ret == false); } +#endif TEST_CASE("Ignore semantic value test", "[general]") {