boostorg / parser

A C++ parser combinator library.
Boost Software License 1.0
87 stars 12 forks source link

Single parser error handler #180

Closed asolwa closed 3 weeks ago

asolwa commented 3 months ago

When a single, primitive parser is used, the error stream remains empty, even if an error occurs. In the example below, 'oss' is empty, but it should have an error message, shouldn't it?

#include <boost/parser/parser.hpp>

int main()
{
    using namespace boost::parser;

    constexpr auto parser = string("test");
    {
        char const * str = "abz";
        std::ostringstream oss;
        stream_error_handler eh("simple_parser.cpp", oss);
        auto result = parse(str, with_error_handler(parser, eh));
        std::cout << oss.str();
    }
}
tzlaine commented 3 weeks ago

The only time that error handler should have anything in it is when: 1) you, the user, put something in there via a semantic action; or 2) you, the user, indicate where hard errors occur ("expectation points"), and then one of those expectation points is violated. See the "Error Handling and Debugging" page of the docs, in particular the section "How diagnostics are generated".

The fact that its a primitive parser is a red herring, btw. The same thing will happen with any parser that does not do 1) or 2).