Re: fusion pair issue?
Patrick Welche <[email protected]>
| Newsgroups | gmane.comp.parsers.spirit.general |
|---|---|
| Message-ID | <20170401075407.GC274@quark> |
The euphoria has settled a bit: > bool ok = x3::parse(iter, end, > +( +x3::alnum >> ' ' >> +x3::alnum >> ';' ), > res.both); I had called parse() with res.both instead of res. The whole point of this was to hand over a struct capable of holding the parsed values without adding semantic actions. Then one can extended the struct to more complicated grammars. Attached is a working example, which then breaks when I apply: --- try.cpp.orig 2017-04-01 00:59:43.065447337 +0100 +++ try.cpp 2017-04-01 08:46:52.798091359 +0100 @@ -2,6 +2,7 @@ #include <map> +#include <boost/fusion/include/adapt_struct.hpp> #include <boost/fusion/include/std_pair.hpp> #include <boost/spirit/home/x3.hpp> @@ -20,7 +21,7 @@ result res; bool ok = x3::parse(iter, end, +( +x3::alnum >> ' ' >> +x3::alnum >> ';' ), - res.both); + res); if (!ok) std::cout << "Parsing failed\n"; else if (iter != end) Any more tips? Cheers, Patrick ------------------------------------------------------------------------------ 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
works.cpp
(text/plain, 823 B)
#define BOOST_SPIRIT_X3_DEBUG
#include <map>
#include <boost/fusion/include/adapt_struct.hpp>
#include <boost/fusion/include/std_pair.hpp>
#include <boost/spirit/home/x3.hpp>
namespace x3 = boost::spirit::x3;
struct result
{
std::map<std::string, std::string> both;
};
int main()
{
std::string buf("one two;three four;");
std::string::const_iterator iter = buf.begin();
std::string::const_iterator end = buf.end();
result res;
bool ok = x3::parse(iter, end,
+( +x3::alnum >> ' ' >> +x3::alnum >> ';' ),
res);
if (!ok)
std::cout << "Parsing failed\n";
else 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;
}
return 0;
}