Closed rockonedege closed 5 years ago
The tip in the docs need to be fixed. X3 does not support more than one attribute anymore in the parse function only. And I don't think we need to. We want to keep it simple. Just use a tie (tuple tie or fusion tie).
Yeah, that's what I thought.
It would be nice have an example for this use case in the tutorial.
My own experience is that new users tospirit
or ones with prior experience with qi
would find it useful.
here's what works for me in case it helps:
std::tuple<uint32_t, uint32_t, uint32_t> parse_message_prefix_revision(const std::string &s)
{
namespace x3 = boost::spirit::x3;
auto const uint_3_digits = x3::uint_parser<std::uint32_t, 10, 3, 3>{};
auto const uint_4_digits = x3::uint_parser<std::uint32_t, 10, 4, 4>{};
auto iter = s.cbegin();
auto end_iter = s.cend();
std::tuple<uint32_t, uint32_t, uint32_t> len_id_rev;
x3::parse(iter, end_iter,
uint_4_digits >> uint_4_digits >> uint_3_digits,
len_id_rev);
return len_id_rev;
}
BOOST_AUTO_TEST_CASE(test_parse_message_prefix_revision)
{
auto[len, mid, revision] = parse_message_prefix_revision("00200060001");
BOOST_TEST(20 == len);
BOOST_TEST(60 == mid);
BOOST_TEST(1 == revision);
}
It would be nice have an example for this use case in the tutorial.
Would you volunteer to provide this example? A PR will be appreciated.
Done. Please check PR #516
Thanks @rockonedege !
it looks x3::parse and x3::phrase_parse does not accept multiple attributes anymore as it does with qi.
The above citation from the doc(boost 1.70/spirit 3.04) does not hold true any more.