【发布时间】:2014-09-11 04:07:41
【问题描述】:
使用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];
// ...
?
如果输入错误(语法不匹配),这部分代码什么也不做(即使是最简单的语法,它应该识别标识符)- 不打印错误消息。
【问题讨论】:
-
我自己的代码有一个类似的问题,它基于rexpr tutorial 和x3_fun,但我不完全确定故障来自何处,即是否是我自己的错误。你检查过邮件列表吗?我没有编译两个教程项目,因此没有检查它们是否正确。
-
@Christoph 无法立即完成,但在不久的将来我可以。
-
Awesome :)
on_success方法定义在x3::annotate_on_successannotate_on_success.cpp 并继承于struct rexpr_class : x3::annotate_on_success, error_handler_base {};rexpr_def.hpp 被成功调用,但on_error处理程序定义为用户的 -
error_handler.hpp 不是(至少在我的项目中),即使我将它的所有声明和定义直接移动到我的等效
rexpr_class中。明天或后天,我可以尝试检查on_error和on_success的出现情况,目前我在x3目录中找不到它们,只有on_error的签名不同。跨度> -
简短更新:regexpr_full 中定义的
on_error处理程序被正确调用。
标签: c++ boost-spirit-qi boost-spirit-x3