Spirit X3 具有 boost::string_ref 语义动作构造
Spirit X3 with boost::string_ref construction from semantic action
我对 boost Spirit X3 和 string_ref class 感到困惑。如何构造一个 string_ref 对象。控制台打印出这样的想法:
N5boost16basic_string_refIcSt11char_traitsIcEEE / N5boost14iterator_rangeIN9__gnu_cxx17__normal_iteratorIPcNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEEEE
我不知道如何将它翻译成 "normal type name" 但在我看来我需要从提升迭代器范围创建 string_ref ?
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() );
};
规则是:
auto const quote = rule<struct quote, Type>{"quote"}
= lit('"')
>> raw[*~char_('"')][ f ]
>> lit('"');
根据 cv_and_he
的评论,我使用以下 lambda 作为语义操作
auto f = [](auto& ctx)
{
auto& attr = _attr(ctx);
_val(ctx) = boost::string_ref( &attr[0], attr.size() );
};
我对 boost Spirit X3 和 string_ref class 感到困惑。如何构造一个 string_ref 对象。控制台打印出这样的想法:
N5boost16basic_string_refIcSt11char_traitsIcEEE / N5boost14iterator_rangeIN9__gnu_cxx17__normal_iteratorIPcNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEEEE
我不知道如何将它翻译成 "normal type name" 但在我看来我需要从提升迭代器范围创建 string_ref ?
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() );
};
规则是:
auto const quote = rule<struct quote, Type>{"quote"}
= lit('"')
>> raw[*~char_('"')][ f ]
>> lit('"');
根据 cv_and_he
的评论,我使用以下 lambda 作为语义操作
auto f = [](auto& ctx)
{
auto& attr = _attr(ctx);
_val(ctx) = boost::string_ref( &attr[0], attr.size() );
};