Permalink
Browse files

Improves error message presented to user

  • Loading branch information...
Martin York Martin York
Martin York authored and Martin York committed May 9, 2012
1 parent 982b63c commit de1ed70edf5cb5b436935d90021ea6da7045ef64
Showing with 6 additions and 1 deletion.
  1. +6 −1 Json/ParserShiftReduce.y
View
@@ -9,6 +9,7 @@
#include "ParserInterface.h"
#include "LexerJson.h"
#include <stdexcept>
+#include <sstream>
using ThorsAnvil::Json::ParserInterface;
using ThorsAnvil::Json::JsonValue;
@@ -109,6 +110,10 @@ int ThorsAnvil::Json::yylex(void*, LexerJson& lexer, ParserInterface& pi)
void yy::ParserShiftReduce::error(yy::location const&, std::string const& msg)
{
- throw ThorsAnvil::Json::ParsingError(msg);
+ std::string lastToken(lexer.YYText(), lexer.YYText() + lexer.YYLeng());
+ std::stringstream extended;
+ extended << msg << " -> Last Token: " << lastToken << " At line: " << lexer.lineno();
+
+ throw ThorsAnvil::Json::ParsingError(extended.str());
}

0 comments on commit de1ed70

Please sign in to comment.