I also open the same question on stackoverflow. For better formatting of
code, please refer to
https://stackoverflow.com/questions/58353782/attributes-of-sequence-and-list...
https://stackoverflow.com/questions/58353782/attributes-of-sequence-and-list...
I want to parse something like
"{xxxx}
{xxxx}"
which is separated by eol into a *vector> *:
({xxxx},{xxxx}) so that "{" and "}" stays with internal characters together.
Note there are only two elements on the outer vector. My code is:
#define BOOST_SPIRIT_UNICODE
#include <iostream>
#include
#include<string>
#include<vector>
using namespace std;
namespace sw=boost::spirit::standard_wide;
namespace qi= boost::spirit::qi;
using boost::spirit::standard_wide::char_;
int main()
{
wstring s =
L"{\"id\":23,\"text\":\"sf\nsf\"}\n{\"id\":23,\"text\":\"sfsf\"}";
qi::rule>(),
sw::blank_type> ru;
ru = (qi::char_(L"{") >> *(char_-char_(L"}")) >> char_(L"}")) % qi::eol;
vector> result;
qi::phrase_parse(s.begin(), s.end(), ru, sw::blank, result);
for (auto& v : result) {
//cout << "Size of string: " << v.size() << endl;
for (auto& s : v) {
wcout << s;
};
cout << endl;
};
std::cout << "Size of result"< for the outer vector.
Then consider the rule:
*ru = (qi::char_(L"{") >> *(char_-char_(L"}")) >> char_(L"}")) % qi::eol;*
According to the documentation, *(char_-char_(L"}")) should be vector . And
because *a: A, b: vector --> (a >> b): vector *, then I think that
*(qi::char_(L"{") >> *(char_-char_(L"}")) >> char_(L"}"))* should be
*vector*. This is contracdicted to the result.
Where I'm wrong?
--
Sent from: http://boost.2283326.n4.nabble.com/Boost-Users-f2553780.html