![](/img/trans.png)
[英]boost::spirit: qi::rule or struct containing a qi::rule as parsing result
[英]Boost Spirit Qi rule for XML comment tag
XML 注釋標簽的 EBNF 規則是:
Comment ::= '<!--' ((Char - '-') | ('-' (Char - '-')))* '-->'
如何獲得提升靈氣規則呢?
using boost::spirit::qi::ascii::char_;
using boost::spirit::qi::lit;
comment = lit("<!--") >> *((~char_('-') >> char_) | (char_('-') >> ~char_('-'))) >> lit("-->");
這是我最好的嘗試,但不正確...
~char_('-')
對應於(Char - '-')
。
第一部分:
(~char_('-') >> char_)
應該
~char_('-')
獨自的。
否則,這個char_
可以匹配-
並且第二部分(char_('-') >> ~char_('-')
匹配->
在下一回合。
我會更直接地說:
comment = "<!--" > *(qi::char_ - "--") > "-->";
請記住使規則詞素(禁用/忽略船長)。 (請參閱Boost Spirit 船長問題)
#include <boost/spirit/include/qi.hpp>
namespace qi = boost::spirit::qi;
using It = std::string::const_iterator;
int main() {
qi::rule<It> comment; // lexeme
comment = "<!--" > *(qi::char_ - "--") > "-->";
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.