mirror of
https://github.com/yhirose/cpp-peglib.git
synced 2024-12-22 20:05:31 +00:00
Changed to allow 'mutable' lambda function as semantic action. Closed #2.
This commit is contained in:
parent
6cc1534257
commit
f7e7e308ed
30
peglib.h
30
peglib.h
@ -284,6 +284,11 @@ private:
|
|||||||
return TypeAdaptor<R>(fn);
|
return TypeAdaptor<R>(fn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename F, typename R>
|
||||||
|
Fty make_adaptor(F fn, R (F::*mf)(const char*, size_t, const std::vector<any>& v, any& c)) {
|
||||||
|
return TypeAdaptor<R>(fn);
|
||||||
|
}
|
||||||
|
|
||||||
template<typename F, typename R>
|
template<typename F, typename R>
|
||||||
Fty make_adaptor(F fn, R(*mf)(const char*, size_t, const std::vector<any>& v, any& c)) {
|
Fty make_adaptor(F fn, R(*mf)(const char*, size_t, const std::vector<any>& v, any& c)) {
|
||||||
return TypeAdaptor<R>(fn);
|
return TypeAdaptor<R>(fn);
|
||||||
@ -294,6 +299,11 @@ private:
|
|||||||
return TypeAdaptor_s_l_v<R>(fn);
|
return TypeAdaptor_s_l_v<R>(fn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename F, typename R>
|
||||||
|
Fty make_adaptor(F fn, R (F::*mf)(const char*, size_t, const std::vector<any>& v)) {
|
||||||
|
return TypeAdaptor_s_l_v<R>(fn);
|
||||||
|
}
|
||||||
|
|
||||||
template<typename F, typename R>
|
template<typename F, typename R>
|
||||||
Fty make_adaptor(F fn, R(*mf)(const char*, size_t, const std::vector<any>& v)) {
|
Fty make_adaptor(F fn, R(*mf)(const char*, size_t, const std::vector<any>& v)) {
|
||||||
return TypeAdaptor_s_l_v<R>(fn);
|
return TypeAdaptor_s_l_v<R>(fn);
|
||||||
@ -304,6 +314,11 @@ private:
|
|||||||
return TypeAdaptor_s_l<R>(fn);
|
return TypeAdaptor_s_l<R>(fn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename F, typename R>
|
||||||
|
Fty make_adaptor(F fn, R (F::*mf)(const char*, size_t)) {
|
||||||
|
return TypeAdaptor_s_l<R>(fn);
|
||||||
|
}
|
||||||
|
|
||||||
template<typename F, typename R>
|
template<typename F, typename R>
|
||||||
Fty make_adaptor(F fn, R (*mf)(const char*, size_t)) {
|
Fty make_adaptor(F fn, R (*mf)(const char*, size_t)) {
|
||||||
return TypeAdaptor_s_l<R>(fn);
|
return TypeAdaptor_s_l<R>(fn);
|
||||||
@ -314,6 +329,11 @@ private:
|
|||||||
return TypeAdaptor_v_n<R>(fn);
|
return TypeAdaptor_v_n<R>(fn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename F, typename R>
|
||||||
|
Fty make_adaptor(F fn, R (F::*mf)(const std::vector<any>& v, any& c)) {
|
||||||
|
return TypeAdaptor_v_n<R>(fn);
|
||||||
|
}
|
||||||
|
|
||||||
template<typename F, typename R>
|
template<typename F, typename R>
|
||||||
Fty make_adaptor(F fn, R (*mf)(const std::vector<any>& v, any& c)) {
|
Fty make_adaptor(F fn, R (*mf)(const std::vector<any>& v, any& c)) {
|
||||||
return TypeAdaptor_v_n<R>(fn);
|
return TypeAdaptor_v_n<R>(fn);
|
||||||
@ -324,6 +344,11 @@ private:
|
|||||||
return TypeAdaptor_v<R>(fn);
|
return TypeAdaptor_v<R>(fn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename F, typename R>
|
||||||
|
Fty make_adaptor(F fn, R (F::*mf)(const std::vector<any>& v)) {
|
||||||
|
return TypeAdaptor_v<R>(fn);
|
||||||
|
}
|
||||||
|
|
||||||
template<typename F, typename R>
|
template<typename F, typename R>
|
||||||
Fty make_adaptor(F fn, R (*mf)(const std::vector<any>& v)) {
|
Fty make_adaptor(F fn, R (*mf)(const std::vector<any>& v)) {
|
||||||
return TypeAdaptor_v<R>(fn);
|
return TypeAdaptor_v<R>(fn);
|
||||||
@ -334,6 +359,11 @@ private:
|
|||||||
return TypeAdaptor_empty<R>(fn);
|
return TypeAdaptor_empty<R>(fn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename F, typename R>
|
||||||
|
Fty make_adaptor(F fn, R (F::*mf)()) {
|
||||||
|
return TypeAdaptor_empty<R>(fn);
|
||||||
|
}
|
||||||
|
|
||||||
template<typename F, typename R>
|
template<typename F, typename R>
|
||||||
Fty make_adaptor(F fn, R (*mf)()) {
|
Fty make_adaptor(F fn, R (*mf)()) {
|
||||||
return TypeAdaptor_empty<R>(fn);
|
return TypeAdaptor_empty<R>(fn);
|
||||||
|
12
test/test.cc
12
test/test.cc
@ -183,6 +183,18 @@ TEST_CASE("Backtracking test", "[general]")
|
|||||||
REQUIRE(count == 2);
|
REQUIRE(count == 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE("mutable lambda test", "[general]")
|
||||||
|
{
|
||||||
|
vector<string> vec;
|
||||||
|
|
||||||
|
peg pg("ROOT <- 'mutable lambda test'");
|
||||||
|
|
||||||
|
// This test makes sure if the following code can be compiled.
|
||||||
|
pg["TOKEN"] = [=](const char* s, size_t l) mutable {
|
||||||
|
vec.push_back(string(s, l));
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
TEST_CASE("Simple calculator test", "[general]")
|
TEST_CASE("Simple calculator test", "[general]")
|
||||||
{
|
{
|
||||||
auto syntax =
|
auto syntax =
|
||||||
|
Loading…
Reference in New Issue
Block a user