<i id='dB0By'><tr id='dB0By'><dt id='dB0By'><q id='dB0By'><span id='dB0By'><b id='dB0By'><form id='dB0By'><ins id='dB0By'></ins><ul id='dB0By'></ul><sub id='dB0By'></sub></form><legend id='dB0By'></legend><bdo id='dB0By'><pre id='dB0By'><center id='dB0By'></center></pre></bdo></b><th id='dB0By'></th></span></q></dt></tr></i><div id='dB0By'><tfoot id='dB0By'></tfoot><dl id='dB0By'><fieldset id='dB0By'></fieldset></dl></div>
  • <legend id='dB0By'><style id='dB0By'><dir id='dB0By'><q id='dB0By'></q></dir></style></legend>

    <small id='dB0By'></small><noframes id='dB0By'>

      1. <tfoot id='dB0By'></tfoot>

        • <bdo id='dB0By'></bdo><ul id='dB0By'></ul>

        boost::spirit::qi 关键字和标识符

        boost::spirit::qi keywords and identifiers(boost::spirit::qi 关键字和标识符)
          <tbody id='g29wb'></tbody>
          <i id='g29wb'><tr id='g29wb'><dt id='g29wb'><q id='g29wb'><span id='g29wb'><b id='g29wb'><form id='g29wb'><ins id='g29wb'></ins><ul id='g29wb'></ul><sub id='g29wb'></sub></form><legend id='g29wb'></legend><bdo id='g29wb'><pre id='g29wb'><center id='g29wb'></center></pre></bdo></b><th id='g29wb'></th></span></q></dt></tr></i><div id='g29wb'><tfoot id='g29wb'></tfoot><dl id='g29wb'><fieldset id='g29wb'></fieldset></dl></div>

            • <tfoot id='g29wb'></tfoot>

                <legend id='g29wb'><style id='g29wb'><dir id='g29wb'><q id='g29wb'></q></dir></style></legend>
                • <bdo id='g29wb'></bdo><ul id='g29wb'></ul>

                  <small id='g29wb'></small><noframes id='g29wb'>

                  本文介绍了boost::spirit::qi 关键字和标识符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我看过一些与 qi 语法中关键字/标识符使用的细微差别相关的帖子,但我不太明白 boost 示例中演示的方法应该如何工作......

                  I've seen a few posts related to the nuances of keyword/identifier use in qi grammars, but I can't quite make sense of how the approach demonstrated in the boost examples is supposed to work...

                  关键字声明:

                  qi::symbols<char> keywords;
                  

                  示例关键字集:

                  keywords.add
                          ("foo")
                          ("bar")
                          ;
                  

                  标识符规则声明:

                  qi::rule<std::string::const_iterator, std::string(), ascii::space_type> identifier;
                  

                  以下是 qi calc 和编译器示例中标识符规则的定义方式:

                  Here's how the identifier rule is defined in the qi calc and compiler examples:

                  identifier = !keywords >> qi::raw[ qi::lexeme[ ( qi::alpha | '_' ) >> *( qi::alnum | '_' ) ] ];
                  

                  也许我读错了 qi 语法,但在我看来,这不会接受任何匹配或关键字开头的文字.拒绝完整的关键字匹配是所需的行为.但是,我想接受food"作为标识符,即使它以关键字foo"开头.这似乎是一个非常标准的用例,但很难找到真正确定这一点的文档.

                  Perhaps I'm reading the qi syntax wrong, but it seems to me that this would not accept any literal that matches or starts with a keyword. Rejecting a full keyword match is the desired behavior. But, I want to accept "food" as an identifier, even though it begins with the keyword "foo". This seems like a pretty standard use case, but having trouble finding documentation that really nails this down.

                  谁能提供一个仅拒绝与关键字完全匹配的标识符规则?

                  Can anyone offer an identifier rule that only rejects exact matches to keywords?

                  谢谢!

                  推荐答案

                  其实这个问题值得一票.它应该更经常被实现,并且可能在 Spirit 教程中解决,因为它经常被忽视(显然 编译器示例没问题)

                  Actually this question deserves some votes. It should be much more oft realized, and probably be addressed in the Spirit Tutorials, as it's often overlooked (obviously the compiler samples are ok)

                  也许我读错了 qi 语法,但在我看来这不会接受任何匹配或以关键字开头的文字.

                  Perhaps I'm reading the qi syntax wrong, but it seems to me that this would not accept any literal that matches or starts with a keyword.

                  没错.如果您发现我自己的一个答案(很有可能),我倾向于将其作为一种快速而肮脏的方式来修复一开始就没有适当关键字保护的语法.

                  That's correct. In case you spotted in one of my own answers (quite a good chance) I tend to do this as a quick-and-dirty way to fixup grammars that didn't have proper keyword guards there in the first place.

                  但是,需要不同的关键字/标识符需要做更多的工作.我可能会找到一个指向正确完成的答案的链接(这并不难,只是很乏味).

                  But yeah, requiring distinct keywords/identifiers requires some more work. I might find a link to an answer where it's done correctly (it's not hard, it's just tedious).

                  同时,看看非常相关的

                  • 来自 Spirit Repository 的 Qi distinct 解析器指令
                  • Qi distinct Parser Directive from the Spirit Repository

                  如果您正在构建一个非常强大的通用语言语法,那么您应该考虑使用 Spirit Lexer.再说一次,在我看来,Spirit 的目标是快速开发和使用 Spirit 的表达式模板 eDSL 简洁嵌入的小型一次性语法.我认为,在很多方面,这与何时这很重要.

                  If you're building a really robust general-purpose language grammar, this is about the point where you should consider using a Spirit Lexer. Then again, in my humble opinion, Spirit aims at rapid development and small, one-off grammars that are succinctly embedded using Spirit's expression template eDSL. In a lot of aspects, that is much the antipode of when this matters, I reckon.

                  这篇关于boost::spirit::qi 关键字和标识符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How to limit the number of running instances in C++(C++中如何限制运行实例的数量)
                  Using boost::asio::async_read with stdin?(将 boost::asio::async_read 与 stdin 一起使用?)
                  How to find out what dependencies (i.e other Boost libraries) a particular Boost library requires?(如何找出特定 Boost 库需要哪些依赖项(即其他 Boost 库)?)
                  What#39;s the purpose of a leading quot;::quot; in a C++ method call(引导“::的目的是什么?在 C++ 方法调用中)
                  Boost Spirit x3: parse into structs(Boost Spirit x3:解析为结构体)
                  How boost auto-linking makes choice?(boost自动链接如何做出选择?)

                  • <bdo id='7mTVG'></bdo><ul id='7mTVG'></ul>
                      <tbody id='7mTVG'></tbody>
                    <tfoot id='7mTVG'></tfoot>
                    <legend id='7mTVG'><style id='7mTVG'><dir id='7mTVG'><q id='7mTVG'></q></dir></style></legend>

                        <small id='7mTVG'></small><noframes id='7mTVG'>

                        • <i id='7mTVG'><tr id='7mTVG'><dt id='7mTVG'><q id='7mTVG'><span id='7mTVG'><b id='7mTVG'><form id='7mTVG'><ins id='7mTVG'></ins><ul id='7mTVG'></ul><sub id='7mTVG'></sub></form><legend id='7mTVG'></legend><bdo id='7mTVG'><pre id='7mTVG'><center id='7mTVG'></center></pre></bdo></b><th id='7mTVG'></th></span></q></dt></tr></i><div id='7mTVG'><tfoot id='7mTVG'></tfoot><dl id='7mTVG'><fieldset id='7mTVG'></fieldset></dl></div>