parsing into private fields
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 30/100
Research direction
No source file or test is named. Start with the bp::parse and rule example, then investigate how Spirit.X3 handles attributes and compare the proposed friend-helper and Boost.Describe approaches. Done means an agreed mechanism for parsing into private fields, with its scope and validation covered by tests or documentation.
Written by the indexing model from the issue text.
Description
Currently my biggest gripe with Spirit.X3 is that you can't parse into a class with private fields. This leaves you with two options:
- use a proxy type, e.g.
class Myclass_impl {
public:
char c;
};
class Myclass : private Myclass_impl {
public:
Myclass_impl &base() { return *this; }
};
bp::rule<struct tag, Myclass_impl> rule{"rule"};
const auto rule_def = bp::char_;
BOOST_PARSER_DEFINE_RULES(rule);
void func() {
std::string str{"c"};
Myclass result;
bp::parse(str, rule, result.base());
}
- Just don't use private members, which means your parser is no longer a parser, just a validator.
1. makes public headers unreadable as users would have to look into implementation headers to see the actual class body, while
2. violates the parse, don't validate principle and thus allows for invalidly constructed objects that would never be returned from a successful parse.
Are there any plans to remedy this, e.g. via a Boost.Parser helper class that the user class could befriend, or via a specialization that grants access to the private members (Boost.Describe comes to mind) ?
Or am I just missing a workaround that everyone has been using for the past decade
- Dominant language
- C++
- Stars
- 182
- Forks
- 28
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from boostorg/parser
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Difficulty 1/5 Under an hour Newbie friendliness 82/100
-
Difficulty 1/5 Under an hour Newbie friendliness 20/100
-
Difficulty 3/5 1-2 days Newbie friendliness 55/100
-
Difficulty 3/5 1-2 days Newbie friendliness 48/100
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
AXERA-TECH/ax-llm#77 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
games-on-whales/wolf#509 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
bug-unconfirmed
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
NVIDIA/cuda-samples#453 ·