metaSMT 2
|
00001 #include <boost/spirit/include/qi.hpp> 00002 #include <boost/tuple/tuple.hpp> 00003 #include <boost/tuple/tuple_io.hpp> 00004 #include <boost/fusion/adapted/boost_tuple.hpp> 00005 #include <string> 00006 #include <vector> 00007 00008 namespace metaSMT { 00009 namespace SAT { 00014 typedef boost::tuple< std::string, std::vector< int > > result_tuple; 00015 00016 // debug code 00017 //template< typename O> 00018 //O& operator<< (O& o, std::vector< int > const & v) { 00019 // BOOST_FOREACH(int i, v) { 00020 // o << i << ' '; 00021 // } 00022 // return o; 00023 //} 00024 00025 template< typename Iterator > 00026 struct model_grammar : boost::spirit::qi::grammar<Iterator, result_tuple()> 00027 { 00028 model_grammar() : model_grammar::base_type(start) 00029 { 00030 using boost::spirit::qi::lit; 00031 using boost::spirit::qi::char_; 00032 using boost::spirit::qi::int_; 00033 using boost::spirit::qi::eol; 00034 using boost::spirit::qi::attr; 00035 00036 start = 00037 *comment 00038 >> result 00039 >> *comment 00040 >> -lit("v ") >> ( int_ % ((eol >> -lit("v ")) | lit(' ')) ) >> +eol 00041 >> *comment 00042 ; 00043 result = -lit("s ") >> *(char_ - (eol | ' ')) >> +eol; 00044 comment = -(lit('c') >> *(char_ - eol)) >> +eol; 00045 00046 //start.name("start"); 00047 //comment.name("comment"); 00048 //result.name("result"); 00049 00050 //debug(start); 00051 //debug(comment); 00052 //debug(result); 00053 } 00054 00055 boost::spirit::qi::rule<Iterator, result_tuple()> start; 00056 boost::spirit::qi::rule<Iterator, std::string()> result; 00057 boost::spirit::qi::rule<Iterator > comment; 00058 00059 }; 00060 } /* SA */ 00061 } /* metaSMT */