Simple XML parser - error handling - line number

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Simple XML parser - error handling - line number

Boost - Users mailing list
I see tutorial sample:
https://www.boost.org/doc/libs/1_67_0/libs/spirit/example/qi/mini_xml3.cpp
<https://www.boost.org/doc/libs/1_67_0/libs/spirit/example/qi/mini_xml3.cpp>  
                        on_error<fail>
                                (
                                        xml
                                        , std::cout
                                        << val("Error! Expecting ")
                                        << _4                               // what failed?
                                        << val(" here: \"")
                                        << construct<std::string>(_3, _2)   // iterators to error-pos, end
                                        << val("\"")
                                        << std::endl
                                        );
How print line number, or how print _2 and _3 . If I write _2 instead _4, is
compiler error.



--
Sent from: http://boost.2283326.n4.nabble.com/Boost-Users-f2553780.html
_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: Simple XML parser - error handling - line number

Boost - Users mailing list
AMDG

On 06/29/2018 12:43 PM, AndrzejB via Boost-users wrote:

> I see tutorial sample:
> https://www.boost.org/doc/libs/1_67_0/libs/spirit/example/qi/mini_xml3.cpp
> <https://www.boost.org/doc/libs/1_67_0/libs/spirit/example/qi/mini_xml3.cpp>  
> on_error<fail>
> (
> xml
> , std::cout
> << val("Error! Expecting ")
> << _4                               // what failed?
> << val(" here: \"")
> << construct<std::string>(_3, _2)   // iterators to error-pos, end
> << val("\"")
> << std::endl
> );
> How print line number,

The parser doesn't track line numbers at all.
If you want to print it, you'll need to add
something to count new lines.

> or how print _2 and _3 . If I write _2 instead _4, is
> compiler error.
>

_2 and _3 are iterators.  You can't print them directly.
Hence why this code constructs a string from them.

In Christ,
Steven Watanabe
_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users