#include #include #include #include #include #include #include #include using namespace std; template bool test(Iterator first, Iterator last) { namespace qi=boost::spirit::qi; using boost::phoenix::val; using boost::spirit::qi::eps; using boost::spirit::qi::parse; using boost::spirit::qi::_1; using boost::spirit::qi::_2; //used for error handler using boost::spirit::qi::_3; //used for error handler using boost::spirit::qi::_4; //used for error handler using boost::spirit::qi::char_; using boost::spirit::qi::eol; using boost::spirit::qi::on_error; using boost::spirit::qi::fail; using boost::phoenix::construct; using boost::phoenix::val; qi::rulestart; start.name("start"); start=*(eps>char_('a')>>eol); on_error ( start , std::cout << val("Error! Expecting ") << _4 << val(" here(") //linenumber insert << val("): \"") << construct(_3, _2) << val("\"") << std::endl ); bool r = qi::parse(first,last,start); if (r && first == last){ return true; } else{ return false; } } int main () { ifstream myfile; myfile.open ("input.txt"); //disable whitespace skipping myfile.unsetf(std::ios::skipws); //create iterator for boost boost::spirit::istream_iterator begin(myfile); boost::spirit::istream_iterator end; bool r = test(begin,end); if(r){ std::cerr << "Parsing works..." << std::endl; } else{ std::cerr << "Parsing failed..." << std::endl; } myfile.close(); return 0; }