Update of /cvsroot/cpptool/rfta/src/rftaparser
In directory sc8-pr-cvs1:/tmp/cvs-serv17287/src/rftaparser
Modified Files:
Parser.cpp
Log Message:
* added line number to error message on parse failure
Index: Parser.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rftaparser/Parser.cpp,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** Parser.cpp 4 May 2003 06:55:25 -0000 1.11
--- Parser.cpp 4 May 2003 07:34:43 -0000 1.12
***************
*** 11,14 ****
--- 11,15 ----
#include <rfta/parser/ParserTools.h>
#include <xtl/CStringView.h>
+ #include <boost/lexical_cast.hpp>
***************
*** 76,86 ****
Parser::throwFailure( const ParserTools::ParseError &error )
{
std::string message = error.what();
message += "\n- Current position: ";
message += Xtl::CStringView( error.context_ ).getSubString(0, 60).str();
message += "\n- While analyzing:\n";
message += error.context_.getString().str();
!
throw ParserError( message, context_ );
}
--- 77,118 ----
Parser::throwFailure( const ParserTools::ParseError &error )
{
+ Xtl::CStringView source( context_.getSourceNode()->getOriginalSource() );
+ int startLine = getLineNumberOf( start_ );
+ int endLine = getLineNumberOf( end_ );
+ int currentLine = getLineNumberOf( error.context_ );
+
+ boost::format formatter(
+ "%s\n"
+ "- Parser lines: current = %d, start = %d, end = %d\n"
+ "- Current text: %s\n"
+ "- While analyzing:\n%s" );
+
+ std::string message =
+ (formatter % error.what()
+ % currentLine % startLine % endLine
+ % Xtl::CStringView( error.context_ ).getSubString(0, 60).str()
+ % error.context_.getString().str() ).str();
+ /*
+
std::string message = error.what();
+ message += "\n- Current line: " + boost::lexical_cast<std::string>( currentLine );
message += "\n- Current position: ";
message += Xtl::CStringView( error.context_ ).getSubString(0, 60).str();
message += "\n- While analyzing:\n";
message += error.context_.getString().str();
! */
throw ParserError( message, context_ );
+ }
+
+
+ int
+ Parser::getLineNumberOf( const char *position ) const
+ {
+ if ( !position )
+ return -1;
+
+ Xtl::CStringView source( context_.getSourceNode()->getOriginalSource() );
+ const char *originalPosition = source.getStart() + getIndexOf( position );
+ return std::count( source.getStart(), originalPosition, '\n' ) +1;
}
|