tzlaine / parser

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

add directive `defaulted` #63

Closed akrzemi1 closed 5 months ago

akrzemi1 commented 5 months ago

Please, fee free to close this Issue if you consider it too extravagant.

The solution proposed in https://github.com/tzlaine/parser/issues/60 works fine, but seems inelegant to me, as this is the only place where I have to spell out my attribute type, it doesn't allow me to specify my intent directly, and it does not seem necessary at all. Hence this proposal.

Add directive defaulted with the following semantic.

So defaulted[p] parses the same as p | eps except that we can derive the type of the attribute from p.

tzlaine commented 5 months ago

I think this is too niche. I find it hard to see defaulted[p] as an improvement over p | bp::attr(foo). They seem very similar, but since attr already exists, I don't see the point of duplicating part of its functionality and calling it defaulted.