Boost logo

Boost :

From: Дмитрий Архипов (grisumbras_at_[hidden])
Date: 2024-03-01 19:16:18


> > Much of the wealth of research into parser combinators wasn't incorporated
> > into this library. I didn't see in the documentation, for example, an easy
> > way to "map" one parser's attribute into another. This kind of thing should
> > be a basis operation provided by the library.
>
> Could you explain what you mean by this? This happens implicitly
> usually, and you can explicitly do it in semantic actions. Do you
> mean something else?

I actually wanted to ask for a similar thing, but then forgot about
it. Basically, sometimes you have to
create a rule simply because you want to convert the attribute from
type A to type B, and you use a
semantic action. Semantic actions result in parser's attribute
becoming none. But if instead semantic
action's result type would be the parser's attribute, then using an
action would become a mapping operation.
E.g.

(+bp::digit)[( [](auto& attr){ return std::stol(attr); } )]; //
mapping string -> long

If the library would also unwrap tuples in attributes, you could even
do things like

(double_ >> double_)[ std::plus<>() ]


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk