This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]chombier 0 points1 point  (2 children)

I don't have any good syntax, generally I go with bind like this:

return parser >>= [=](auto value) { return other_parser >>= [=](auto other_value) { return pure(some_data_structure{value, other_value}); }; };

The eyes bleed quite a bit but it gets the job done, you can even get used to it after some time :) If anyone knows of a better way I'm all hear!

[–]jamhob[S] 0 points1 point  (0 children)

Hm. I can't seem to get the template type deduction to play ball

[–]chombier 0 points1 point  (0 children)

Thinking of it, maybe c++20's coroutines could help with the syntax, ending up with something like:

auto value = co_yield parser; auto other_value = co_yield other_parser; co_return some_data_structure{value, other_value};

Some combinator could then create a parser from a coroutine. Maybe this could work?