Currently, the only way to yield expectation failure is from normal parsers:
constexpr auto p = a > b;
constexpr auto p = a >> x4::expect[b];
We need some facility to yield expectation failure in semantic action:
// proposed syntax
constexpr auto p = a >> b[([](auto&& ctx) {
return x4::unexpected("error message");
})];
The current workaround is to just throw C++ exception:
constexpr auto p = a >> b[([](auto&& ctx) {
throw std::runtime_error("error message");
})];
However this workaround has serious downsides:
- It defeats the purpose of expectation failure and essentially degrades your codebase into X3 era, where it suffered from C++ exception's overheads
- It yields "unreachable code" warning on compilers because all of the X4's internal code which comes after the
x4::action handling is correctly analyzed as "unreachable code" on very well optimized compilers
Currently, the only way to yield expectation failure is from normal parsers:
We need some facility to yield expectation failure in semantic action:
The current workaround is to just throw C++ exception:
However this workaround has serious downsides:
x4::actionhandling is correctly analyzed as "unreachable code" on very well optimized compilers