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_number.c... 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) // Begin grammar ( '(' >> double_[ref(rN) = _1] >> -(',' >> double_[ref(iN) = _1]) >> ')' | double_[ref(rN) = _1] ), // End grammar space); Thank you Alfredo error message below: complex_number.cpp: In function 'bool client::parse_complex(Iterator, Iterator, std::complex<double>&) [with Iterator = __gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >]': complex_number.cpp:81: instantiated from here complex_number.cpp:51: error: no matching function for call to 'phrase_parse(__gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> >
, __gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, const boost::proto::exprns_::expr<boost::proto::tag::bitwise_or, boost::proto::argsns_::list2<const boost::proto::exprns_::expr<boost::proto::tag::shift_right, boost::proto::argsns_::list2<const boost::proto::exprns_::expr<boost::proto::tag::shift_right, boost::proto::argsns_::list2<const boost::proto::exprns_::expr<boost::proto::tag::shift_right, boost::proto::argsns_::list2<boost::proto::exprns_::expr<boost::proto::tag::terminal, boost::proto::argsns_::term<const char&>, 0l>, const boost::proto::exprns_::expr<boost::proto::tag::subscript, boost::proto::argsns_::list2<const boost::spirit::terminal<boost::spirit::tag::double_>&, boost::proto::exprns_::expr<boost::proto::tag::terminal, boost::proto::argsns_::term<const boost::phoenix::actor<boost::phoenix::composite<boost::phoenix::assign_eval, boost::fusion::vector<boost::phoenix::reference<double>, boost::spirit::argument<0>, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_> > >&>, 0l> >, 2l>&>, 2l>&, const boost::proto::exprns_::expr<boost::proto::tag::negate, boost::proto::argsns_::list1<const boost::proto::exprns_::expr<boost::proto::tag::shift_right, boost::proto::argsns_::list2<boost::proto::exprns_::expr<boost::proto::tag::terminal, boost::proto::argsns_::term<const char&>, 0l>, const boost::proto::exprns_::expr<boost::proto::tag::subscript, boost::proto::argsns_::list2<const boost::spirit::terminal<boost::spirit::tag::double_>&, boost::proto::exprns_::expr<boost::proto::tag::terminal, boost::proto::argsns_::term<const boost::phoenix::actor<boost::phoenix::composite<boost::phoenix::assign_eval, boost::fusion::vector<boost::phoenix::reference<double>, boost::spirit::argument<0>, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_> > >&>, 0l> >, 2l>&>, 2l>&>, 1l>&>, 2l>&, boost::proto::exprns_::expr<boost::proto::tag::terminal, boost::proto::argsns_::term<const char&>, 0l> >, 2l>&, const boost::proto::exprns_::expr<boost::proto::tag::subscript, boost::proto::argsns_::list2<const boost::spirit::terminal<boost::spirit::tag::double_>&, boost::proto::exprns_::expr<boost::proto::tag::terminal, boost::proto::argsns_::term<const boost::phoenix::actor<boost::phoenix::composite<boost::phoenix::assign_eval, boost::fusion::vector<boost::phoenix::reference<double>, boost::spirit::argument<0>, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_> > >&>, 0l> >, 2l>&>, 2l>, const boost::spirit::ascii::space_type&)' /g/g91/correaa/usr/include/boost/spirit/home/qi/parse.hpp:62: note: candidates are: bool boost::spirit::qi::phrase_parse(Iterator&, Iterator, const Expr&, const Skipper&, boost::spirit::qi::skip_flag::enum_t) [with Iterator = __gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, Expr = boost::proto::exprns_::expr<boost::proto::tag::bitwise_or, boost::proto::argsns_::list2<const boost::proto::exprns_::expr<boost::proto::tag::shift_right, boost::proto::argsns_::list2<const boost::proto::exprns_::expr<boost::proto::tag::shift_right, boost::proto::argsns_::list2<const boost::proto::exprns_::expr<boost::proto::tag::shift_right, boost::proto::argsns_::list2<boost::proto::exprns_::expr<boost::proto::tag::terminal, boost::proto::argsns_::term<const char&>, 0l>, const boost::proto::exprns_::expr<boost::proto::tag::subscript, boost::proto::argsns_::list2<const boost::spirit::terminal<boost::spirit::tag::double_>&, boost::proto::exprns_::expr<boost::proto::tag::terminal, boost::proto::argsns_::term<const boost::phoenix::actor<boost::phoenix::composite<boost::phoenix::assign_eval, boost::fusion::vector<boost::phoenix::reference<double>, boost::spirit::argument<0>, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_> > >&>, 0l> >, 2l>&>, 2l>&, const boost::proto::exprns_::expr<boost::proto::tag::negate, boost::proto::argsns_::list1<const boost::proto::exprns_::expr<boost::proto::tag::shift_right, boost::proto::argsns_::list2<boost::proto::exprns_::expr<boost::proto::tag::terminal, boost::proto::argsns_::term<const char&>, 0l>, const boost::proto::exprns_::expr<boost::proto::tag::subscript, boost::proto::argsns_::list2<const boost::spirit::terminal<boost::spirit::tag::double_>&, boost::proto::exprns_::expr<boost::proto::tag::terminal, boost::proto::argsns_::term<const boost::phoenix::actor<boost::phoenix::composite<boost::phoenix::assign_eval, boost::fusion::vector<boost::phoenix::reference<double>, boost::spirit::argument<0>, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_> > >&>, 0l> >, 2l>&>, 2l>&>, 1l>&>, 2l>&, boost::proto::exprns_::expr<boost::proto::tag::terminal, boost::proto::argsns_::term<const char&>, 0l> >, 2l>&, const boost::proto::exprns_::expr<boost::proto::tag::subscript, boost::proto::argsns_::list2<const boost::spirit::terminal<boost::spirit::tag::double_>&, boost::proto::exprns_::expr<boost::proto::tag::terminal, boost::proto::argsns_::term<const boost::phoenix::actor<boost::phoenix::composite<boost::phoenix::assign_eval, boost::fusion::vector<boost::phoenix::reference<double>, boost::spirit::argument<0>, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_> > >&>, 0l> >, 2l>&>, 2l>, Skipper = boost::spirit::ascii::space_type] /g/g91/correaa/usr/include/boost/spirit/home/qi/detail/parse_auto.hpp: 164: note: bool boost::spirit::qi::phrase_parse(Iterator&, Iterator, Expr&, const Skipper&, boost::spirit::qi::skip_flag::enum_t) [with Iterator = __gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, Expr = const boost::proto::exprns_::expr<boost::proto::tag::bitwise_or, boost::proto::argsns_::list2<const boost::proto::exprns_::expr<boost::proto::tag::shift_right, boost::proto::argsns_::list2<const boost::proto::exprns_::expr<boost::proto::tag::shift_right, boost::proto::argsns_::list2<const boost::proto::exprns_::expr<boost::proto::tag::shift_right, boost::proto::argsns_::list2<boost::proto::exprns_::expr<boost::proto::tag::terminal, boost::proto::argsns_::term<const char&>, 0l>, const boost::proto::exprns_::expr<boost::proto::tag::subscript, boost::proto::argsns_::list2<const boost::spirit::terminal<boost::spirit::tag::double_>&, boost::proto::exprns_::expr<boost::proto::tag::terminal, boost::proto::argsns_::term<const boost::phoenix::actor<boost::phoenix::composite<boost::phoenix::assign_eval, boost::fusion::vector<boost::phoenix::reference<double>, boost::spirit::argument<0>, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_> > >&>, 0l> >, 2l>&>, 2l>&, const boost::proto::exprns_::expr<boost::proto::tag::negate, boost::proto::argsns_::list1<const boost::proto::exprns_::expr<boost::proto::tag::shift_right, boost::proto::argsns_::list2<boost::proto::exprns_::expr<boost::proto::tag::terminal, boost::proto::argsns_::term<const char&>, 0l>, const boost::proto::exprns_::expr<boost::proto::tag::subscript, boost::proto::argsns_::list2<const boost::spirit::terminal<boost::spirit::tag::double_>&, boost::proto::exprns_::expr<boost::proto::tag::terminal, boost::proto::argsns_::term<const boost::phoenix::actor<boost::phoenix::composite<boost::phoenix::assign_eval, boost::fusion::vector<boost::phoenix::reference<double>, boost::spirit::argument<0>, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_> > >&>, 0l> >, 2l>&>, 2l>&>, 1l>&>, 2l>&, boost::proto::exprns_::expr<boost::proto::tag::terminal, boost::proto::argsns_::term<const char&>, 0l> >, 2l>&, const boost::proto::exprns_::expr<boost::proto::tag::subscript, boost::proto::argsns_::list2<const boost::spirit::terminal<boost::spirit::tag::double_>&, boost::proto::exprns_::expr<boost::proto::tag::terminal, boost::proto::argsns_::term<const boost::phoenix::actor<boost::phoenix::composite<boost::phoenix::assign_eval, boost::fusion::vector<boost::phoenix::reference<double>, boost::spirit::argument<0>, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_> > >&>, 0l> >, 2l>&>, 2l>, Skipper = boost::spirit::ascii::space_type]
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_number .cpp
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) // Begin grammar ( '(' >> double_[ref(rN) = _1] >> -(',' >> double_[ref(iN) = _1]) >> ')' | double_[ref(rN) = _1] ), // End grammar
space);
What Spirit version are you looking at? Regards Hartmut --------------- http://boost-spirit.com
Thank you Alfredo error message below:
complex_number.cpp: In function 'bool client::parse_complex(Iterator, Iterator, std::complex<double>&) [with Iterator = __gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >]': complex_number.cpp:81: instantiated from here complex_number.cpp:51: error: no matching function for call to 'phrase_parse(__gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> >
, __gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, const boost::proto::exprns_::expr<boost::proto::tag::bitwise_or, boost::proto::argsns_::list2<const boost::proto::exprns_::expr<boost::proto::tag::shift_right, boost::proto::argsns_::list2<const boost::proto::exprns_::expr<boost::proto::tag::shift_right, boost::proto::argsns_::list2<const boost::proto::exprns_::expr<boost::proto::tag::shift_right, boost::proto::argsns_::list2<boost::proto::exprns_::expr<boost::proto::tag ::terminal, boost::proto::argsns_::term<const char&>, 0l>, const boost::proto::exprns_::expr<boost::proto::tag::subscript, boost::proto::argsns_::list2<const boost::spirit::terminal<boost::spirit::tag::double_>&, boost::proto::exprns_::expr<boost::proto::tag::terminal, boost::proto::argsns_::term<const boost::phoenix::actor<boost::phoenix::composite<boost::phoenix::assign_eva l, boost::fusion::vector<boost::phoenix::reference<double>, boost::spirit::argument<0>, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_> > >&>, 0l> >, 2l>&>, 2l>&, const boost::proto::exprns_::expr<boost::proto::tag::negate, boost::proto::argsns_::list1<const boost::proto::exprns_::expr<boost::proto::tag::shift_right, boost::proto::argsns_::list2<boost::proto::exprns_::expr<boost::proto::tag ::terminal, boost::proto::argsns_::term<const char&>, 0l>, const boost::proto::exprns_::expr<boost::proto::tag::subscript, boost::proto::argsns_::list2<const boost::spirit::terminal<boost::spirit::tag::double_>&, boost::proto::exprns_::expr<boost::proto::tag::terminal, boost::proto::argsns_::term<const boost::phoenix::actor<boost::phoenix::composite<boost::phoenix::assign_eva l, boost::fusion::vector<boost::phoenix::reference<double>, boost::spirit::argument<0>, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_> > >&>, 0l> >, 2l>&>, 2l>&>, 1l>&>, 2l>&, boost::proto::exprns_::expr<boost::proto::tag::terminal, boost::proto::argsns_::term<const char&>, 0l> >, 2l>&, const boost::proto::exprns_::expr<boost::proto::tag::subscript, boost::proto::argsns_::list2<const boost::spirit::terminal<boost::spirit::tag::double_>&, boost::proto::exprns_::expr<boost::proto::tag::terminal, boost::proto::argsns_::term<const boost::phoenix::actor<boost::phoenix::composite<boost::phoenix::assign_eva l, boost::fusion::vector<boost::phoenix::reference<double>, boost::spirit::argument<0>, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_> > >&>, 0l> >, 2l>&>, 2l>, const boost::spirit::ascii::space_type&)' /g/g91/correaa/usr/include/boost/spirit/home/qi/parse.hpp:62: note: candidates are: bool boost::spirit::qi::phrase_parse(Iterator&, Iterator, const Expr&, const Skipper&, boost::spirit::qi::skip_flag::enum_t) [with Iterator = __gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, Expr = boost::proto::exprns_::expr<boost::proto::tag::bitwise_or, boost::proto::argsns_::list2<const boost::proto::exprns_::expr<boost::proto::tag::shift_right, boost::proto::argsns_::list2<const boost::proto::exprns_::expr<boost::proto::tag::shift_right, boost::proto::argsns_::list2<const boost::proto::exprns_::expr<boost::proto::tag::shift_right, boost::proto::argsns_::list2<boost::proto::exprns_::expr<boost::proto::tag ::terminal, boost::proto::argsns_::term<const char&>, 0l>, const boost::proto::exprns_::expr<boost::proto::tag::subscript, boost::proto::argsns_::list2<const boost::spirit::terminal<boost::spirit::tag::double_>&, boost::proto::exprns_::expr<boost::proto::tag::terminal, boost::proto::argsns_::term<const boost::phoenix::actor<boost::phoenix::composite<boost::phoenix::assign_eva l, boost::fusion::vector<boost::phoenix::reference<double>, boost::spirit::argument<0>, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_> > >&>, 0l> >, 2l>&>, 2l>&, const boost::proto::exprns_::expr<boost::proto::tag::negate, boost::proto::argsns_::list1<const boost::proto::exprns_::expr<boost::proto::tag::shift_right, boost::proto::argsns_::list2<boost::proto::exprns_::expr<boost::proto::tag ::terminal, boost::proto::argsns_::term<const char&>, 0l>, const boost::proto::exprns_::expr<boost::proto::tag::subscript, boost::proto::argsns_::list2<const boost::spirit::terminal<boost::spirit::tag::double_>&, boost::proto::exprns_::expr<boost::proto::tag::terminal, boost::proto::argsns_::term<const boost::phoenix::actor<boost::phoenix::composite<boost::phoenix::assign_eva l, boost::fusion::vector<boost::phoenix::reference<double>, boost::spirit::argument<0>, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_> > >&>, 0l> >, 2l>&>, 2l>&>, 1l>&>, 2l>&, boost::proto::exprns_::expr<boost::proto::tag::terminal, boost::proto::argsns_::term<const char&>, 0l> >, 2l>&, const boost::proto::exprns_::expr<boost::proto::tag::subscript, boost::proto::argsns_::list2<const boost::spirit::terminal<boost::spirit::tag::double_>&, boost::proto::exprns_::expr<boost::proto::tag::terminal, boost::proto::argsns_::term<const boost::phoenix::actor<boost::phoenix::composite<boost::phoenix::assign_eva l, boost::fusion::vector<boost::phoenix::reference<double>, boost::spirit::argument<0>, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_> > >&>, 0l> >, 2l>&>, 2l>, Skipper = boost::spirit::ascii::space_type] /g/g91/correaa/usr/include/boost/spirit/home/qi/detail/parse_auto.hpp: 164: note: bool boost::spirit::qi::phrase_parse(Iterator&, Iterator, Expr&, const Skipper&, boost::spirit::qi::skip_flag::enum_t) [with Iterator = __gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, Expr = const boost::proto::exprns_::expr<boost::proto::tag::bitwise_or, boost::proto::argsns_::list2<const boost::proto::exprns_::expr<boost::proto::tag::shift_right, boost::proto::argsns_::list2<const boost::proto::exprns_::expr<boost::proto::tag::shift_right, boost::proto::argsns_::list2<const boost::proto::exprns_::expr<boost::proto::tag::shift_right, boost::proto::argsns_::list2<boost::proto::exprns_::expr<boost::proto::tag ::terminal, boost::proto::argsns_::term<const char&>, 0l>, const boost::proto::exprns_::expr<boost::proto::tag::subscript, boost::proto::argsns_::list2<const boost::spirit::terminal<boost::spirit::tag::double_>&, boost::proto::exprns_::expr<boost::proto::tag::terminal, boost::proto::argsns_::term<const boost::phoenix::actor<boost::phoenix::composite<boost::phoenix::assign_eva l, boost::fusion::vector<boost::phoenix::reference<double>, boost::spirit::argument<0>, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_> > >&>, 0l> >, 2l>&>, 2l>&, const boost::proto::exprns_::expr<boost::proto::tag::negate, boost::proto::argsns_::list1<const boost::proto::exprns_::expr<boost::proto::tag::shift_right, boost::proto::argsns_::list2<boost::proto::exprns_::expr<boost::proto::tag ::terminal, boost::proto::argsns_::term<const char&>, 0l>, const boost::proto::exprns_::expr<boost::proto::tag::subscript, boost::proto::argsns_::list2<const boost::spirit::terminal<boost::spirit::tag::double_>&, boost::proto::exprns_::expr<boost::proto::tag::terminal, boost::proto::argsns_::term<const boost::phoenix::actor<boost::phoenix::composite<boost::phoenix::assign_eva l, boost::fusion::vector<boost::phoenix::reference<double>, boost::spirit::argument<0>, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_> > >&>, 0l> >, 2l>&>, 2l>&>, 1l>&>, 2l>&, boost::proto::exprns_::expr<boost::proto::tag::terminal, boost::proto::argsns_::term<const char&>, 0l> >, 2l>&, const boost::proto::exprns_::expr<boost::proto::tag::subscript, boost::proto::argsns_::list2<const boost::spirit::terminal<boost::spirit::tag::double_>&, boost::proto::exprns_::expr<boost::proto::tag::terminal, boost::proto::argsns_::term<const boost::phoenix::actor<boost::phoenix::composite<boost::phoenix::assign_eva l, boost::fusion::vector<boost::phoenix::reference<double>, boost::spirit::argument<0>, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_> > >&>, 0l> >, 2l>&>, 2l>, Skipper = boost::spirit::ascii::space_type]
Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
On Fri, Oct 1, 2010 at 2:34 PM, alfC <alfredo.correa@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_number.c...
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. Visual studio can accept a const in a non-const if it is a temporary, as above. GCC however, follows the standard, meaning that you must create an iterator for at least the s.begin() and pass the iterator in, not a temporary, meaning change the above lines to this: std::string s = "(2, 3)"; // < line added to example std::string::iterator iter = s.begin(); bool r = phrase_parse(iter, s.end(), //< only line changed in the example was (first, last)
On Fri, Oct 1, 2010 at 2:34 PM, alfC <alfredo.correa@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_nu mber.cpp
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.
Visual studio can accept a const in a non-const if it is a temporary, as above. GCC however, follows the standard, meaning that you must create an iterator for at least the s.begin() and pass the iterator in, not a temporary, meaning change the above lines to this:
std::string s = "(2, 3)"; // < line added to example std::string::iterator iter = s.begin(); bool r = phrase_parse(iter, s.end(), //< only line changed in the example was (first, last)
Starting with V2.4 (Boost V1.44) Spirit has a set of overloaded API functions allowing to pass a const iterator as the first parameter as well. Your code would work there just fine. Regards Hartmut --------------- http://boost-spirit.com
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
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
My guess is that you meant to write: lexeme[+(char_-' ') [phx::ref(name) += _1]] adding the matched characters one by one to the string and avoiding to skip the spaces in between characters. The expression +~char_(' ') is equivalent but more efficient, btw. It means 'match everything but ' ' at least once'.
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; }
As a rule, I'd suggest to avoid semantic actions altogether. If you write: bool parsed = phrase_parse(first, last, "atom" >> double_ >> double_ >> double_ >> int_ >> lexeme[+~char_(' ')] >> int_, space, x, y, z, type, name, index ); you get the same result, just a lot simpler and cleaner. Regards Hartmut --------------- http://boost-spirit.com
participants (3)
-
alfC
-
Hartmut Kaiser
-
OvermindDL1