56325

Error when using boost::spirit::qi::phrase_parse() with a qi::grammar

Question:

I'm doing an IRC message parser with Boost.Spirit but I'm getting a (very long) error when I try to parse an input. I've followed the "<a href="http://www.boost.org/doc/libs/1_48_0/libs/spirit/doc/html/spirit/qi/tutorials/roman_numerals.html" rel="nofollow">Roman Numerals</a>" example. Also, I'm using g++4.7 with -std=c++11. The error occurs only when I call phrase_parse() on test.cpp, not when I make an instance of message_grammar.

The grammar class is:

class message_grammar : qi::grammar<std::string::const_iterator, std::string()> { public: message_grammar() : base_type(m_message) { using qi::_val; using qi::_1; using boost::spirit::ascii::char_; using qi::lit; qi::rule<std::string::const_iterator, std::string()> alpha, graph, number, special, user, nick, chn, channel; alpha = qi::as_string[qi::alpha]; graph = qi::as_string[qi::graph]; number = qi::as_string[char_('0', '9')]; chn = qi::as_string[(char_('#') | char_('$'))]; special = qi::as_string[ char_('-') | char_('[') | char_(']') | char_('\\') | char_('`') | char_('^') | char_('{') | char_('}') ]; user = ( graph [_val = std::string("USER%% ") + _1] >> *graph[_val += _1] ); nick = ( alpha[_val = std::string("NICK%% ") + _1] >> *( alpha | number | special )[_val += _1] ); channel = ( chn [_val = std::string("CHAN%% ") + _1] >> +(alpha | number | special) [_val += _1] ); m_message = ( nick [_val = _1] >> alpha [_val += std::string(" ") + _1] >> channel [_val += std::string(" ") + _1] >> user [_val += std::string(" ") + _1] ); } qi::rule<std::string::const_iterator, std::string()> m_message; };

and the testing function is:

int main() { string str, parsed_str; getline(cin, str); irc::message_grammar grammar; auto it = str.begin(); auto end = str.end(); bool ok = qi::phrase_parse(it, end, grammar , qi::space, parsed_str); if (ok && it == end) { cout << "OK" << endl; cout << parsed_str << endl; } else { cout << "NO " << ok << endl; } }

And the error message:

