From: <har...@t-...> - 2003-03-31 20:13:47
|
Jeff Holle wrote: There are the following changed nessecary to make it work as expected: > The program: > > #include <iostream> > #include <fstream> > #include <string> > #include <boost/spirit.hpp> > using std::cout; > using std::cerr; > using std::endl; > using std::string; > using std::ifstream; > using std::getline; > using namespace boost::spirit; > > struct name > { > template <typename IteratorT> > void operator()(IteratorT const & first,IteratorT const & last) const > { > string s(first,last); > cout << s << endl; > } // you need the one argument operator() for alnum_p // because this parser has an own result_type defined template <typename ValueT> void operator() (ValueT const &val) { cout << val << endl; } > }; > > > struct ini_grammar : public grammar<ini_grammar> > { > template <typename ScannerT> > struct definition > { > definition(ini_grammar const& self) > { > expression = *alnum_p[name] >> *space_p >> '=' >> *space_p >> > *alnum_p; << this is line 31 and the source of the compiler error // you have to pass an instance of the required functor as the // semantic action, not a type expression = *alnum_p[name()] >> ... > }; > rule<ScannerT> expression; > rule<ScannerT> const& > start() const { return expression; } > }; > }; > > int > main(int argc, char **argv) > { > if (argc < 2) { > cerr << "usage: testParser \"win ini file\"" << endl; > exit(0); > } > ifstream( in(argv[1])); // this seems to be a typo ifstream in(argv[1]); > if (!in) { > cerr << "Can't open \"" << argv[1] << "\"" << endl; > exit(0); > } > ini_grammar ini; > string str; > while (getline(in, str)) > { > parse_info<> info = parse(str.c_str(), ini, space_p); > if (info.full) > cout << "parsing succeeded" << endl; > else > cout << "parsing failed" << endl; > } > } HTH Regards Hartmut |