tzlaine / parser

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

parser.hpp requires print_parser declaration for custom parsers #178

Open vmauery opened 3 weeks ago

vmauery commented 3 weeks ago

When I tried adding a print_parser for my custom parser, ultimately I had to add it before including parser.hpp like this:

namespace boost::parser
{
template <typename T>
struct custom_parser;
namespace detail
{
template <typename Context, typename T>
void print_parser(Context const& context, custom_parser<T> const&,
                  std::ostream&, int components = 0);
} // namespace detail
} // namespace boost::parser

#include <boost/parser/parser.hpp>

And then I could define it later after my parser class. Also, I didn't see anything in the documentation about adding a parser_interface and only managed to find that by reading through other parsers in the parser.hpp file.

I think this could be avoided by adding a default noop print_parser (not sure what this is used for anyway). Or maybe being able to turn this feature off would be good.

template <typename Context>
void print_parser(Context const&, auto const&, std::ostream&, int component = 0)
{
}