8 #define BOOST_SPIRIT_USE_PHOENIX_V3
9 #include <boost/fusion/adapted/std_tuple.hpp>
10 #include <boost/fusion/include/std_pair.hpp>
11 #include <boost/spirit/include/phoenix.hpp>
12 #include <boost/spirit/include/qi.hpp>
13 #include <boost/spirit/include/qi_parse.hpp>
14 #include <boost/spirit/include/support_line_pos_iterator.hpp>
17 namespace spirit = boost::spirit;
18 namespace qi = boost::spirit::qi;
19 namespace px = boost::phoenix;
26 struct Skipper:
public qi::grammar<Iterator> {
28 main = (qi::space | (qi::lit(
"*") > *(qi::char_ - qi::eol) > qi::eol));
33 struct OPBParser:
public qi::grammar<Iterator, OPBFile(), Skipper> {
43 mVarname = qi::lexeme[ qi::alpha > *(qi::alnum | qi::char_(
"_"))];
52 std::optional<OPBFile>
parse(std::istream& in) {
53 in.unsetf(std::ios::skipws);
59 if (qi::phrase_parse(begin, end, *
this, skipper, res)) {
61 std::cout <<
"Failed to parse:" << std::endl;
62 std::cout <<
"\"" << std::string(begin, end) <<
"\"" << std::endl;
67 std::cout <<
"Failed to parse:" << std::endl;
68 std::cout <<
"\"" << std::string(begin, end) <<
"\"" << std::endl;
80 return OPBFile(obj, constraints);
97 return parser.
parse(in);
Variable fresh_integer_variable() noexcept
PositionIteratorType Iterator
std::optional< OPBFile > parseOPBFile(std::ifstream &in)
spirit::istream_iterator BaseIteratorType
spirit::line_pos_iterator< BaseIteratorType > PositionIteratorType
carl::io::helper::ErrorHandler ErrorHandler
std::vector< std::pair< int, carl::Variable > > OPBPolynomial
std::tuple< OPBPolynomial, Relation, int > OPBConstraint
A Variable represents an algebraic variable that can be used throughout carl.
qi::rule< Iterator > main
qi::rule< Iterator, Variable(), Skipper > mNewVarWrapper
qi::rule< Iterator, std::pair< int, Variable >), Skipper > mTerm
qi::rule< Iterator, OPBPolynomial(), Skipper > mObjective
qi::symbols< char, Variable > mVariables
qi::rule< Iterator, OPBConstraint(), Skipper > mConstraint
Variable addVariable(const std::string &s)
px::function< ErrorHandler > errorHandler
qi::rule< Iterator, std::string(), Skipper > mVarname
qi::rule< Iterator, OPBPolynomial(), Skipper > mPolynomial
qi::rule< Iterator, OPBFile(), Skipper > mMain
std::optional< OPBFile > parse(std::istream &in)
qi::symbols< char, Relation > mRelation
OPBFile createFile(const OPBPolynomial &obj, const std::vector< OPBConstraint > &constraints)