* found to be totally unhelpful. (TODO: fix this upstream to
* improve)
*/
-std::string parseErrorHelper(const char* lineStart, int charPositionInLine, const std::string& message)
+std::string parseErrorHelper(const char* lineStart,
+ std::size_t lineLength,
+ std::size_t charPositionInLine,
+ const std::string& message)
{
// Is it a multi-line message
bool multilineMessage = (message.find('\n') != string::npos);
ss << message << endl << endl;
}
- int posSliceStart = (charPositionInLine - 50 <= 0) ? 0 : charPositionInLine - 50 + 5;
- int posSliceEnd = posSliceStart + 70;
- int caretPos = 0;
- int caretPosExtra = 0; // for inital intendation, epilipses etc.
+ std::size_t posSliceStart =
+ (charPositionInLine <= 50) ? 0 : charPositionInLine - 50 + 5;
+ std::size_t posSliceEnd = posSliceStart + 70;
+ std::size_t caretPos = 0;
+ std::size_t caretPosExtra = 0; // for inital intendation, epilipses etc.
ss << " "; caretPosExtra += 2;
if(posSliceStart > 0) {
ss << "..."; caretPosExtra += 3;
}
- for(int i = posSliceStart; lineStart[i] != '\n'; ++i) {
+ for (std::size_t i = posSliceStart; i < lineLength && lineStart[i] != '\n';
+ ++i)
+ {
if(i == posSliceEnd) {
ss << "...";
break;
void AntlrInput::parseError(const std::string& message, bool eofException)
{
- string updatedMessage = parseErrorHelper((const char*)d_antlr3InputStream->getLineBuf(d_antlr3InputStream),
- d_lexer->getCharPositionInLine(d_lexer),
- message);
+ auto lineLength = d_antlr3InputStream->sizeBuf
+ - (static_cast<char*>(d_antlr3InputStream->currentLine)
+ - static_cast<char*>(d_antlr3InputStream->data));
+ std::string updatedMessage = parseErrorHelper(
+ (const char*)d_antlr3InputStream->getLineBuf(d_antlr3InputStream),
+ lineLength,
+ d_lexer->getCharPositionInLine(d_lexer),
+ message);
Debug("parser") << "Throwing exception: "
<< (const char*)d_lexer->rec->state->tokSource->fileName->chars << ":"