Reputation: 2061
im confused with boost Spirit X3 and string_ref class. How to construct a string_ref object. The console prints somethink like this :
N5boost16basic_string_refIcSt11char_traitsIcEEE / N5boost14iterator_rangeIN9__gnu_cxx17__normal_iteratorIPcNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEEEE
I dont know how to translate it to "normal type name" but it seems to me that i need to create the string_ref from a boost iterator range ?
auto f = [](auto& ctx)
{
auto val = _val(ctx);
auto attr = _attr(ctx);
std::cout << typeid(val).name() << " / " << typeid(attr).name() << "\n";
// _val(ctx) = boost::string_ref( attr.c_str(), 1 ); //phx::construct<boost::string_ref>( _where(ctx).begin(), _attr(ctx).size() );
};
And the rule is :
auto const quote = rule<struct quote, Type>{"quote"}
= lit('"')
>> raw[*~char_('"')][ f ]
>> lit('"');
Upvotes: 1
Views: 281
Reputation: 2061
After the comment from cv_and_he
I'm using the following lambda as semantic action
auto f = [](auto& ctx)
{
auto& attr = _attr(ctx);
_val(ctx) = boost::string_ref( &attr[0], attr.size() );
};
Upvotes: 2