如何在使用spirit :: qi时忽略spirit :: Lex中的标记属性?

时间:2012-12-04 07:45:55

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

当我使用这个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,但我只是遇到模板错误。

我该怎么做才能清理它?

1 个答案:

答案 0 :(得分:3)

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

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

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