[qi] Get line number of an on_error handler from an ifstream iterator

Hello, can anyone of you give me a hint, how I can get the line number of the input file inside the on_error handler where the parsing error happens? Full source is atttached as file.cpp. bool test(Iterator first, Iterator last) { qi::rule<Iterator>start; start.name("start"); start=*(eps>char_('a')>>eol); on_error<fail> ( start , std::cout << val("Error! Expecting ") << _4 << val(" here(") //linenumber insert << val("): \"") << constructstd::string(_3, _2) << val("\"") << std::endl ); bool r = qi::parse(first,last,start); if (r && first == last){ return true; } else{ return false; } } Best regards

On 9/14/2011 1:40 AM, boost_mailinglist@gmx.de wrote:
Hello,
can anyone of you give me a hint, how I can get the line number of the input file inside the on_error handler where the parsing error happens?
Full source is atttached as file.cpp.
One way is to use the file_iterator adapter of spirit classic. There are other ways. In the compiler-tutorial (*), I decorate the AST nodes with a unique identifier to a map of iterators/or positions which can be used to compute the file position on demand. (* %BOOST%/libs/spirit/example/qi/compiler_tutorial ) Regards, -- Joel de Guzman http://www.boostpro.com http://boost-spirit.com

Am 14.09.2011 04:40, schrieb Joel de Guzman:
On 9/14/2011 1:40 AM, boost_mailinglist@gmx.de wrote:
Hello,
can anyone of you give me a hint, how I can get the line number of the input file inside the on_error handler where the parsing error happens?
Full source is atttached as file.cpp.
One way is to use the file_iterator adapter of spirit classic. There are other ways. In the compiler-tutorial (*), I decorate the AST nodes with a unique identifier to a map of iterators/or positions which can be used to compute the file position on demand.
(* %BOOST%/libs/spirit/example/qi/compiler_tutorial )
Regards,
Hello, thank you for the answer. Do you have a documentation for the examples inside the folder? They seems not to be written just for fun or to test a new function. The way to replace the error_handler could be a solution for my problem. Best regards.
participants (2)
-
boost_mailinglist@gmx.de
-
Joel de Guzman