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] >> ']' >>
bp::repeat(std::ref(size))[bp::char_];

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:
bp::repeat(std::ref(size))[bp::char_]
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.

Regards,
Mohammad Nejati


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