Skip to content

Some mechanism is needed for yielding expectation failure in semantic action #75

@saki7

Description

@saki7

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:

  1. It defeats the purpose of expectation failure and essentially degrades your codebase into X3 era, where it suffered from C++ exception's overheads
  2. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions