#include <string>
#include <boost/spirit/include/qi.hpp>
#include <boost/fusion/include/adapt_struct.hpp>
struct Date {
int year, month, day;
};
struct Time {
int hour, minute, second;
};
BOOST_FUSION_ADAPT_STRUCT(
Date,
(int, year)
(int, month)
(int, day)
)
BOOST_FUSION_ADAPT_STRUCT(
Time,
(int, hour)
(int, minute)
(int, second)
)
namespace qi = boost::spirit::qi;
namespace ascii = boost::spirit::ascii;
typedef std::string::const_iterator Iterator;
class DateParser:
public qi::grammar < Iterator, Date() > {
qi::rule < Iterator, Date() > main;
public:
DateParser(): base_type(main) {
main %= qi::int_ >> '-' >> // Year
qi::int_ >> '-' >> // Month
qi::int_; // Day
}
};
class TimeParser:
public qi::grammar < Iterator, Time() > {
qi::rule < Iterator, Time() > main;
public:
TimeParser(): base_type(main) {
main %= qi::int_ >> ':' >> // Hour
qi::int_ >> ':' >> // Minute
qi::int_; // Second
}
};
class DateTimeParser:
public qi::grammar < Iterator, boost::variant<Date, Time>() > {
qi::rule < Iterator, boost::variant<Date, Time>()> main;
public:
DateTimeParser(): base_type(main) {
main %= date_parser | time_parser;
}
DateParser date_parser;
TimeParser time_parser;
};
#include<iostream>
#include<cstdio>
struct Printer : public boost::static_visitor<> {
void operator()(Date a) const {
printf("Year: %d, Month: %d, Day: %d\n", a.year, a.month, a.day);
}
void operator()(Time a) const {
printf("Hour: %d, Minute: %d, Second: %d\n", a.hour, a.minute, a.second);
}
};
int main() {
std::string s;
std::getline(std::cin, s);
Iterator beg = s.begin(), end = s.end();
boost::variant<Date, Time> ret;
phrase_parse(beg, end, DateTimeParser(), ascii::space, ret);
if (beg != end)
puts("Parse failed.");
else
boost::apply_visitor(Printer(), ret);
}
I2luY2x1ZGUgPHN0cmluZz4KI2luY2x1ZGUgPGJvb3N0L3NwaXJpdC9pbmNsdWRlL3FpLmhwcD4KI2luY2x1ZGUgPGJvb3N0L2Z1c2lvbi9pbmNsdWRlL2FkYXB0X3N0cnVjdC5ocHA+CgpzdHJ1Y3QgRGF0ZS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