Boost.Spirit.Qi - Errors at the beginning of the rule

How can I detect an error at the beginning of a rule? For example, consider the Mini XML Example included in documents. If I give the parser something like this:

<element>this is an error<element> 

Then I get:

Error! Waiting here: "

Error! Waiting here: ""

Analysis failed.

This is great, but then think about feeding it:

 element>this is an error</element> 

And I get very general and not very useful:

Analysis failed.

How can I change the rule for error reporting in an informative way?

+4
source share
1 answer

You want to require an item at the root level of the document.

Other messages are generated by unsuccessful waiting points. You will need an additional waiting point first. I would do this:

  • rename the old xml rule to element
  • create a new xml rule that has an element at the waiting point:

      xml = qi::eps > element; 
  • [Do not change anything]

  • profit!

The output will be:

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

See here here

+8
source

Source: https://habr.com/ru/post/984261/


All Articles