X3: How to parse "text" | "texture" into variant<text, texture> ?

Mike Gresens <[email protected]>
Newsgroups gmane.comp.parsers.spirit.general
Message-ID <[email protected]>
Hi,

some code here:

#include <boost/spirit/home/x3.hpp>
#include <boost/variant.hpp>
#include <boost/fusion/include/adapt_struct.hpp>
#include <string>
#include <iostream>

namespace x3 = boost::spirit::x3;

struct text_t {};
struct texture_t {};
typedef boost::variant<text_t, texture_t> object_t;
typedef std::string::const_iterator iterator;

BOOST_FUSION_ADAPT_STRUCT(text_t);
BOOST_FUSION_ADAPT_STRUCT(texture_t);

const x3::rule<class object_rule, object_t> object_rule("object");
const x3::rule<class text_rule, text_t> text_rule("text");
const x3::rule<class texture_rule, texture_t> texture_rule("texture");

const auto object_rule_def = text_rule | texture_rule;
const auto text_rule_def = x3::lit("text") > x3::lit('{') > x3::lit('}');
const auto texture_rule_def = x3::lit("texture") > x3::lit('{') >
x3::lit('}');

BOOST_SPIRIT_DEFINE(object_rule, text_rule, texture_rule);

int main()
{
	const std::string text("text {}");
	const std::string texture("texture {}");
	object_t object;
	try
	{
		x3::phrase_parse(text.begin(), text.end(), object_rule, x3::space,
object); // OK
		x3::phrase_parse(texture.begin(), texture.end(), object_rule, x3::space,
object); // Failure
	}
	catch (const x3::expectation_failure<iterator>& failure)
	{
		std::cout << failure.what() << " : " << failure.which() << " : " <<
*failure.where() << std::endl;
	}
}

So how can I parse "text" | "texture" into the object variant?

Thanks,
Mike...




--
View this message in context: http://boost.2283326.n4.nabble.com/X3-How-to-parse-text-texture-into-variant-text-texture-tp4683488.html
Sent from the spirit-general mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=272487151&iu=/4140
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.