Boost.Spirit.Qi - 规则开头的错误 [英] Boost.Spirit.Qi - Errors at the beginning of a rule

查看:94
本文介绍了Boost.Spirit.Qi - 规则开头的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在规则开始时检测错误?例如,请考虑 Mini XML示例包含在文档中。如果我给解析器提供像:

How would I detect an error at the start of a rule? For example, consider the Mini XML example included in the docs. If I feed the parser something like:

<element>this is an error<element>

然后我得到:


错误!期望在这里:

Error! Expecting here: ""

错误!期望在这里:

解析失败。

然后考虑送入:

element>this is an error</element>

我得到非常通用,不太有用:

And I get the very generic and not so useful:


解析失败。

Parsing failed.

如何修改规则以报告错误

How could I modify the rule to report the error in an informative way?

推荐答案

您需要在文档根级别

其他邮件是由失败的期望点产生的。您需要在开始时添加额外的期望点。我会这样做:

The other messages are generated by failed expectation points. You'll want an extra expectation point at the start. I'd do this:


  1. 将旧 xml 重命名为 element

  2. 创建一个新的 xml 规则, :

  1. rename old xml rule to element
  2. create a new xml rule that has the element at an expectation point:

    xml = qi::eps > element;


  • [不要更改任何内容]

  • [Don't change anything else]

    利润!

    profit!



    >输出变为:

    The output becomes:

    Error! Expecting <element> here: "element>this is a test</element>
    "
    -------------------------
    Parsing failed
    -------------------------
    

    请参阅此处

    这篇关于Boost.Spirit.Qi - 规则开头的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