BoostSpiritX3中的错误处理和注释
error handling and annotation in Boost.Spirit X3
使用boost::spirit::x3::position_tagged
作为某些AST节点的基类(如何选择应该标记的,例如对于类C语言?)和规则ID定义中使用的其他构造(如:)的逻辑是什么
struct error_handler_tag;
struct error_handler_base
{
template< typename Iterator, typename Exception, typename Context >
x3::error_handler_result
on_error(Iterator & /*first*/, Iterator const & /*last*/,
Exception const & x, Context const & context)
{
std::string message_ = "Error! Expecting: " + x.which() + " here:";
auto & error_handler = x3::get< error_handler_tag >(context).get();
error_handler(x.where(), message_);
return x3::error_handler_result::fail;
}
};
struct annotation_base
{
template< typename T, typename Iterator, typename Context >
void
on_success(Iterator const & first, Iterator const & last,
T & ast, Context const & context)
{
auto & error_handler = x3::get< error_handler_tag >(context).get();
error_handler.tag(ast, first, last);
}
};
// ...
error_handler_type error_handler(beg, end, std::cerr);
auto const parser_ = x3::with< error_handler_tag >(std::ref(error_handler))[grammar];
// ...
在错误输入(语法不匹配)的情况下,这部分代码什么也不做(即使是最简单的语法,它应该识别标识符)——不打印错误台面。
相关文章:
- 警告处理为错误这里有什么问题
- 在C#中处理C++指针而不使用unsafe的最佳方法
- 处理多个异常集合的C++方法
- 找不到成员对象:没有名为get_event()的成员,也处理多态性和向量
- 使用流处理接收到的数据
- 获取日期异步信号安全吗?如果在信号处理程序中使用,它会导致死锁吗
- 处理小于cpu数据总线的数据类型.(c++转换为机器代码)
- 基于多个条件处理地图中的所有元素
- 如何用数字处理log(0)
- SSL上的`curl_easy_send`和`curl_asy_recv`:如何处理`CURLE_AGAIN`
- Visual Studio 2019:插入多个C++风格的单行注释
- 错误处理.将系统错误代码映射到泛型
- 从文本文件中读取时钟时间和事件时间并进行处理
- 在运行时处理类型擦除的数据-如何不重新发明轮子
- 在for循环中使用auto vs decltype(vec.size())来处理字符串的向量
- 预处理一个自定义文本文件,以使用Boost Spirit删除注释
- 如何处理flex中的嵌套注释
- xerces_3_1能够在注释和处理指令中创建无效的 xml
- BoostSpiritX3中的错误处理和注释
- 是人脸检测需要之前做注释-图像处理