Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // spiritvariant.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- struct TRIV
- {
- int v;
- };
- struct TRIVT
- {
- int v;
- int t;
- };
- struct TRIVN
- {
- int v;
- int n;
- };
- BOOST_FUSION_ADAPT_STRUCT(
- TRIV,
- (int, v)
- )
- BOOST_FUSION_ADAPT_STRUCT(
- TRIVT,
- (int, v),
- (int, t)
- )
- BOOST_FUSION_ADAPT_STRUCT(
- TRIVN,
- (int, v),
- (int, n)
- )
- struct TRI
- {
- int v = 0;
- int t = 0;
- int n = 0;
- TRI() { };
- TRI(int V, int T, int N) : v(V), t(T), n(N) { };
- TRI(TRIV t) : v(t.v) { };
- TRI(TRIVT t) : v(t.v), t(t.t) { };
- TRI(TRIVN t) : v(t.v), n(t.n) { };
- };
- BOOST_FUSION_ADAPT_STRUCT(
- TRI,
- (int, v),
- (int, t),
- (int, n)
- )
- std::ostream& operator<<(std::ostream &out, const TRI &type)
- {
- return out << "{ " << type.v << ", " << type.t << ", " << type.n << " }";
- }
- using namespace std;
- namespace x3 = boost::spirit::x3;
- namespace
- {
- x3::rule<class tvrule, TRIV>
- tvrule = "tvrule";
- auto const tvrule_def
- = x3::lexeme[x3::int_];
- ;
- BOOST_SPIRIT_DEFINE(tvrule);
- x3::rule<class tvtrule, TRIVT>
- tvtrule = "tvtrule";
- auto const tvtrule_def
- = x3::lexeme[x3::int_ >> x3::lit("/") >> x3::int_];
- ;
- BOOST_SPIRIT_DEFINE(tvtrule);
- x3::rule<class tvnrule, TRIVN>
- tvnrule = "tvnrule";
- auto const tvnrule_def
- = x3::lexeme[x3::int_ >> x3::lit("//") >> x3::int_];
- BOOST_SPIRIT_DEFINE(tvnrule);
- x3::rule<class trrule, TRI>
- trrule = "trrule";
- auto const trrule_def
- = x3::lexeme[x3::int_ >> x3::lit('/') >> x3::int_ >> x3::lit('/') >> x3::int_];
- BOOST_SPIRIT_DEFINE(trrule);
- x3::rule<class trule, TRI>
- trule = "trule";
- auto const trule_def
- = tvrule;
- BOOST_SPIRIT_DEFINE(trule);
- }
- int main()
- {
- auto in = "1/2/2"s;
- auto i = in.begin();
- x3::phrase_parse(i, in.end(), trule
- [
- ([](auto& ctx)
- {
- cout << x3::_attr(ctx) << endl;
- })
- ], x3::blank);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement