X3 解析器如何使用已生成的标记向量。 如何定义规则,例如
enum class token { aa, bb, cc};
auto rule = token::aa >> token::bb >> -token::cc;
std::vector<token> tokens{token::aa, token:bb, token:cc};
auto ok = parse(tokens.cbegin(), tokens.cend(), rule);
我有兴趣验证输入。这个想法是为了避免遵循 C++ 零开销原则的任何词法分析(x3::lit、x3::char_、x3::lexeme、x3::alpha 等)。
最佳答案
X3 不支持 Lex,而且可能永远不会支持。
从这里开始:
- using Lex makes most of the sweet-spot disappear since all "highlevel" parsers (like
real_parser
,[u]int_parser
) are out the window. The Spirit devs are on record they prefer not to use Lex. Moreover, Spirit X3 doesn't have Lex support anymore
There are no replacements for the lexer and I doubt X3 will ever have one, unless someone contributes some time and effort. I personally don't really use them, instead preferring on pure Qi. If you do it right, A pure Qi parser can be at par with or even outperform one with a lexer (anecdotal evidence only, not fully substantiated).
The real advantage of X3 over QI is 1) in compile time and 2) in AST building. Parsing should be more or less the same. But, again in my experience, the most time consuming operations are in AST building, not parsing and not lexing.
Apologies in advance to the onslaught of questions and thanks in advance for any insights. I'd love to migrate our parser to X3 as it seems to provide many benefits over Qi.
再次请原谅延迟回复。
问候,
block 引用>
--
乔尔·德·古兹曼当被问及时,Joel 在其他地方建议如果您的应用程序确实从中受益,则创建您自己的简单 token 流,例如在这里https://sourceforge.net/p/spirit/mailman/spirit-general/thread/2A5FC1FD75EA0346A44CF4BD559664CD10CCEC%40SHEX-MB-09.ad.local/#msg34855244
关于c++17 - 将 BOOST Spirit X3 与自定义词法分析器结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/77245558/