tzlaine / parser

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

Type trait for parser's attribure #66

Closed akrzemi1 closed 8 months ago

akrzemi1 commented 8 months ago

Docs section Terminology has: "Since it is not possible to write a type trait that returns the attribute type of a parser, we need notation for concisely communicating". But it isnot at all clear why that would be impossible.

akrzemi1 commented 8 months ago

A sample definition:

template <typename Parser>
using attribute_type = decltype(boost::parser::parse(std::string_view{}, std::declval<Parser>()))::value_type;
tzlaine commented 8 months ago

char_'s attribute type depends on the input. So that definition is correct as long as the input is always a sequence of char. But it's possibly (but not always, depending on the exact combination of parsers) wrong if the input is a sequence of char32_t.

See the rationale section for why I think char_ polymorphism is an important feature.

However, it's really easy to interrogate this yourself at the point of use: decltype(bp::parser(str, p).