murilo@mac:cleverbot$ g++-mp-4.7 -std=c++11 test.cpp -Wall In file included from /opt/local/include/boost/proto/core.hpp:23:0, from /opt/local/include/boost/proto/proto.hpp:12, from /opt/local/include/boost/spirit/home/support/meta_compiler.hpp:19, from /opt/local/include/boost/spirit/home/qi/meta_compiler.hpp:14, from /opt/local/include/boost/spirit/home/qi/action/action.hpp:14, from /opt/local/include/boost/spirit/home/qi/action.hpp:14, from /opt/local/include/boost/spirit/home/qi.hpp:14, from /opt/local/include/boost/spirit/include/qi.hpp:16, from ircparser.h:6, from test.cpp:1: /opt/local/include/boost/proto/domain.hpp: In instantiation of 'struct boost::proto::domainns_::domain<>::as_expr<irc::message_grammar>': /opt/local/include/boost/proto/traits.hpp:266:71: required from 'struct boost::proto::result_of::as_expr<irc::message_grammar, boost::proto::domainns_::default_domain>' /opt/local/include/boost/spirit/home/support/meta_compiler.hpp:221:16: required from 'struct boost::spirit::traits::matches<boost::spirit::qi::domain, irc::message_grammar>' /opt/local/include/boost/spirit/home/qi/parse.hpp:155:9: required from 'bool boost::spirit::qi::phrase_parse(Iterator&, Iterator, const Expr&, const Skipper&, boost::spirit::qi::skip_flag, Attr&) [with Iterator = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >; Expr = irc::message_grammar; Skipper = boost::proto::exprns_::expr<boost::proto::tagns_::tag::terminal, boost::proto::argsns_::term<boost::spirit::tag::char_code<boost::spirit::tag::space, boost::spirit::char_encoding::standard> >, 0l>; Attr = std::basic_string<char>]' /opt/local/include/boost/spirit/home/qi/parse.hpp:197:86: required from 'bool boost::spirit::qi::phrase_parse(Iterator&, Iterator, const Expr&, const Skipper&, Attr&) [with Iterator = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >; Expr = irc::message_grammar; Skipper = boost::proto::exprns_::expr<boost::proto::tagns_::tag::terminal, boost::proto::argsns_::term<boost::spirit::tag::char_code<boost::spirit::tag::space, boost::spirit::char_encoding::standard> >, 0l>; Attr = std::basic_string<char>]' test.cpp:20:25: required from here /opt/local/include/boost/proto/extends.hpp:551:13: error: 'typedef void boost::proto::exprns_::extends<boost::proto::exprns_::expr<boost::proto::tagns_::tag::terminal, boost::proto::argsns_::term<boost::spirit::qi::reference<const boost::spirit::qi::rule<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char> >, std::basic_string<char>(), boost::spirit::unused_type, boost::spirit::unused_type, boost::spirit::unused_type> > >, 0l>, boost::spirit::qi::grammar<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char> >, std::basic_string<char>()>, boost::proto::domainns_::default_domain, 0l>::proto_is_expr_' is inaccessible In file included from /opt/local/include/boost/proto/traits.hpp:32:0, from /opt/local/include/boost/proto/expr.hpp:27, from /opt/local/include/boost/proto/core.hpp:17, from /opt/local/include/boost/proto/proto.hpp:12, from /opt/local/include/boost/spirit/home/support/meta_compiler.hpp:19, from /opt/local/include/boost/spirit/home/qi/meta_compiler.hpp:14, from /opt/local/include/boost/spirit/home/qi/action/action.hpp:14, from /opt/local/include/boost/spirit/home/qi/action.hpp:14, from /opt/local/include/boost/spirit/home/qi.hpp:14, from /opt/local/include/boost/spirit/include/qi.hpp:16, from ircparser.h:6, from test.cpp:1: /opt/local/include/boost/proto/domain.hpp:141:13: error: within this context In file included from /opt/local/include/boost/proto/core.hpp:23:0, from /opt/local/include/boost/proto/proto.hpp:12, from /opt/local/include/boost/spirit/home/support/meta_compiler.hpp:19, from /opt/local/include/boost/spirit/home/qi/meta_compiler.hpp:14, from /opt/local/include/boost/spirit/home/qi/action/action.hpp:14, from /opt/local/include/boost/spirit/home/qi/action.hpp:14, from /opt/local/include/boost/spirit/home/qi.hpp:14, from /opt/local/include/boost/spirit/include/qi.hpp:16, from ircparser.h:6, from test.cpp:1: /opt/local/include/boost/proto/extends.hpp:551:13: error: 'typedef void boost::proto::exprns_::extends<boost::proto::exprns_::expr<boost::proto::tagns_::tag::terminal, boost::proto::argsns_::term<boost::spirit::qi::reference<const boost::spirit::qi::rule<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char> >, std::basic_string<char>(), boost::spirit::unused_type, boost::spirit::unused_type, boost::spirit::unused_type> > >, 0l>, boost::spirit::qi::grammar<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char> >, std::basic_string<char>()>, boost::proto::domainns_::default_domain, 0l>::proto_is_expr_' is inaccessible In file included from /opt/local/include/boost/proto/traits.hpp:32:0, from /opt/local/include/boost/proto/expr.hpp:27, from /opt/local/include/boost/proto/core.hpp:17, from /opt/local/include/boost/proto/proto.hpp:12, from /opt/local/include/boost/spirit/home/support/meta_compiler.hpp:19, from /opt/local/include/boost/spirit/home/qi/meta_compiler.hpp:14, from /opt/local/include/boost/spirit/home/qi/action/action.hpp:14, from /opt/local/include/boost/spirit/home/qi/action.hpp:14, from /opt/local/include/boost/spirit/home/qi.hpp:14, from /opt/local/include/boost/spirit/include/qi.hpp:16, from ircparser.h:6, from test.cpp:1: /opt/local/include/boost/proto/domain.hpp:141:13: error: within this context In file included from /opt/local/include/boost/proto/core.hpp:23:0, from /opt/local/include/boost/proto/proto.hpp:12, from /opt/local/include/boost/spirit/home/support/meta_compiler.hpp:19, from /opt/local/include/boost/spirit/home/qi/meta_compiler.hpp:14, from /opt/local/include/boost/spirit/home/qi/action/action.hpp:14, from /opt/local/include/boost/spirit/home/qi/action.hpp:14, from /opt/local/include/boost/spirit/home/qi.hpp:14, from /opt/local/include/boost/spirit/include/qi.hpp:16, from ircparser.h:6, from test.cpp:1: /opt/local/include/boost/proto/extends.hpp:551:13: error: 'typedef void boost::proto::exprns_::extends<boost::proto::exprns_::expr<boost::proto::tagns_::tag::terminal, boost::proto::argsns_::term<boost::spirit::qi::reference<const boost::spirit::qi::rule<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char> >, std::basic_string<char>(), boost::spirit::unused_type, boost::spirit::unused_type, boost::spirit::unused_type> > >, 0l>, boost::spirit::qi::grammar<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char> >, std::basic_string<char>()>, boost::proto::domainns_::default_domain, 0l>::proto_is_expr_' is inaccessible In file included from /opt/local/include/boost/proto/traits.hpp:32:0, from /opt/local/include/boost/proto/expr.hpp:27, from /opt/local/include/boost/proto/core.hpp:17, from /opt/local/include/boost/proto/proto.hpp:12, from /opt/local/include/boost/spirit/home/support/meta_compiler.hpp:19, from /opt/local/include/boost/spirit/home/qi/meta_compiler.hpp:14, from /opt/local/include/boost/spirit/home/qi/action/action.hpp:14, from /opt/local/include/boost/spirit/home/qi/action.hpp:14, from /opt/local/include/boost/spirit/home/qi.hpp:14, from /opt/local/include/boost/spirit/include/qi.hpp:16, from ircparser.h:6, from test.cpp:1: /opt/local/include/boost/proto/domain.hpp:142:17: error: within this context In file included from /opt/local/include/boost/proto/core.hpp:23:0, from /opt/local/include/boost/proto/proto.hpp:12, from /opt/local/include/boost/spirit/home/support/meta_compiler.hpp:19, from /opt/local/include/boost/spirit/home/qi/meta_compiler.hpp:14, from /opt/local/include/boost/spirit/home/qi/action/action.hpp:14, from /opt/local/include/boost/spirit/home/qi/action.hpp:14, from /opt/local/include/boost/spirit/home/qi.hpp:14, from /opt/local/include/boost/spirit/include/qi.hpp:16, from ircparser.h:6, from test.cpp:1: /opt/local/include/boost/proto/extends.hpp:551:13: error: 'typedef void boost::proto::exprns_::extends<boost::proto::exprns_::expr<boost::proto::tagns_::tag::terminal, boost::proto::argsns_::term<boost::spirit::qi::reference<const boost::spirit::qi::rule<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char> >, std::basic_string<char>(), boost::spirit::unused_type, boost::spirit::unused_type, boost::spirit::unused_type> > >, 0l>, boost::spirit::qi::grammar<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char> >, std::basic_string<char>()>, boost::proto::domainns_::default_domain, 0l>::proto_is_expr_' is inaccessible In file included from /opt/local/include/boost/proto/traits.hpp:32:0, from /opt/local/include/boost/proto/expr.hpp:27, from /opt/local/include/boost/proto/core.hpp:17, from /opt/local/include/boost/proto/proto.hpp:12, from /opt/local/include/boost/spirit/home/support/meta_compiler.hpp:19, from /opt/local/include/boost/spirit/home/qi/meta_compiler.hpp:14, from /opt/local/include/boost/spirit/home/qi/action/action.hpp:14, from /opt/local/include/boost/spirit/home/qi/action.hpp:14, from /opt/local/include/boost/spirit/home/qi.hpp:14, from /opt/local/include/boost/spirit/include/qi.hpp:16, from ircparser.h:6, from test.cpp:1: /opt/local/include/boost/proto/domain.hpp:143:56: error: within this context In file included from /opt/local/include/boost/proto/core.hpp:23:0, from /opt/local/include/boost/proto/proto.hpp:12, from /opt/local/include/boost/spirit/home/support/meta_compiler.hpp:19, from /opt/local/include/boost/spirit/home/qi/meta_compiler.hpp:14, from /opt/local/include/boost/spirit/home/qi/action/action.hpp:14, from /opt/local/include/boost/spirit/home/qi/action.hpp:14, from /opt/local/include/boost/spirit/home/qi.hpp:14, from /opt/local/include/boost/spirit/include/qi.hpp:16, from ircparser.h:6, from test.cpp:1: /opt/local/include/boost/proto/extends.hpp:551:13: error: 'typedef void boost::proto::exprns_::extends<boost::proto::exprns_::expr<boost::proto::tagns_::tag::terminal, boost::proto::argsns_::term<boost::spirit::qi::reference<const boost::spirit::qi::rule<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char> >, std::basic_string<char>(), boost::spirit::unused_type, boost::spirit::unused_type, boost::spirit::unused_type> > >, 0l>, boost::spirit::qi::grammar<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char> >, std::basic_string<char>()>, boost::proto::domainns_::default_domain, 0l>::proto_is_expr_' is inaccessible In file included from /opt/local/include/boost/proto/traits.hpp:32:0, from /opt/local/include/boost/proto/expr.hpp:27, from /opt/local/include/boost/proto/core.hpp:17, from /opt/local/include/boost/proto/proto.hpp:12, from /opt/local/include/boost/spirit/home/support/meta_compiler.hpp:19, from /opt/local/include/boost/spirit/home/qi/meta_compiler.hpp:14, from /opt/local/include/boost/spirit/home/qi/action/action.hpp:14, from /opt/local/include/boost/spirit/home/qi/action.hpp:14, from /opt/local/include/boost/spirit/home/qi.hpp:14, from /opt/local/include/boost/spirit/include/qi.hpp:16, from ircparser.h:6, from test.cpp:1: /opt/local/include/boost/proto/domain.hpp:146:29: error: within this context In file included from /opt/local/include/boost/proto/core.hpp:23:0, from /opt/local/include/boost/proto/proto.hpp:12, from /opt/local/include/boost/spirit/home/support/meta_compiler.hpp:19, from /opt/local/include/boost/spirit/home/qi/meta_compiler.hpp:14, from /opt/local/include/boost/spirit/home/qi/action/action.hpp:14, from /opt/local/include/boost/spirit/home/qi/action.hpp:14, from /opt/local/include/boost/spirit/home/qi.hpp:14, from /opt/local/include/boost/spirit/include/qi.hpp:16, from ircparser.h:6, from test.cpp:1: /opt/local/include/boost/proto/extends.hpp:551:13: error: 'typedef void boost::proto::exprns_::extends<boost::proto::exprns_::expr<boost::proto::tagns_::tag::terminal, boost::proto::argsns_::term<boost::spirit::qi::reference<const boost::spirit::qi::rule<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char> >, std::basic_string<char>(), boost::spirit::unused_type, boost::spirit::unused_type, boost::spirit::unused_type> > >, 0l>, boost::spirit::qi::grammar<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char> >, std::basic_string<char>()>, boost::proto::domainns_::default_domain, 0l>::proto_is_expr_' is inaccessible In file included from /opt/local/include/boost/proto/traits.hpp:32:0, from /opt/local/include/boost/proto/expr.hpp:27, from /opt/local/include/boost/proto/core.hpp:17, from /opt/local/include/boost/proto/proto.hpp:12, from /opt/local/include/boost/spirit/home/support/meta_compiler.hpp:19, from /opt/local/include/boost/spirit/home/qi/meta_compiler.hpp:14, from /opt/local/include/boost/spirit/home/qi/action/action.hpp:14, from /opt/local/include/boost/spirit/home/qi/action.hpp:14, from /opt/local/include/boost/spirit/home/qi.hpp:14, from /opt/local/include/boost/spirit/include/qi.hpp:16, from ircparser.h:6, from test.cpp:1: /opt/local/include/boost/proto/domain.hpp:146:29: error: within this context In file included from /opt/local/include/boost/proto/core.hpp:23:0, from /opt/local/include/boost/proto/proto.hpp:12, from /opt/local/include/boost/spirit/home/support/meta_compiler.hpp:19, from /opt/local/include/boost/spirit/home/qi/meta_compiler.hpp:14, from /opt/local/include/boost/spirit/home/qi/action/action.hpp:14, from /opt/local/include/boost/spirit/home/qi/action.hpp:14, from /opt/local/include/boost/spirit/home/qi.hpp:14, from /opt/local/include/boost/spirit/include/qi.hpp:16, from ircparser.h:6, from test.cpp:1: /opt/local/include/boost/proto/extends.hpp:551:13: error: 'typedef void boost::proto::exprns_::extends<boost::proto::exprns_::expr<boost::proto::tagns_::tag::terminal, boost::proto::argsns_::term<boost::spirit::qi::reference<const boost::spirit::qi::rule<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char> >, std::basic_string<char>(), boost::spirit::unused_type, boost::spirit::unused_type, boost::spirit::unused_type> > >, 0l>, boost::spirit::qi::grammar<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char> >, std::basic_string<char>()>, boost::proto::domainns_::default_domain, 0l>::proto_is_expr_' is inaccessible In file included from /opt/local/include/boost/proto/traits.hpp:32:0, from /opt/local/include/boost/proto/expr.hpp:27, from /opt/local/include/boost/proto/core.hpp:17, from /opt/local/include/boost/proto/proto.hpp:12, from /opt/local/include/boost/spirit/home/support/meta_compiler.hpp:19, from /opt/local/include/boost/spirit/home/qi/meta_compiler.hpp:14, from /opt/local/include/boost/spirit/home/qi/action/action.hpp:14, from /opt/local/include/boost/spirit/home/qi/action.hpp:14, from /opt/local/include/boost/spirit/home/qi.hpp:14, from /opt/local/include/boost/spirit/include/qi.hpp:16, from ircparser.h:6, from test.cpp:1: /opt/local/include/boost/proto/domain.hpp:146:46: error: within this context In file included from /opt/local/include/boost/proto/core.hpp:23:0, from /opt/local/include/boost/proto/proto.hpp:12, from /opt/local/include/boost/spirit/home/support/meta_compiler.hpp:19, from /opt/local/include/boost/spirit/home/qi/meta_compiler.hpp:14, from /opt/local/include/boost/spirit/home/qi/action/action.hpp:14, from /opt/local/include/boost/spirit/home/qi/action.hpp:14, from /opt/local/include/boost/spirit/home/qi.hpp:14, from /opt/local/include/boost/spirit/include/qi.hpp:16, from ircparser.h:6, from test.cpp:1: /opt/local/include/boost/proto/matches.hpp: In instantiation of 'struct boost::proto::matches<irc::message_grammar, boost::spirit::meta_compiler<boost::spirit::qi::domain>::meta_grammar>': /opt/local/include/boost/spirit/home/support/meta_compiler.hpp:221:16: required from 'struct boost::spirit::traits::matches<boost::spirit::qi::domain, irc::message_grammar>' /opt/local/include/boost/spirit/home/qi/parse.hpp:155:9: required from 'bool boost::spirit::qi::phrase_parse(Iterator&, Iterator, const Expr&, const Skipper&, boost::spirit::qi::skip_flag, Attr&) [with Iterator = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >; Expr = irc::message_grammar; Skipper = boost::proto::exprns_::expr<boost::proto::tagns_::tag::terminal, boost::proto::argsns_::term<boost::spirit::tag::char_code<boost::spirit::tag::space, boost::spirit::char_encoding::standard> >, 0l>; Attr = std::basic_string<char>]' /opt/local/include/boost/spirit/home/qi/parse.hpp:197:86: required from 'bool boost::spirit::qi::phrase_parse(Iterator&, Iterator, const Expr&, const Skipper&, Attr&) [with Iterator = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >; Expr = irc::message_grammar; Skipper = boost::proto::exprns_::expr<boost::proto::tagns_::tag::terminal, boost::proto::argsns_::term<boost::spirit::tag::char_code<boost::spirit::tag::space, boost::spirit::char_encoding::standard> >, 0l>; Attr = std::basic_string<char>]' test.cpp:20:25: required from here /opt/local/include/boost/proto/extends.hpp:551:13: error: 'typedef struct boost::spirit::qi::grammar<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char> >, std::basic_string<char>()> boost::proto::exprns_::extends<boost::proto::exprns_::expr<boost::proto::tagns_::tag::terminal, boost::proto::argsns_::term<boost::spirit::qi::reference<const boost::spirit::qi::rule<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char> >, std::basic_string<char>(), boost::spirit::unused_type, boost::spirit::unused_type, boost::spirit::unused_type> > >, 0l>, boost::spirit::qi::grammar<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char> >, std::basic_string<char>()>, boost::proto::domainns_::default_domain, 0l>::proto_derived_expr' is inaccessible

