This code gives me the following errors at the line My_grammar g;
:
no matching function for call to boost::spirit::qi::grammar<My_grammar>::grammar()’
use of deleted function ‘My_grammar::My_grammar()’
I don't get it, isn't there supposed to be a default (not deleted) constructor ? But the problem is probably elsewhere.
I'd implement a constructor, but it brings new errors, and the tutorials/examples never use the same approach (some with constructors, some without), or use classes neither I, the doc, the compiler or google know anything about (CParser ??). I think it might be because of the headers I (don't) include, since there is A LOT I can choose from under boost/spirit. Again, people in possibly out-of-date tutorials don't seem to include the same, or to use ones that don't exist with my yesterday, apt-get fetched, most probably up-to-date version of boost. I'm using Eclipse, in case it changes anything.
#include <iostream>
#include <cstdlib>
#include <string>
#include <boost/spirit/include/qi.hpp>
#include <boost/spirit/include/qi_rule.hpp>
using namespace boost::spirit;
#define BOOST_SPIRIT_DEBUG
struct My_grammar :
public boost::spirit::qi::grammar<My_grammar>
{
public:
template <typename ScannerT>
struct definition
{
public:
definition(My_grammar const& self)
{
sentence
= 'a';
}
boost::spirit::qi::rule<ScannerT> sentence;
boost::spirit::qi::rule<ScannerT> const& start() const { return sentence; }
};
};
int main() {
My_grammar g;
return EXIT_SUCCESS;
}
I feel a lot more questions coming next (e.g : I already tried and failed the parse() function), but I want to solve it one at a time.
Looks like you are stuck with a "classical" spirit parser skeleton.
Spirit V2 is rather different, and has looooong superseded V1:
Here's how you'd write the grammar definition in Spirit V2:
#define BOOST_SPIRIT_DEBUG
#include <boost/spirit/include/qi.hpp>
namespace qi = boost::spirit::qi;
template <typename It>
struct My_grammar : public qi::grammar<It> {
My_grammar() : My_grammar::base_type(sentence) {
sentence = 'a';
}
qi::rule<It> sentence;
};
int main() {
My_grammar<std::string::const_iterator> g;
}