How future-safe is it to write a parser with Boost Spirit X3?

别来无恙 提交于 2019-12-04 01:42:38

问题


I'm considering writing what is essentially my first parser since forever (= since the compiler class at Uni which I've forgotten mostly).

Since I use C++, I was thinking of using Boost Spirit. Then I noticed there's the "regular" 2.5.2 and there's something magical subset of the code named Spirit X3.

I' also ve noticed that Boost Spirit X3 was announced/discussed/pre-released already 2 years ago, yet Boost Spirit's official version is 2.5.2. Finally, I read:

Where is boost-spirit 3? Is it abandoned?

So I "know" that it's not an abandoned project - but not a very actively maintained project. How "safe" is it for me to write a parser with Spirit X3? Is it possible it might fail / be dropped / be abandoned, or is it certain to become the main line of Boost Spirit release?


回答1:


It's already released, so there's little chance of it just vanishing.

I liberally use X3 even in production code: After all, we do have tests for a reason.

That said, I know a number of hairy issues surround the linking of rules spread across separate translation units¹.

Here's a list of things that make me consider not using X3 in the following cases:

  • where Qi's attribute transformation logic is more enticing (makes for more readable rules). See e.g.
  • Phoenix integration is desired Boost Spirit X3 cannot compile repeat directive with variable factor
  • Sharing rules across TUs is desired

Slightly less pressing differences are when:

  • locals are involved ("X3 becomes a real tedium, (if not completely unbearable) with stateful rules (by which I mean rules with "locals")"). A lot of it can be solved using with<>: Boost Spirit X3 cannot compile repeat directive with variable factor but I'm not convinced it's re-entrant
  • lazy rule invocation is required²
  • Lexer is desired (i.e. I wouldn't port a Qi/Lex grammar to X3, except by rewrite)

Note however, there are definite areas where X3 shines:

  • compilation time
  • ease of generating dynamic rules/custom directives (see boost::spirit::x3 attribute compatibility rules, intuition or code? or Recursive x3 parser with results passing around)
  • ease of creating custom parsers (e.g. Spirit-Qi: How can I write a nonterminal parser?)

¹ see the mailing list, and e.g. x3 linker error with separate TU and linking errors while separate parser using boost spirit x3

² In fact, it might be "easy" to create one by creating a custom parser, building on with<> and any_parser<>



来源:https://stackoverflow.com/questions/45014216/how-future-safe-is-it-to-write-a-parser-with-boost-spirit-x3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!