On Oct 1, 7:35 pm, OvermindDL1 <overmind...@gmail.com> wrote:
On Fri, Oct 1, 2010 at 2:34 PM, alfC <alfredo.cor...@gmail.com> wrote:
can anybody explain to me why this example from the Spirit.Qi manual works
http://www.boost.org/doc/libs/1_44_0/libs/spirit/example/qi/complex_n...
and when I try to use the string iterators directly I get a horrific compiler error? Something to do with string iterators being pointers or something?
std::string s = "(2, 3)"; // < line added to example bool r = phrase_parse(s.begin(), s.end(), //< only line changed in the example was (first, last)
You are using GCC, phrase_parse's first parameter must be non-const.
right in the spot. Thank you. That worked. I have another question in general on Spirit.Qi. I read the manual many times and I still can't figure out how to read 'words' from the parser. In the following example I want to parse the name of something but I can not use the semantic assignment on std::string. ? The pattern is matched if I disable the assignment line but it doesn't compile with the line "[ref(name) = _1]". Again this is boost 1.43 with gcc 4.4. #include <boost/spirit/include/qi.hpp> #include <boost/spirit/include/phoenix_core.hpp> #include <boost/spirit/include/phoenix_operator.hpp> using boost::spirit::qi::double_; using boost::spirit::qi::int_; using boost::spirit::qi::lexeme; using boost::spirit::qi::char_; using boost::spirit::qi::_1; using boost::spirit::qi::phrase_parse; using boost::spirit::ascii::space; using boost::phoenix::ref; int main(){ std::string test_line = " atom -1.4275 -1.84343 -1.9255 1 center_atom 12"; std::string::iterator first = test_line.begin(), last = test_line.end(); double x=9999., y=9999., z=9999.; int type=-1; std::string name ; int index=-1; bool parsed = phrase_parse(first, last, ( "atom" >> double_[ref(x) = _1] >> double_[ref(y) = _1] >> double_[ref(z) = _1] >> int_[ref(type) = _1] >> (+char_-' ') [ref(name) = _1] // < problem in this line, it doesn't compile >> int_[ref(index) = _1] ), space ); if(not parsed) std::clog << "can not interpret line, values read can be incomplete" << std::endl; std::clog <<"just read: x = " << x << " y = " << y << " z = " << z << " type = " << type << " name = " << name << " index = " << index << std::endl; return 0; } Thank you, Alfredo