Commented out the current 'predicate feature' implementation.

This commit is contained in:
yhirose 2015-06-12 18:57:58 -04:00
parent 50768de875
commit b5eec078aa
3 changed files with 9 additions and 19 deletions

View File

@ -261,25 +261,7 @@ The following are available operators:
Predicate control Predicate control
----------------- -----------------
```c++ * TODO
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<long>() == 100;
};
long val;
auto ret = parser.parse("100", val);
assert(ret == true);
assert(val == 100);
ret = parser.parse("200", val);
assert(ret == false);
```
Adjust definitions Adjust definitions
------------------ ------------------

View File

@ -279,10 +279,12 @@ any call(F fn, Args&&... args) {
return any(fn(std::forward<Args>(args)...)); return any(fn(std::forward<Args>(args)...));
} }
#if 0
/* /*
* Predicate * Predicate
*/ */
typedef std::function<bool(const char* s, size_t n, const any& val, const any& dt)> Predicate; typedef std::function<bool(const char* s, size_t n, const any& val, const any& dt)> Predicate;
#endif
class Action class Action
{ {
@ -1233,7 +1235,9 @@ public:
std::string name; std::string name;
size_t id; size_t id;
#if 0
Predicate predicate; Predicate predicate;
#endif
std::vector<Action> actions; std::vector<Action> actions;
std::function<std::string ()> error_message; std::function<std::string ()> error_message;
bool ignoreSemanticValue; 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); val = reduce(chldsv, dt, action);
} }
#if 0
// Predicate check // Predicate check
if (success(len) && outer_->predicate && !outer_->predicate(anchors, anchorn, val, dt)) { if (success(len) && outer_->predicate && !outer_->predicate(anchors, anchorn, val, dt)) {
len = -1; len = -1;
} }
#endif
c.pop(); c.pop();
}); });

View File

@ -484,6 +484,7 @@ TEST_CASE("Calculator test with AST", "[general]")
REQUIRE(val == -3); REQUIRE(val == -3);
} }
#if 0
TEST_CASE("Predicate test", "[general]") TEST_CASE("Predicate test", "[general]")
{ {
peg parser("NUMBER <- [0-9]+"); peg parser("NUMBER <- [0-9]+");
@ -504,6 +505,7 @@ TEST_CASE("Predicate test", "[general]")
ret = parser.parse("200", val); ret = parser.parse("200", val);
REQUIRE(ret == false); REQUIRE(ret == false);
} }
#endif
TEST_CASE("Ignore semantic value test", "[general]") TEST_CASE("Ignore semantic value test", "[general]")
{ {