On Fri, Feb 12, 2010 at 5:01 PM, Matthias Vallentin
On Fri, Feb 12, 2010 at 08:57:53AM +0000, Brian O'Kennedy wrote:
The first argument to qi::parse is a non-const reference (which fails on the temporary you're passing in).
That makes sense (and fixed it).
Try:
std::string::iterator ii = str.begin(); boost::spirit::qi::parse(ii, str.end(), raw[+~string(delim)] % lit(delim), result);
This grammar definition does not work for me, I get an assertion failing with: subject_is_not_negatable, which makes sense as the complement of string is not really defined.
Ah, because string was not what I originally put, I put char_, someone
else changed that to string and I just copy/pasted what they put. You
want char_ there, not string.
On Fri, Feb 12, 2010 at 5:01 PM, Matthias Vallentin
When we parse into std::vectorstd::string, this seems to be a straight-forward solution:
using namespace boost::spirit::qi; using namespace boost::spirit::karma;
std::string str("foo---bar---baz"); std::string delim("---"); std::vectorstd::string result;
std::string::iterator i = str.begin(); parse(i, str.end(), +alpha % lit(delim), result);
std::cout << format(stream % ", ", result) << std::endl;
How do we have to modify the above when result is of type std::string? The example below merely puts "fbb" in the result string:
std::string::iterator i = str.begin(); parse(i, str.end(), raw[+alpha] % lit(delim), result);
According to attribute composition rules, I would assume the grammar attribute is equivalent to vector
. How does qi::parse determine which function to use for the result? Is it merely using push_back, and hence only the first character is appended?
Do note, using alpha (instead of my original solution) will cause it
to fail with non a-zA-Z characters. If you want to support any type
of string (ala how the tokanizer works), you should use my original
solution.
On Fri, Feb 12, 2010 at 5:01 PM, Matthias Vallentin
Spirit uses the first parameter to return how far it got in the parsing of your string.
Why is a const_iterator insufficient? Shouldn't it also work to report the position of the parser?
const_iterator is sufficient, it never changes the values, just that with this: std::string::iterator ii = str.begin(); boost::spirit::qi::parse(ii, str.end(), raw[+~char_(delim)] % lit(delim), result); The entire string was consumed if ii==str.end(), if they do not equal then it hit something it cannot parse (which will not happen with my above given grammar).