Boost Spirit x3解析为具有单个字段的结构 [英] Boost Spirit x3 parsing into a struct with single field

查看:55
本文介绍了Boost Spirit x3解析为具有单个字段的结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在研究提振精神的例子,并遇到了以下问题.(我认为它在某些地方像代码中的错误一样被描述,但是我可能是错的)

Im keep invistigate boost spirit examples, and collided with the following problem. (i think it was described somwhere like a bug in the code, but i may be wrong)

简而言之:当尝试解析具有从x3 :: variant继承的单个文件类型的结构时,解析器没有生成.

Simply: Parser didn build when try to pars into a struct with a single filed of type inherited from x3::variant.

这是代码的一部分

struct operand : x3::variant<
        nil
      , unsigned int
      , std::string          
      , x3::forward_ast<expression>
    >
{
    using base_type::base_type;
    using base_type::operator=;
};
struct assign_return
{
    char sign;
    operand var;
};

我将其解析为以下内容(当然,所有需要正确定义的内容)

which i parse as folows (of cource all it needed define correctly)

auto const areturn_def =
        lexeme["return" >> !(alnum | '_')] >> char_(':') >> expression >> ';';

此代码正常工作

但是,如果我不想解析':'并按照(按照惯例,我会在此结构的BOOST_FUSION_ADAPT_STRUCT中进行更改)

but if i dont wanna parse ':' and chaged everything according with (ofcource i do changes in BOOST_FUSION_ADAPT_STRUCT for this struct)

struct assign_return
{        
    operand var;
};
auto const areturn_def =
        lexeme["return" >> !(alnum | '_')] >> expression >> ';';

此代码未出现以下错误:

This code didnt build up with the foollowing error:

C:\Program Files\boost\boost\boost\spirit\home\x3\nonterminal\rule.hpp:113:  undefined reference to `bool client::parser::parse_rule<__gnu_cxx::__normal_iterator<char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, boost::spirit::x3::context<boost::spirit::x3::skipper_tag, boost::spirit::x3::char_class<boost::spirit::char_encoding::ascii, boost::spirit::x3::space_tag> const, boost::spirit::x3::unused_type>, client::ast::assign_return>(boost::spirit::x3::rule<client::parser::expression_class, client::ast::expression, false>, __gnu_cxx::__normal_iterator<char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >&, __gnu_cxx::__normal_iterator<char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > const&, boost::spirit::x3::context<boost::spirit::x3::skipper_tag, boost::spirit::x3::char_class<boost::spirit::char_encoding::ascii, boost::spirit::x3::space_tag> const, boost::spirit::x3::unused_type> const&, client::ast::assign_return&)'

如果我们仔细查看错误代码并提及错误功能

If we look carefully at the error code and function it mention

template <typename Iterator, typename Context, typename Attribute_>    
bool parse(Iterator& first, Iterator const& last
      , Context const& context, unused_type, Attribute_& attr) const

我们可以看到,模板参数正确,但是参数列表:

We could see, that template parameters are correct, but argument list:

(rule, iterator, iterator, context, Attribute) 

这似乎是未定义引用的问题,但是如何解决?

It seems like a problem of undefined reference, but how?

感谢您的帮助!

推荐答案

是的.看起来与单元素序列无关.链接器错误通常是:)

Yeah. This looks like unrelated to single-element sequences. Linker errors usually are :)

您可能可以使用演示的技术

You could probably employ the techniques demonstrated

查找罪魁祸首.如果您发布完整,最少的有效"示例,我们可以为您提供帮助.

To find the culprit. If you post a full, minimal, "working" example we can help.

这篇关于Boost Spirit x3解析为具有单个字段的结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