Re: X3: Using dynamic Repetition Parser Directives
Mike Gresens <[email protected]>
| Newsgroups | gmane.comp.parsers.spirit.general |
|---|---|
| Message-ID | <[email protected]> |
Was just the original code from
https://stackoverflow.com/questions/33624149/boost-spirit-x3-cannot-compile-repeat-directive-with-variable-factor/33627991#33627991
replacing std::vector<int> by std::string and x3::int_ by x3::char_
Would like to provide you buildable code, but currently this code seems to
be completely broken:
#include <boost/spirit/home/x3.hpp>
#include <boost/spirit/home/x3/binary.hpp>
#include <string>
#include <memory>
#include <iostream>
namespace x3 = boost::spirit::x3;
namespace hessian {
typedef std::string string_t;
namespace parser {
namespace detail {
//string ::= s b1 b0 <utf8-data> string
// ::= S b1 b0 <utf8-data>
// ::= [x00-x1f] <utf8-data>
// NOTE: The length means number of UTF16 characters but the content is
given in UTF8 characters!
struct length_tag;
const auto length_action = [](auto& ctx)
{
*x3::get<length_tag>(ctx) = x3::_attr(ctx);
};
const auto more_action = [](auto &ctx)
{
x3::_pass(ctx) = *x3::get<length_tag>(ctx) > x3::_val(ctx).size();
};
const auto done_action = [](auto &ctx)
{
x3::_pass(ctx) = *x3::get<length_tag>(ctx) == x3::_val(ctx).size();
};
const auto push_action = [](auto &ctx)
{
x3::_val(ctx).push_back(x3::_attr(ctx));
};
const x3::rule<class string_rule, string_t> string_rule("string");
const x3::rule<class string1_rule, string_t> string1_rule;
const x3::rule<class string2_rule, string_t> string2_rule;
const auto length_rule = x3::omit[x3::big_word [length_action] ];
const auto content_rule = x3::lexeme[ *(x3::eps [more_action] >> x3::char_
[push_action]) >> x3::eps [done_action] ];
const auto string_rule_def =
x3::with<length_tag>(std::make_shared<std::size_t>())[string1_rule |
string2_rule];
const auto string1_rule_def = x3::lit('S') >> length_rule >> content_rule;
const auto string2_rule_def = x3::lit('s') >> length_rule >> content_rule >>
string_rule;
BOOST_SPIRIT_DEFINE(string_rule, string1_rule, string2_rule);
}
using detail::string_rule;
}
}
void test_string()
{
const std::string text("s\x00\x07hello, S\x00\x05world"s);
try
{
hessian::string_t attr;
std::cout << x3::parse(text.begin(), text.end(), x3::eps >
hessian::parser::string_rule, attr) << std::endl;
std::cout << attr << std::endl;
}
catch (const x3::expectation_failure<std::string::const_iterator>&
exception)
{
std::cout << exception.what() << " " << exception.which() << " " <<
std::string(exception.where(), text.end()) << std::endl;
}
}
Error is always: fatal error: template instantiation depth exceeds maximum
of 2048
Yes, 2048!!! Totally stuck
Mike...
--
View this message in context: http://boost.2283326.n4.nabble.com/X3-Using-dynamic-Repetition-Parser-Directives-tp4682992p4683111.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=267308311&iu=/4140