mirror of
https://github.com/yhirose/cpp-peglib.git
synced 2024-12-22 11:55:30 +00:00
Commented out the current 'predicate feature' implementation.
This commit is contained in:
parent
50768de875
commit
b5eec078aa
20
README.md
20
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<long>() == 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
|
||||
------------------
|
||||
|
6
peglib.h
6
peglib.h
@ -279,10 +279,12 @@ any call(F fn, Args&&... args) {
|
||||
return any(fn(std::forward<Args>(args)...));
|
||||
}
|
||||
|
||||
#if 0
|
||||
/*
|
||||
* Predicate
|
||||
*/
|
||||
typedef std::function<bool(const char* s, size_t n, const any& val, const any& dt)> Predicate;
|
||||
#endif
|
||||
|
||||
class Action
|
||||
{
|
||||
@ -1233,7 +1235,9 @@ public:
|
||||
|
||||
std::string name;
|
||||
size_t id;
|
||||
#if 0
|
||||
Predicate predicate;
|
||||
#endif
|
||||
std::vector<Action> actions;
|
||||
std::function<std::string ()> 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();
|
||||
});
|
||||
|
@ -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]")
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user