Closed akrzemi1 closed 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
.
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.defaulted[p]
always matches,p
matches, this is the final result (in terms of consumed input and the value of the attribute),p
doesn't match the final result is the default-constructed value of type beingp
's attribute type.So
defaulted[p]
parses the same asp | eps
except that we can derive the type of the attribute fromp
.