Boost logo

Boost :

From: Mohammad Nejati [ashtum] (ashtumashtum_at_[hidden])
Date: 2024-02-29 20:12:55

Hi everyone,

I have two questions about the following code, which attempts to parse
length-prefixed strings using the proposed Boost.Parser:

std::string input = "[5]HELLO[5]WORLD";

unsigned int size = 0;
auto action = [&size](auto & ctx) { size = bp::_attr(ctx); };

auto lps_parser = '[' >> bp::uint_[action] >> ']' >>

auto result = bp::parse(input, *lps_parser);

1. Is it possible to eliminate the need for the action and size
variable by using some kind of placeholder in bp::repeat that utilizes
the attribute of the first parser?

2. How can we make this part of the parser more efficient:
The current implementation seems to loop and execute bp::char_ parser
on each character, while all it needs to do is chunk a portion of the
input string.

Mohammad Nejati

Boost list run by bdawes at, gregod at, cpdaniel at, john at