Closed rkaminsk closed 1 year ago
Can you clarify what your problem is?
I would expect the following example to compile without giving the unused overload.
#include <stdexcept>
#include <iostream>
#include <lexy/callback.hpp>
#include <lexy/dsl.hpp>
#include <lexy/action/parse.hpp>
#include <lexy/input/string_input.hpp>
namespace grammar {
struct example_prod {
static constexpr auto rule = LEXY_LIT("x");
static constexpr auto value = lexy::callback_with_state<void>(
[]() {
throw std::runtime_error("never called but required");
},
[](int &state) {
state += 1;
}
);
};
}
int main() {
auto in = lexy::zstring_input("xx");
int state = 10;
auto res = lexy::parse<grammar::example_prod>(in, state, lexy::noop);
std::cout << "value: " << state << std::endl;
}
Fixed.
The helper
lexy::callback_with_state
fails to compile if not both a version with and without state for each possible overload is given. As a quick hack, I applied the patch below to get things to compile. Not sure how ho fix this properly.