Skip to content

Instantly share code, notes, and snippets.

@Tristramg
Created November 4, 2010 19:27
Show Gist options
  • Save Tristramg/663031 to your computer and use it in GitHub Desktop.
Save Tristramg/663031 to your computer and use it in GitHub Desktop.
#include <boost/spirit/include/classic_core.hpp>
#include <boost/spirit/include/classic_file_iterator.hpp>
#include <boost/spirit/include/classic_push_back_actor.hpp>
#include <iostream>
using namespace BOOST_SPIRIT_CLASSIC_NS;
int main(int, char**)
{
file_iterator<> first("bui.txt");
file_iterator<> last = first.make_end();
if(!first)
{
std::cout << "Ton fichier il pue" << std::endl;
return 1;
}
std::vector< std::vector<int> > v1, v2, v3;
parse_info< file_iterator<char> > info = parse(first, last, "#Domain" >> eol_p);
BOOST_ASSERT(info.hit);
while(! (info=parse(info.stop, last, eol_p)).hit)
{
v1.push_back(std::vector<int>());
BOOST_ASSERT((info = parse(info.stop, last, real_p[push_back_a(v1.back())] >> *(' '|real_p[push_back_a(v1.back())])>>eol_p)).hit);
}
BOOST_ASSERT((info = parse(info.stop, last, "#solution" >> eol_p)).hit);
while(! (info=parse(info.stop, last, eol_p)).hit)
{
v2.push_back(std::vector<int>());
BOOST_ASSERT((info = parse(info.stop, last, real_p[push_back_a(v2.back())] >> *(' '|real_p[push_back_a(v2.back())])>>eol_p)).hit);
}
BOOST_ASSERT((info = parse(info.stop, last, "#non solution" >> eol_p)).hit);
while(info.stop != last)
{
v3.push_back(std::vector<int>());
BOOST_ASSERT((info=parse(info.stop, last, real_p[push_back_a(v3.back())] >> *(' '|real_p[push_back_a(v3.back())])>>eol_p)).hit);
}
std::cout << v1.size() << " " << v2.size() << " " << v3.size() << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment