【问题标题】:How to ignore a token attribute from spirit::Lex when using spirit::qi?使用 Spirit::qi 时如何忽略来自 spirit::Lex 的标记属性?
【发布时间】:2012-12-04 07:45:54
【问题描述】:

当我使用这个 qi 语法接受来自 Lex 的标记时:

pair %=  token(ID_MARKER)
    >> ':'
    >> atom
    >> ','
    >> atom
    ;

结合这个融合/元组映射来帮助捕获:

BOOST_FUSION_ADAPT_STRUCT(
    Client::pair_rec,
    (std::string,      m_dummy  )  // want to rid of this capture of ID_MARKER
    (Client::atom_rec, m_atom_1 )
    (Client::atom_rec, m_atom_2 )
)

一切正常。

但我想使用 ID_MARKER 只是为了解析;我真的不需要或不想捕捉它。

所以我尝试使用qi::lit 忽略该属性:

pair %=  qi::lit( token(ID_MARKER) )
    >> ':'
    >> atom
    >> ','
    >> atom
    ;

连同从捕获中删除m_dummy,但我只是得到一个模板错误墙。

我应该做些什么来清理它?

【问题讨论】:

  • @llonesmiz 再次 +1 thx - 省略完美。如果您将其添加为答案,我会接受。

标签: c++ boost-spirit boost-spirit-qi boost-spirit-lex


【解决方案1】:

没有代码来测试我不能确定,但​​是:

pair %=  qi::omit[ token(ID_MARKER) ]
    >> ':'
    >> atom
    >> ','
    >> atom
    ;

应该可以。您还可以在词法分析器中添加token_def<lex::omit> marker;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多