Answer1:

You should declare message_grammar as a struct rather than a class. Also, you can derive your class publicly from qi::grammar:

class message_grammar : public qi::grammar<std::string::const_iterator, std::string()> { }

you also may find this <a href="https://stackoverflow.com/questions/8750292/class-v-s-struct-in-boostspirit" rel="nofollow">article</a> useful.

Recommend

  • Access violation on std::function assignement using lambdas
  • boost spirit, boost any and quoted string - compile-time error
  • MIMEMultipart, MIMEText, MIMEBase, and payloads for sending email with file attachment in Python
  • Problems with grammar
  • cron job to send ip of BeagleBone Black (at every reboot) to my email is not firing
  • NodeJS Sendrgrid Issue in sending email to multiple recepients
  • error 400 bad request with XEP-0055?
  • Angular/Nativescript: Listview doesn't show at all
  • Ignore all characters up to a given word
  • TransportError(403, u'cluster_block_exception', u'blocked by: [FORBIDDEN/12/index rea
  • Get highest value from a file using mSL and mIRC
  • Ignoring certain validation rules with jQuery validate
  • Use Batch file to add headers to CSV
  • Python - replace unicode emojis with ASCII charachters
  • writing unicode to binary file in python
  • C++, user input check for '\\0' stops at spaces?
  • StreamWriter won't flush to NetworkStream
  • node-postgres UTF password bug
  • How to remove last utf8 char of a python string
  • Send the string to its hex equivalent
  • Creating a C++ function that calls other Lua function
  • remove unicode characters but keep all special and English characters with preg_replace
  • Why isn't my “Fizz Buzz” test in R working?
  • Validate jQuery plugin, field not required
  • Switch to popup in python using selenium
  • Why Encoding.ASCII != ASCIIEncoding.Default in C#?
  • How to define and use opencv mat of user type
  • Is there a javascript serializer for JSON.Net?
  • Projection media query: browser support and workarounds?
  • script to move all files from one location to another location
  • WinForms: two way TextBox problem
  • Where to put my custom functions in Wordpress?
  • Can I make an Android app that runs a web view in Chrome 39?
  • Buffer size for converting unsigned long to string
  • Turn off referential integrity in Derby? is it possible?
  • Authorize attributes not working in MVC 4
  • Busy indicator not showing up in wpf window [duplicate]
  • Binding checkboxes to object values in AngularJs
  • Python/Django TangoWithDjango Models and Databases
  • Net Present Value in Excel for Grouped Recurring CF