Boost Spirit X3 Skip Parser Implementation?
Boost Spirit X3 Skip Parser Implementation?
对于我正在使用X3解析的当前语法,空格和Perl风格的注释将被忽略。
在我看来,X3 中的跳过解析器只是一个普通的解析器,它消耗的任何输入都被视为"跳过"。我想出了这个:
namespace x3 = boost::spirit::x3;
auto const blank_comment =
x3::blank | x3::lexeme[ '#' >> *(x3::char_ - x3::eol) >> x3::eol ];
在解析一个非常基本的输入(几个注释行和一个引用的字符串行(时,这似乎效果很好。(住在科利鲁(
但是,由于我找不到有关此事的任何文档,并且当前跳过解析器的详细信息隐藏在一个复杂的模板系统中,我希望得到一些输入。
- 这是定义"跳过解析器"的正确方法吗?有标准方法吗?
- 这样的实现是否存在性能问题?如何改进?
我之前搜索了SO以获取详细信息,并使用Qi(带有Boost::Spirit的自定义跳过解析器(找到了答案。由于我从未学过气,所以很多细节都很难理解。我上面描述的方法似乎更直观。
是的,这很好。
船长似乎很理想。您可以通过重新排序和使用字符集否定 ( operator~
来优化quoted_string
规则:
住在科里鲁
#include <boost/spirit/home/x3.hpp>
namespace parser {
namespace x3 = boost::spirit::x3;
auto const quoted_string = x3::lexeme [ '"' >> *('' >> x3::char_ | ~x3::char_(""n")) >> '"' ];
auto const space_comment = x3::space | x3::lexeme[ '#' >> *(x3::char_ - x3::eol) >> x3::eol];
}
#include <iostream>
int main() {
std::string result, s1 = "# foonn#barn t"This is a simple string, containing \"escaped quotes\""";
phrase_parse(s1.begin(), s1.end(), parser::quoted_string, parser::space_comment, result);
std::cout << "Original: `" << s1 << "`nResult: `" << result << "`n";
}
指纹
Original: `# foo
#bar
"This is a simple string, containing "escaped quotes""`
Result: `This is a simple string, containing "escaped quotes"`
相关文章:
- Softmax Implementation in C++
- 在陈述"Implementation-defined"时,什么样的软件是"Implementation"的一部分?究竟什么是"Implementation"?
- 对于代理容器上的迭代器来说,"least bad implementation"可能是什么?
- STL binary_search() implementation
- Android Studio 3.1.2 - 无法运行C++子例程"No implementation found for Java.lang.String..."
- Vivado HLS implementation of RISCV
- C++ Class implementation
- c++ is_member_pointer implementation
- shared_mutex C++11 implementation
- VC++ implementation of std::promise
- libc++ implementation of std::condition_variable_any
- Paypal implementation...c++
- Boost Mutex implementation for Windows
- Implementation of mergesort
- C++ `Timer` class implementation
- BFS implementation
- C++ NTP Server implementation
- Low level implementation of bitwise Mod
- std::list implementation&pointer arithemetic.
- SIMD Implementation of std::nth_element