Re: fusion pair issue?
Seth <[email protected]>
| Newsgroups | gmane.comp.parsers.spirit.general |
|---|---|
| Message-ID | <[email protected]> |
On 01-04-17 09:54, Patrick Welche wrote:
>
> Any more tips?
No real difference. Indeed I had been reshaping the problem in several
ways to match the conventions that jell with X3.
If you must, you will have to do some type "hinting" work. I love hiding
the cruft in small factory lambdas like this:
http://coliru.stacked-crooked.com/a/416a5b7061721b2d :
using Map = std::map<std::string, std::string>;
struct result {
Map both;
};
BOOST_FUSION_ADAPT_STRUCT(result, both)
int main()
{
std::string const buf("one two;three four;");
auto iter = buf.begin(), end = buf.end();
auto parser = []{
using namespace boost::spirit::x3;
auto string_ = lexeme [ +(graph - ';') ];
auto map_ = -(string_ >> string_) % ';';
return rule<struct _, Map> {"parser"} = skip(space) [ map_ ];
};
result res;
bool ok = parse(iter, end, parser(), res);
if (ok) {
std::cout << "Parse success\n";
}
else {
std::cout << "Parsing failed\n";
}
if (iter != end) {
std::cout << "Bit left over at the end: " <<
std::string(iter, end) << std::endl;
}
else {
for (auto p : res.both) {
std::cout << "found: " << p.first << ' ' << p.second <<
std::endl;
}
}
}
Which prints
<parser>
<try>one two;three four;</try>
<success></success>
<attributes>[[[[o, n, e], [t, w, o]], [[t, h, r, e, e], [f, o, u,
r]]]]</attributes>
</parser>
Parse success
found: one two
found: three four
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Spirit-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/spirit-general